Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use new variable script from Pull Request 347 #394

Merged
merged 1 commit into from
Nov 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified .github/scripts/sentry.sh
100644 → 100755
Empty file.
87 changes: 76 additions & 11 deletions .github/scripts/variables.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,11 +1,76 @@
if [ "$BRAND" == "payex" ]; then
echo ::set-env name=BRAND_URL::https://payexdesignguide.z16.web.core.windows.net
echo ::set-env name=BRAND_BUILD_SCRIPT::build:prod:payex
echo ::set-output name=BRAND_BUILD_SCRIPT::build:prod:payex
elif [ "$BRAND" == "swedbankpay" ]; then
echo ::set-env name=BRAND_URL::https://swedbankpaydesignguide.z16.web.core.windows.net
echo ::set-env name=BRAND_BUILD_SCRIPT::build:prod
echo ::set-output name=BRAND_BUILD_SCRIPT::build:prod
else
echo "Unknown brand!"
fi
#!/bin/bash
set -o errexit # Abort if any command fails
me=$(basename "$0")

help_message="\
Generates variables based on the provided brand and ref arguments.
Usage:
$me --brand <brand> [--ref <ref>]
$me --help
Arguments:
-h, --help Displays this help screen.
-b, --brand <brand> The name of the brand to generate variables for.
-r, --ref <ref> The Git ref being built."

initialize() {
while : ; do
if [[ $1 = "-h" || $1 = "--help" ]]; then
echo "$help_message"
return 0
elif [[ ( $1 = "-b" || $1 = "--brand" ) && -n $2 ]]; then
brand=$2
shift 2
elif [[ ( $1 = "-r" || $1 = "--ref" ) && -n $2 ]]; then
ref=$2
shift 2
else
break
fi
done

if [[ -z "$brand" ]]; then
echo "No brand specified." >&2
echo "$help_message"
return 1
fi
}

generate_variables() {
if [[ "$ref" == refs/tags/* ]]; then
version="${ref#refs/tags/}"
echo "::set-output name=VERSION::$version"
elif [[ "$ref" == refs/heads/release/* ]]; then
version="${ref#refs/heads/release/}"
echo "::set-output name=VERSION::$version"
elif [[ "$ref" == refs/heads/* ]]; then
branch="${ref#refs/heads/}"
echo "::set-output name=BRANCH::$branch"
fi

echo "Ref: $ref"
echo "Branch: $branch"
echo "Version: $version"
echo "Brand: $brand"

if [ "$brand" == "payex" ]; then
echo ::set-output name=BRAND_NAME::PayEx
echo ::set-output name=BRAND_URL::https://payexdesignguide.z6.web.core.windows.net
echo ::set-output name=AZURE_ACCOUNT::payexdesignguide
echo ::set-output name=BUILD_SCRIPT::build:prod:payex
elif [ "$brand" == "swedbankpay" ]; then
echo ::set-output name=BRAND_NAME::SwedbankPay
echo ::set-output name=BRAND_URL::https://swedbankpaydesignguide.z6.web.core.windows.net
echo ::set-output name=AZURE_ACCOUNT::swedbankpaydesignguide
echo ::set-output name=BUILD_SCRIPT::build:prod
else
echo "Unknown brand '$brand'!"
return 1
fi
}

main() {
initialize "$@"
generate_variables
}

main "$@"
23 changes: 4 additions & 19 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,10 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Fetch all history for all tags and branches
run: git fetch --prune --unshallow

# Set brand specific variables
- name: Environment variables
run: |
chmod +x ./.github/scripts/variables.sh
./.github/scripts/variables.sh
env:
BRAND: ${{ matrix.brand }}

- name: Install GitVersion
uses: gittools/actions/gitversion/[email protected]
with:
versionSpec: '5.1.x'

- name: Use GitVersion
id: gitversion
uses: gittools/actions/gitversion/[email protected]
id: variables
run: ./.github/scripts/variables.sh --brand ${{ matrix.brand }} --ref ${{ github.ref }}

- name: Set Node.js 12.x
uses: actions/setup-node@master
Expand All @@ -52,7 +37,7 @@ jobs:
run: npm ci

- name: Build
run: npm run $BRAND_BUILD_SCRIPT -- --env.baseUrl="$BRAND_URL" --env.basename=${{ steps.gitversion.outputs.branchName }} --env.semver=${{ steps.gitversion.outputs.semVer }} --env.info_version=${{ steps.gitversion.outputs.informationalVersion }} --env.github_actions=true
run: npm run ${{ steps.variables.outputs.BUILD_SCRIPT }} -- --env.baseUrl="${{ steps.variables.outputs.BRAND_URL }}" --env.basename=${{ steps.variables.outputs.BRANCH }} --env.semver=${{ steps.variables.outputs.BRANCH }} --env.info_version=${{ steps.variables.outputs.VERSION }} --env.github_actions=true

- name: Azure Login
uses: azure/login@v1
Expand All @@ -63,4 +48,4 @@ jobs:
uses: azure/CLI@v1
with:
inlineScript: |
az storage blob upload-batch -s dist -d \$web --account-name ${{ matrix.brand }}designguide
az storage blob upload-batch -s dist -d \$web --account-name ${{ steps.variables.outputs.AZURE_ACCOUNT }}
10 changes: 2 additions & 8 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,7 @@ jobs:
# Set brand specific variables
- name: Environment variables
id: variables
# "git config core.filemode false" is set to disregard local rwx changes in git [THN]
run: |
git config core.filemode false
chmod +x ./.github/scripts/variables.sh
./.github/scripts/variables.sh
env:
BRAND: ${{ matrix.brand }}
run: ./.github/scripts/variables.sh --brand ${{ matrix.brand }} --ref ${{ github.ref }}

- name: Set Node.js 12.x
uses: actions/setup-node@master
Expand All @@ -39,6 +33,6 @@ jobs:
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
# basename=PullRequest is added to avoid BundleAnalyzer from holding up the agent [THN]
build-script: "${{ steps.variables.outputs.BRAND_BUILD_SCRIPT }} -- --env.basename=PullRequest"
build-script: "${{ steps.variables.outputs.BUILD_SCRIPT }} -- --env.basename=PullRequest"
exclude: "{**/*.map,**/node_modules/**,**/*chunk*.*}"
pattern: "{dist/**/*.js,dist/**/*.css}"
27 changes: 5 additions & 22 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,17 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Fetch all history for all tags and branches
run: git fetch --prune --unshallow

# Set brand specific variables
- name: Environment variables
run: |
chmod +x ./.github/scripts/variables.sh
./.github/scripts/variables.sh
env:
BRAND: ${{ matrix.brand }}
id: variables
run: ./.github/scripts/variables.sh --brand ${{ matrix.brand }} --ref ${{ github.ref }}

# Add sentry token
- name: Sentry token
run: |
chmod +x ./.github/scripts/sentry.sh
./.github/scripts/sentry.sh
run: ./.github/scripts/sentry.sh
env:
TOKEN: ${{ secrets.SENTRY_TOKEN }}

- name: Install GitVersion
uses: gittools/actions/gitversion/[email protected]
with:
versionSpec: '5.1.x'

- name: Use GitVersion
id: gitversion # step id used as reference for output values
uses: gittools/actions/gitversion/[email protected]

- name: Set Node.js 12.x
uses: actions/setup-node@master
with:
Expand All @@ -59,7 +42,7 @@ jobs:
run: npm ci

- name: Build
run: npm run $BRAND_BUILD_SCRIPT -- --env.release=true --env.baseUrl="$BRAND_URL" --env.basename="v/${{ steps.gitversion.outputs.majorMinorPatch }}" --env.semver=${{ steps.gitversion.outputs.semVer }} --env.info_version=${{ steps.gitversion.outputs.informationalVersion }} --env.github_actions=true
run: npm run ${{ steps.variables.outputs.BUILD_SCRIPT }} -- --env.release=true --env.baseUrl="${{ steps.variables.outputs.BRAND_URL }}" --env.basename="v/${{ steps.variables.outputs.VERSION }}" --env.semver=${{ steps.variables.outputs.VERSION }} --env.info_version=${{ steps.variables.outputs.VERSION }} --env.github_actions=true

- name: Azure Login
uses: azure/login@v1
Expand All @@ -70,4 +53,4 @@ jobs:
uses: azure/CLI@v1
with:
inlineScript: |
az storage blob upload-batch -s dist -d \$web --account-name ${{ matrix.brand }}designguide
az storage blob upload-batch -s dist -d \$web --account-name ${{ steps.variables.outputs.AZURE_ACCOUNT }}