diff --git a/.github/scripts/sentry.sh b/.github/scripts/sentry.sh old mode 100644 new mode 100755 diff --git a/.github/scripts/variables.sh b/.github/scripts/variables.sh old mode 100644 new mode 100755 index 329f481aa5..551e8be517 --- a/.github/scripts/variables.sh +++ b/.github/scripts/variables.sh @@ -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 \ No newline at end of file +#!/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 [--ref ] + $me --help +Arguments: + -h, --help Displays this help screen. + -b, --brand The name of the brand to generate variables for. + -r, --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 "$@" \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index cc12cc6240..24e95dbded 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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/setup@v0.6.1 - with: - versionSpec: '5.1.x' - - - name: Use GitVersion - id: gitversion - uses: gittools/actions/gitversion/execute@v0.6.1 + id: variables + run: ./.github/scripts/variables.sh --brand ${{ matrix.brand }} --ref ${{ github.ref }} - name: Set Node.js 12.x uses: actions/setup-node@master @@ -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 @@ -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 \ No newline at end of file + az storage blob upload-batch -s dist -d \$web --account-name ${{ steps.variables.outputs.AZURE_ACCOUNT }} \ No newline at end of file diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 2c626ae748..d47f9c844c 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -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 @@ -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}" \ No newline at end of file diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml index 8ded2fe2c4..dac86346ad 100644 --- a/.github/workflows/tag.yml +++ b/.github/workflows/tag.yml @@ -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/setup@v0.6.1 - with: - versionSpec: '5.1.x' - - - name: Use GitVersion - id: gitversion # step id used as reference for output values - uses: gittools/actions/gitversion/execute@v0.6.1 - - name: Set Node.js 12.x uses: actions/setup-node@master with: @@ -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 @@ -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 \ No newline at end of file + az storage blob upload-batch -s dist -d \$web --account-name ${{ steps.variables.outputs.AZURE_ACCOUNT }} \ No newline at end of file