From 1c5bd20728b42091670921f4be2d4acaff22104a Mon Sep 17 00:00:00 2001 From: Alexander Sapountzis Date: Tue, 9 Jan 2024 10:59:21 -0500 Subject: [PATCH 1/2] ci: Add Staging Process (Step 1) for Phased Rollout --- .github/workflows/staging-step-1.yml | 312 +++++++++++++++++++++++++++ 1 file changed, 312 insertions(+) create mode 100644 .github/workflows/staging-step-1.yml diff --git a/.github/workflows/staging-step-1.yml b/.github/workflows/staging-step-1.yml new file mode 100644 index 00000000..5c9d7890 --- /dev/null +++ b/.github/workflows/staging-step-1.yml @@ -0,0 +1,312 @@ +name: "Staging Release - Step 1: Prepare CDN Pre-Release, Publish NPM" + +on: + workflow_dispatch: + inputs: + dryRun: + description: 'Do a dry run to preview instead of a real release [true/false]' + required: true + type: boolean + default: true + +jobs: + # SDK staging release must be done from the staging branch + confirm-staging-branch: + name: Confirm release is run on staging + runs-on: ubuntu-latest + steps: + - name: Git checkout + uses: actions/checkout@v3 + + - name: Branch Check + run: | + BRANCHNAME=${GITHUB_REF##*/} + if [ $BRANCHNAME != "staging" ]; then + echo "You can only run a staging release from the staging branch, you are trying to run it from ${BRANCHNAME}" + exit 1 + fi + + build-bundle: + name: Build Distribution Bundle + runs-on: ubuntu-latest + needs: confirm-staging-branch + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + ref: development + + - name: NPM install + uses: actions/setup-node@v3 + with: + node-version: 16.x + + - name: Run NPM CI + run: npm ci + + - name: Lint with ESLint + run: npm run lint + + - name: Lint with Prettier + run: npm run prettier + + - name: Run Build IIFE + run: npm run build:iife + + - name: Display Bundle Diff, but Fancy! + run: git diff --unified=3 dist/mparticle.js | npx diff-so-fancy + + - name: Archive npm failure logs + uses: actions/upload-artifact@v2 + if: failure() + with: + name: npm-logs + path: ~/.npm/_logs + + # Currently, we're only using Jest to test TypeScript modules + # and they do not require any built files + test-jest: + name: 'Test Jest' + runs-on: 'ubuntu-latest' + strategy: + matrix: + node-version: [16.x, 17.x, 18.x, 19.x, 20.x] + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: NPM install + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + + - name: Run NPM CI + run: npm ci + + - name: Run Jest Tests + run: npm run test:jest + + - name: Archive npm failure logs + uses: actions/upload-artifact@v3 + if: failure() + with: + name: npm-logs + path: ~/.npm/_logs + + # Only Core test requires bundle, but we want to make sure + # that tests only run when the bundle is successfully built + test-core: + name: Core Tests + uses: mParticle/mparticle-workflows/.github/workflows/web-run-test.yml@main + needs: + - test-jest + - build-bundle + with: + test_command_label: Core SDK Tests + test_command: npm run test + build_command: npm run build:iife + branch_name: ${{ vars.GITHUB_SHA }} + + # Test Sub can be run independent of other tests + test-stub: + name: 'Test Stub' + runs-on: ubuntu-latest + needs: + - test-core + - test-jest + - build-bundle + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: NPM install + uses: actions/setup-node@v3 + with: + node-version: 16.x + + - name: Run NPM CI + run: npm ci + + - name: Install Firefox Latest + uses: browser-actions/setup-firefox@latest + + - name: Log Firefox Version + run: firefox --version + + - name: Run Stub Tests + run: npm run test:stub + + - name: Archive npm failure logs + uses: actions/upload-artifact@v3 + if: failure() + with: + name: npm-logs + path: ~/.npm/_logs + + # Integration Tests run the same suite of tests against various build systems + # to make sure our SDK will run in different environments + + test-integrations-require-js: + name: 'Integration Tests: Require JS' + uses: mParticle/mparticle-workflows/.github/workflows/web-run-test.yml@main + needs: + - test-core + - test-jest + - build-bundle + with: + test_command_label: Require JS Test + test_command: npm run test:requirejs + branch_name: ${{ vars.GITHUB_SHA }} + + test-integrations-common-js-browserfy: + name: 'Integration Tests: Browserfy Common JS' + uses: mParticle/mparticle-workflows/.github/workflows/web-run-test.yml@main + needs: + - test-core + - test-jest + - build-bundle + with: + test_command_label: Browserfy CJS Test + test_command: npm run test:integrations:cjs:browserfy + branch_name: ${{ vars.GITHUB_SHA }} + build_command: npm run build:npm && npm run build:test-bundle + + test-integrations-common-js-webpack: + name: 'Integration Tests: webpack Common JS' + uses: mParticle/mparticle-workflows/.github/workflows/web-run-test.yml@main + needs: + - test-core + - test-jest + - build-bundle + with: + test_command_label: webpack CJS Test + test_command: npm run test:integrations:cjs:webpack + branch_name: ${{ vars.GITHUB_SHA }} + build_command: npm run build:npm && npm run build:test-bundle + + test-integrations-common-js-rollup: + name: 'Integration Tests: Rollup Common JS' + uses: mParticle/mparticle-workflows/.github/workflows/web-run-test.yml@main + needs: + - test-core + - test-jest + - build-bundle + with: + test_command_label: Rollup CJS Test + test_command: npm run test:integrations:cjs:rollup + branch_name: ${{ vars.GITHUB_SHA }} + build_command: npm run build:npm && npm run build:test-bundle + + test-integrations-module-js-webpack: + name: 'Integration Tests: webpack Module JS' + uses: mParticle/mparticle-workflows/.github/workflows/web-run-test.yml@main + needs: + - test-core + - test-jest + - build-bundle + with: + test_command_label: webpack Module Test + test_command: npm run test:integrations:module:webpack + branch_name: ${{ vars.GITHUB_SHA }} + build_command: npm run build:esm && npm run build:test-bundle + + test-integrations-module-js-rollup: + name: 'Integration Tests: Rollup Module JS' + uses: mParticle/mparticle-workflows/.github/workflows/web-run-test.yml@main + needs: + - test-core + - test-jest + - build-bundle + with: + test_command_label: Rollup Module Test + test_command: npm run test:integrations:module:rollup + branch_name: ${{ vars.GITHUB_SHA }} + build_command: npm run build:esm && npm run build:test-bundle + + create-release-branch: + name: Create release branch + runs-on: ubuntu-latest + needs: + - test-core + - test-stub + - test-integrations-common-js-browserfy + - test-integrations-common-js-webpack + - test-integrations-common-js-rollup + - test-integrations-module-js-webpack + - test-integrations-module-js-rollup + - test-integrations-require-js + - confirm-staging-branch + steps: + - name: Checkout development branch + uses: actions/checkout@v3 + with: + repository: mparticle/mparticle-web-sdk + ref: development + + - name: Create and push release branch + run: | + git checkout -b release/${{ github.run_number }} + git push origin release/${{ github.run_number }} + + release: + name: Perform Release + runs-on: ubuntu-latest + needs: + - create-release-branch + env: + GITHUB_TOKEN: ${{ secrets.MP_SEMANTIC_RELEASE_BOT }} + GIT_AUTHOR_NAME: mparticle-automation + GIT_AUTHOR_EMAIL: developers@mparticle.com + GIT_COMMITTER_NAME: mparticle-automation + GIT_COMMITTER_EMAIL: developers@mparticle.com + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + + steps: + - name: Checkout staging branch + uses: actions/checkout@v3 + with: + fetch-depth: 0 + ref: staging + + - name: Import GPG Key + uses: crazy-max/ghaction-import-gpg@e00cb83a68c1158b29afc5217dd0582cada6d172 #v4.4.0 + with: + gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} + passphrase: ${{ secrets.GPG_PASSPHRASE }} + git_user_signingkey: true + git_commit_gpgsign: true + + - name: Merge release branch into staging branch + run: | + git pull origin release/${{ github.run_number }} + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: 16.x + + - name: Install dependencies + run: npm ci + + - name: Release --dry-run + if: ${{ github.event.inputs.dryRun == 'true'}} + run: | + npx semantic-release --branches staging --dry-run + + # NPM Publish happens here + - name: Release + if: ${{ github.event.inputs.dryRun == 'false'}} + run: | + npx semantic-release --branches staging + + - name: Archive npm failure logs + uses: actions/upload-artifact@v3 + if: failure() + with: + name: npm-logs + path: ~/.npm/_logs + + - name: Push automated release commits to release branch + if: ${{ github.event.inputs.dryRun == 'false' }} + run: | + git push origin HEAD:release/${{ github.run_number }} From 5702770470c0b4e2cfa0cfa615e84ae27241a1e2 Mon Sep 17 00:00:00 2001 From: Alexander Sapountzis Date: Tue, 9 Jan 2024 11:33:01 -0500 Subject: [PATCH 2/2] Clean up formatting and lint --- .github/workflows/staging-step-1.yml | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/staging-step-1.yml b/.github/workflows/staging-step-1.yml index 5c9d7890..d053a133 100644 --- a/.github/workflows/staging-step-1.yml +++ b/.github/workflows/staging-step-1.yml @@ -1,4 +1,4 @@ -name: "Staging Release - Step 1: Prepare CDN Pre-Release, Publish NPM" +name: 'Staging Release - Step 1: Prepare CDN Pre-Release, Publish NPM' on: workflow_dispatch: @@ -20,11 +20,11 @@ jobs: - name: Branch Check run: | - BRANCHNAME=${GITHUB_REF##*/} - if [ $BRANCHNAME != "staging" ]; then - echo "You can only run a staging release from the staging branch, you are trying to run it from ${BRANCHNAME}" - exit 1 - fi + BRANCHNAME=${GITHUB_REF##*/} + if [ $BRANCHNAME != "staging" ]; then + echo "You can only run a staging release from the staging branch, you are trying to run it from ${BRANCHNAME}" + exit 1 + fi build-bundle: name: Build Distribution Bundle @@ -60,8 +60,8 @@ jobs: uses: actions/upload-artifact@v2 if: failure() with: - name: npm-logs - path: ~/.npm/_logs + name: npm-logs + path: ~/.npm/_logs # Currently, we're only using Jest to test TypeScript modules # and they do not require any built files @@ -240,8 +240,8 @@ jobs: - name: Checkout development branch uses: actions/checkout@v3 with: - repository: mparticle/mparticle-web-sdk - ref: development + repository: mparticle/mparticle-web-sdk + ref: development - name: Create and push release branch run: | @@ -265,8 +265,8 @@ jobs: - name: Checkout staging branch uses: actions/checkout@v3 with: - fetch-depth: 0 - ref: staging + fetch-depth: 0 + ref: staging - name: Import GPG Key uses: crazy-max/ghaction-import-gpg@e00cb83a68c1158b29afc5217dd0582cada6d172 #v4.4.0 @@ -278,7 +278,7 @@ jobs: - name: Merge release branch into staging branch run: | - git pull origin release/${{ github.run_number }} + git pull origin release/${{ github.run_number }} - name: Setup Node.js uses: actions/setup-node@v3