From 23f1d200e036cace529dc0acce0e752e6ef15e61 Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Thu, 11 Aug 2022 14:32:50 +0000 Subject: [PATCH 1/3] fix: release process --- .github/PULL_REQUEST_TEMPLATE.md | 4 +- .github/workflows/make-release.yml | 197 ++++++++++++++++++++++++++ .github/workflows/on-release-prod.yml | 111 --------------- 3 files changed, 199 insertions(+), 113 deletions(-) create mode 100644 .github/workflows/make-release.yml delete mode 100644 .github/workflows/on-release-prod.yml diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index c3733c946b..e431ff05dc 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -21,8 +21,8 @@ ### Related issues, RFCs - - + + **Issue number:** ### PR status diff --git a/.github/workflows/make-release.yml b/.github/workflows/make-release.yml new file mode 100644 index 0000000000..e86d8c6f61 --- /dev/null +++ b/.github/workflows/make-release.yml @@ -0,0 +1,197 @@ +name: Make Release +on: + workflow_dispatch: {} +concurrency: + group: on-release-publish +jobs: + check-examples: + runs-on: ubuntu-latest + env: + NODE_ENV: dev + strategy: + matrix: + example: ["sam", "cdk"] + fail-fast: false + defaults: + run: + working-directory: examples/${{ matrix.example }} + steps: + - name: Checkout code + uses: actions/checkout@v3 + - name: Setup NodeJS + uses: actions/setup-node@v3 + with: + node-version: 16 + cache: "npm" + - name: Cache node modules + id: cache-node-modules + uses: actions/cache@v3 + with: + path: "./examples/${{ matrix.example }}/node_modules" + # Use the combo between example, name, and SHA-256 hash of all example lock files as cache key. + # It's not possible to use the ${{ matrix.example }} key in the hashFiles fn so + # if any of the lock files (wich should be fairly similar anyway) changes the cache is + # invalidated/discarded for all. + key: ${{ matrix.example }}-cache-examples-node-modules-${{ hashFiles('./examples/*/package-lock.json') }} + - name: Install dependencies + run: npm ci + - name: Run tests + run: npm t + check-layer-publisher: + runs-on: ubuntu-latest + env: + NODE_ENV: dev + defaults: + run: + working-directory: layer-publisher + steps: + - name: Checkout code + uses: actions/checkout@v3 + - name: Setup NodeJS + uses: actions/setup-node@v3 + with: + node-version: 16 + cache: "npm" + - name: Cache node modules + id: cache-node-modules + uses: actions/cache@v3 + with: + path: "./layer-publisher/node_modules" + # Use the combo between example, name, and SHA-256 hash of the layer-publisher lock files as cache key. + key: cache-layer-publisher-node-modules-${{ hashFiles('./layer-publisher/*/package-lock.json') }} + - name: Install Layer publisher app + run: npm ci + run-unit-tests-on-utils: + runs-on: ubuntu-latest + env: + NODE_ENV: dev + strategy: + matrix: + version: [12, 14, 16] + fail-fast: false + steps: + - name: Checkout code + uses: actions/checkout@v3 + - name: Setup NodeJS + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.version }} + cache: "npm" + - name: Setup npm + run: npm i -g npm@next-8 + - name: Cache node modules + id: cache-node-modules + uses: actions/cache@v3 + with: + path: "./node_modules" + # Use the combo between node version, name, and SHA-256 hash of the lock file as cache key so that + # if one of them changes the cache is invalidated/discarded + key: ${{ matrix.version }}-cache-utils-node-modules-${{ hashFiles('./package-lock.json') }} + - name: Install dependencies + # We can skip the install if there was a cache hit + if: steps.cache-node-modules.outputs.cache-hit != 'true' + # See https://github.com/npm/cli/issues/4475 to see why --foreground-scripts + run: npm ci --foreground-scripts + - name: Build packages + # If there's a cache hit we still need to manually build the packages + # this would otherwise have been done automatically as a part of the + # postinstall npm hook + if: steps.cache-node-modules.outputs.cache-hit == 'true' + run: | + npm run build -w packages/commons + npm run build -w packages/logger & npm run build -w packages/tracer & npm run build -w packages/metrics + - name: Lint + run: npm run lint -w packages/commons -w packages/logger -w packages/tracer -w packages/metrics + - name: Run unit tests + run: npm t -w packages/commons -w packages/logger -w packages/tracer -w packages/metrics + publish-npm: + needs: [check-examples, check-layer-publisher, run-unit-tests-on-utils] + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + with: + # Here `token` is needed to avoid incurring in error GH006 Protected Branch Update Failed, + token: ${{ secrets.GH_PUBLISH_TOKEN }} + # While `fetch-depth` is used to allow the workflow to later commit & push the changes. + fetch-depth: 0 + - name: Setup NodeJS + uses: actions/setup-node@v3 + with: + node-version: "16" + cache: "npm" + - name: Setup npm + run: | + npm i -g npm@next-8 + npm set "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" + - name: Cache node modules + id: cache-node-modules + uses: actions/cache@v3 + with: + path: "./node_modules" + # Use the combo between node version, name, and SHA-256 hash of the lock file as cache key so that + # if one of them changes the cache is invalidated/discarded + key: 16-cache-utils-node-modules-${{ hashFiles('./package-lock.json') }} + - name: Build packages + run: | + npm run build -w packages/commons + npm run build -w packages/logger & npm run build -w packages/tracer & npm run build -w packages/metrics + - name: "Version and publish" + env: + GH_TOKEN: ${{ secrets.GH_PUBLISH_TOKEN }} + run: | + git config --global user.name 'github-actions[bot]' + git config --global user.email 'github-actions[bot]@users.noreply.github.com' + git remote set-url origin https://x-access-token:${GH_TOKEN}@github.com/$GITHUB_REPOSITORY + npx lerna version --conventional-commits --force-publish --yes + npx lerna publish from-git --no-verify-access --yes + publish-docs: + needs: publish-npm + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.8" + - name: Set RELEASE_VERSION env var + run: | + RELEASE_VERSION=$(cat packages/commons/package.json | jq '.version' -r) + echo "RELEASE_VERSION=${RELEASE_VERSION}" >> $GITHUB_ENV + - name: Install doc generation dependencies + run: | + pip install --upgrade pip + pip install -r docs/requirements.txt + - name: Setup doc deploy + run: | + git config --global user.name Docs deploy + git config --global user.email docs@dummy.bot.com + - name: Build mkdocs site in "gh-pages" branch and push + run: | + rm -rf site + VERSION="${{ env.RELEASE_VERSION }}" + ALIAS="latest" + echo "Publishing doc for version: $VERSION" + mkdocs build + mike deploy --push --update-aliases --no-redirect "$VERSION" "$ALIAS" + # Set latest version as a default + mike set-default --push latest + - name: Build API docs + run: | + rm -rf api + npm run docs-generateApiDoc + - name: Release API docs to the released version + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./api + keep_files: true + destination_dir: ${{ env.RELEASE_VERSION }}/api + - name: Release API docs to the "latest" version + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./api + keep_files: true + destination_dir: latest/api diff --git a/.github/workflows/on-release-prod.yml b/.github/workflows/on-release-prod.yml deleted file mode 100644 index f431e6a951..0000000000 --- a/.github/workflows/on-release-prod.yml +++ /dev/null @@ -1,111 +0,0 @@ -name: release -on: - workflow_dispatch: {} -jobs: - publish: - ######################### - # Force Github action to run only a single job at a time (based on the group name) - # This is to prevent "race-condition" in publishing a new version of doc to `gh-pages` (#365) - ######################### - concurrency: - group: on-release-publish - runs-on: ubuntu-latest - steps: - - name: "Checkout" - uses: actions/checkout@v3 - with: - # Here `token` is needed to avoid incurring in error GH006 Protected Branch Update Failed, - token: ${{ secrets.GH_PUBLISH_TOKEN }} - # While `fetch-depth` is used to allow the workflow to later commit & push the changes. - fetch-depth: 0 - ######################### - # Release new version - ######################### - - name: "Use NodeJS 16" - uses: actions/setup-node@v3 - with: - node-version: '16' - - name: Install npm@8.x - run: npm i -g npm@next-8 - - name: "Setup npm" - run: | - npm set "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" - - name: Install monorepo packages - # This installs all the dependencies of ./packages/* - # See https://github.com/npm/cli/issues/4475 to see why --foreground-scripts - run: npm ci --foreground-scripts - - name: Install CDK example packages - # Since we are not managing the CDK examples with npm workspaces we install - # the dependencies in a separate step - working-directory: ./examples/cdk - run: npm ci - - name: "Setup SAM" - # We use an ad-hoc action so we can specify the SAM CLI version - uses: aws-actions/setup-sam@v2 - with: - version: 1.49.0 - - name: Install SAM example packages - # Since we are not managing the SAM examples with npm workspaces we install - # the dependencies in a separate step - working-directory: ./examples/sam - run: npm ci - - name: Run lint - run: npm run lerna-lint - - name: Run tests - run: npm run lerna-test - - name: "Version and publish" - env: - GH_TOKEN: ${{ secrets.GH_PUBLISH_TOKEN }} - run: | - git config --global user.name 'github-actions[bot]' - git config --global user.email 'github-actions[bot]@users.noreply.github.com' - git remote set-url origin https://x-access-token:${GH_TOKEN}@github.com/$GITHUB_REPOSITORY - npx lerna version --conventional-commits --force-publish --yes - npx lerna publish from-git --no-verify-access --yes - ######################### - # Generate documentation - ######################### - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: '3.8' - - name: Set RELEASE_VERSION env var - run: | - RELEASE_VERSION=$(cat packages/commons/package.json | jq '.version' -r) - echo "RELEASE_VERSION=${RELEASE_VERSION}" >> $GITHUB_ENV - - name: Install doc generation dependencies - run: | - pip install --upgrade pip - pip install -r docs/requirements.txt - - name: Setup doc deploy - run: | - git config --global user.name Docs deploy - git config --global user.email docs@dummy.bot.com - - name: Build mkdocs site in "gh-pages" branch and push - run: | - rm -rf site - VERSION="${{ env.RELEASE_VERSION }}" - ALIAS="latest" - echo "Publishing doc for version: $VERSION" - mkdocs build - mike deploy --push --update-aliases --no-redirect "$VERSION" "$ALIAS" - # Set latest version as a default - mike set-default --push latest - - name: Build API docs - run: | - rm -rf api - npm run docs-generateApiDoc - - name: Release API docs to the released version - uses: peaceiris/actions-gh-pages@v3 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./api - keep_files: true - destination_dir: ${{ env.RELEASE_VERSION }}/api - - name: Release API docs to the "latest" version - uses: peaceiris/actions-gh-pages@v3 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./api - keep_files: true - destination_dir: latest/api From 886ee6b2ab152c6ceb0a25d439ef49885340b56a Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Thu, 11 Aug 2022 18:22:31 +0000 Subject: [PATCH 2/3] chore: remove duplicate code --- .github/workflows/auto-merge.yml | 68 -------- .github/workflows/make-release.yml | 160 ++---------------- .github/workflows/on-merge-to-main.yml | 121 +++---------- .github/workflows/pr_lint_and_test.yml | 102 +---------- .github/workflows/reusable-publish-docs.yml | 104 ++++++++++++ .github/workflows/reusable-run-unit-tests.yml | 110 ++++++++++++ 6 files changed, 250 insertions(+), 415 deletions(-) delete mode 100644 .github/workflows/auto-merge.yml create mode 100644 .github/workflows/reusable-publish-docs.yml create mode 100644 .github/workflows/reusable-run-unit-tests.yml diff --git a/.github/workflows/auto-merge.yml b/.github/workflows/auto-merge.yml deleted file mode 100644 index 164c7c4f9b..0000000000 --- a/.github/workflows/auto-merge.yml +++ /dev/null @@ -1,68 +0,0 @@ -name: Dependabot PR auto-merge - -on: - workflow_run: - workflows: [on-pull-request] - types: ["completed"] - -jobs: - auto-merge: - name: Auto-merge - runs-on: ubuntu-latest - # Run this only when the previous workflow was successfull & the initial actor was dependabot - if: ${{ github.event.workflow_run.conclusion == 'success' && github.actor == 'dependabot[bot]' }} - steps: - - uses: actions/checkout@v3 - - name: Download PR artifact - uses: actions/github-script@v6 - with: - script: | - const fs = require('fs'); - - // Get all artifacts - const artifacts = await github.actions.listWorkflowRunArtifacts({ - owner: context.repo.owner, - repo: context.repo.repo, - run_id: ${{github.event.workflow_run.id }}, - }); - - // Identify the artifact of the PR - const matchArtifact = artifacts.data.artifacts.filter((artifact) => { - return artifact.name == "pr" - })[0]; - - // Download the actual artifact - const download = await github.actions.downloadArtifact({ - owner: context.repo.owner, - repo: context.repo.repo, - artifact_id: matchArtifact.id, - archive_format: 'zip', - }); - - // Write it to disk - fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data)); - - name: Unzip artifact - run: unzip pr.zip - - name: Merge PR - uses: actions/github-script@v6 - with: - script: | - const fs = require('fs'); - const pullNumber = Number(fs.readFileSync('./NR')); - - // Create a review - github.pulls.createReview({ - owner: context.payload.repository.owner.login, - repo: context.payload.repository.name, - pull_number: pullNumber, - event: 'APPROVE' - }) - - // Merge PR - github.pulls.merge({ - owner: context.payload.repository.owner.login, - repo: context.payload.repository.name, - pull_number: pullNumber, - merge_method: 'squash' - }) - github-token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/make-release.yml b/.github/workflows/make-release.yml index e86d8c6f61..677b126602 100644 --- a/.github/workflows/make-release.yml +++ b/.github/workflows/make-release.yml @@ -4,108 +4,10 @@ on: concurrency: group: on-release-publish jobs: - check-examples: - runs-on: ubuntu-latest - env: - NODE_ENV: dev - strategy: - matrix: - example: ["sam", "cdk"] - fail-fast: false - defaults: - run: - working-directory: examples/${{ matrix.example }} - steps: - - name: Checkout code - uses: actions/checkout@v3 - - name: Setup NodeJS - uses: actions/setup-node@v3 - with: - node-version: 16 - cache: "npm" - - name: Cache node modules - id: cache-node-modules - uses: actions/cache@v3 - with: - path: "./examples/${{ matrix.example }}/node_modules" - # Use the combo between example, name, and SHA-256 hash of all example lock files as cache key. - # It's not possible to use the ${{ matrix.example }} key in the hashFiles fn so - # if any of the lock files (wich should be fairly similar anyway) changes the cache is - # invalidated/discarded for all. - key: ${{ matrix.example }}-cache-examples-node-modules-${{ hashFiles('./examples/*/package-lock.json') }} - - name: Install dependencies - run: npm ci - - name: Run tests - run: npm t - check-layer-publisher: - runs-on: ubuntu-latest - env: - NODE_ENV: dev - defaults: - run: - working-directory: layer-publisher - steps: - - name: Checkout code - uses: actions/checkout@v3 - - name: Setup NodeJS - uses: actions/setup-node@v3 - with: - node-version: 16 - cache: "npm" - - name: Cache node modules - id: cache-node-modules - uses: actions/cache@v3 - with: - path: "./layer-publisher/node_modules" - # Use the combo between example, name, and SHA-256 hash of the layer-publisher lock files as cache key. - key: cache-layer-publisher-node-modules-${{ hashFiles('./layer-publisher/*/package-lock.json') }} - - name: Install Layer publisher app - run: npm ci - run-unit-tests-on-utils: - runs-on: ubuntu-latest - env: - NODE_ENV: dev - strategy: - matrix: - version: [12, 14, 16] - fail-fast: false - steps: - - name: Checkout code - uses: actions/checkout@v3 - - name: Setup NodeJS - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.version }} - cache: "npm" - - name: Setup npm - run: npm i -g npm@next-8 - - name: Cache node modules - id: cache-node-modules - uses: actions/cache@v3 - with: - path: "./node_modules" - # Use the combo between node version, name, and SHA-256 hash of the lock file as cache key so that - # if one of them changes the cache is invalidated/discarded - key: ${{ matrix.version }}-cache-utils-node-modules-${{ hashFiles('./package-lock.json') }} - - name: Install dependencies - # We can skip the install if there was a cache hit - if: steps.cache-node-modules.outputs.cache-hit != 'true' - # See https://github.com/npm/cli/issues/4475 to see why --foreground-scripts - run: npm ci --foreground-scripts - - name: Build packages - # If there's a cache hit we still need to manually build the packages - # this would otherwise have been done automatically as a part of the - # postinstall npm hook - if: steps.cache-node-modules.outputs.cache-hit == 'true' - run: | - npm run build -w packages/commons - npm run build -w packages/logger & npm run build -w packages/tracer & npm run build -w packages/metrics - - name: Lint - run: npm run lint -w packages/commons -w packages/logger -w packages/tracer -w packages/metrics - - name: Run unit tests - run: npm t -w packages/commons -w packages/logger -w packages/tracer -w packages/metrics + run-unit-tests: + uses: ./.github/workflows/reusable-run-unit-tests.yml publish-npm: - needs: [check-examples, check-layer-publisher, run-unit-tests-on-utils] + needs: run-unit-tests runs-on: ubuntu-latest steps: - name: Checkout code @@ -145,53 +47,11 @@ jobs: git remote set-url origin https://x-access-token:${GH_TOKEN}@github.com/$GITHUB_REPOSITORY npx lerna version --conventional-commits --force-publish --yes npx lerna publish from-git --no-verify-access --yes - publish-docs: + publish: needs: publish-npm - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v3 - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: "3.8" - - name: Set RELEASE_VERSION env var - run: | - RELEASE_VERSION=$(cat packages/commons/package.json | jq '.version' -r) - echo "RELEASE_VERSION=${RELEASE_VERSION}" >> $GITHUB_ENV - - name: Install doc generation dependencies - run: | - pip install --upgrade pip - pip install -r docs/requirements.txt - - name: Setup doc deploy - run: | - git config --global user.name Docs deploy - git config --global user.email docs@dummy.bot.com - - name: Build mkdocs site in "gh-pages" branch and push - run: | - rm -rf site - VERSION="${{ env.RELEASE_VERSION }}" - ALIAS="latest" - echo "Publishing doc for version: $VERSION" - mkdocs build - mike deploy --push --update-aliases --no-redirect "$VERSION" "$ALIAS" - # Set latest version as a default - mike set-default --push latest - - name: Build API docs - run: | - rm -rf api - npm run docs-generateApiDoc - - name: Release API docs to the released version - uses: peaceiris/actions-gh-pages@v3 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./api - keep_files: true - destination_dir: ${{ env.RELEASE_VERSION }}/api - - name: Release API docs to the "latest" version - uses: peaceiris/actions-gh-pages@v3 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./api - keep_files: true - destination_dir: latest/api + uses: ./.github/workflows/reusable-publish-docs.yml + with: + workflow_origin: ${{ github.event.repository.full_name }} + isRelease: "true" + secrets: + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/on-merge-to-main.yml b/.github/workflows/on-merge-to-main.yml index 0792aa6da5..83e8238b69 100644 --- a/.github/workflows/on-merge-to-main.yml +++ b/.github/workflows/on-merge-to-main.yml @@ -5,6 +5,8 @@ on: workflows: ["Record PR details"] types: - completed +concurrency: + group: on-merge-to-main jobs: get_pr_details: @@ -15,10 +17,30 @@ jobs: workflow_origin: ${{ github.event.repository.full_name }} secrets: token: ${{ secrets.GITHUB_TOKEN }} + run-unit-tests: + uses: ./.github/workflows/reusable-run-unit-tests.yml + publish: + needs: + [get_pr_details, run-unit-tests, check-examples, check-layer-publisher] + uses: ./.github/workflows/reusable-publish-docs.yml + with: + workflow_origin: ${{ github.event.repository.full_name }} + prIsMerged: ${{ needs.get_pr_details.outputs.prIsMerged }} + secrets: + token: ${{ secrets.GITHUB_TOKEN }} + update-release-draft: + needs: publish + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + - name: Update release draft + uses: release-drafter/release-drafter@v5.20.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} release_label_on_merge: - needs: get_pr_details + needs: [get_pr_details, update-release-draft] runs-on: ubuntu-latest - if: needs.get_pr_details.outputs.prIsMerged == 'true' steps: - uses: actions/checkout@v3 - name: "Label PR related issue for release" @@ -33,98 +55,3 @@ jobs: script: | const script = require('.github/scripts/label_related_issue.js') await script({github, context, core}) - publish: - ######################### - # Force Github action to run only a single job at a time (based on the group name) - # This is to prevent "race-condition" in publishing a new version of doc to `gh-pages` (#365) - ######################### - concurrency: - group: on-merge-to-main - runs-on: ubuntu-latest - steps: - - name: "Checkout" - uses: actions/checkout@v3 - with: - fetch-depth: 0 - ######################### - # Release new version - ######################### - - name: "Use NodeJS 16" - uses: actions/setup-node@v3 - with: - node-version: '16' - - name: Install npm@8.x - run: npm i -g npm@next-8 - - name: "Setup npm" - run: | - npm set "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" - - name: Install monorepo packages - # This installs all the dependencies of ./packages/* - # See https://github.com/npm/cli/issues/4475 to see why --foreground-scripts - run: npm ci --foreground-scripts - - name: Install CDK example packages - # Since we are not managing the CDK examples with npm workspaces we install - # the dependencies in a separate step - working-directory: ./examples/cdk - run: npm ci - - name: Install Layer publisher app - working-directory: ./layer-publisher - run: npm ci - - name: "Setup SAM" - # We use an ad-hoc action so we can specify the SAM CLI version - uses: aws-actions/setup-sam@v2 - with: - version: 1.49.0 - - name: Install SAM example packages - # Since we are not managing the SAM examples with npm workspaces we install - # the dependencies in a separate step - working-directory: ./examples/sam - run: npm ci - - name: Run lint - run: npm run lerna-lint - - name: Run tests - run: npm run lerna-test - - name: Update release draft - uses: release-drafter/release-drafter@v5.20.0 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - ######################### - # Generate documentation - ######################### - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: '3.8' - - name: Install doc generation dependencies - run: | - pip install --upgrade pip - pip install -r docs/requirements.txt - - name: Setup doc deploy - run: | - git config --global user.name Docs deploy - git config --global user.email docs@dummy.bot.com - - name: Build mkdocs site in "gh-pages" branch and push - run: | - rm -rf site - VERSION="dev" - echo "Publishing doc for version: $VERSION" - mkdocs build - mike deploy --push "$VERSION" - - name: Build API docs - run: | - rm -rf api - npm run docs-generateApiDoc - - name: Release API docs to the released version - uses: peaceiris/actions-gh-pages@v3 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./api - keep_files: true - destination_dir: dev/api - - name: Release API docs to the "latest" version - uses: peaceiris/actions-gh-pages@v3 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./api - keep_files: true - destination_dir: latest/api diff --git a/.github/workflows/pr_lint_and_test.yml b/.github/workflows/pr_lint_and_test.yml index 8ca59e6c32..640395e70b 100644 --- a/.github/workflows/pr_lint_and_test.yml +++ b/.github/workflows/pr_lint_and_test.yml @@ -4,103 +4,5 @@ on: pull_request: types: [opened, synchronize] jobs: - run-unit-tests-on-utils: - runs-on: ubuntu-latest - env: - NODE_ENV: dev - strategy: - matrix: - version: [12, 14, 16] - fail-fast: false - steps: - - name: Checkout code - uses: actions/checkout@v3 - - name: Setup NodeJS - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.version }} - cache: "npm" - - name: Setup npm - run: npm i -g npm@next-8 - - name: Cache node modules - id: cache-node-modules - uses: actions/cache@v3 - with: - path: "./node_modules" - # Use the combo between node version, name, and SHA-256 hash of the lock file as cache key so that - # if one of them changes the cache is invalidated/discarded - key: ${{ matrix.version }}-cache-utils-node-modules-${{ hashFiles('./package-lock.json') }} - - name: Install dependencies - # We can skip the install if there was a cache hit - if: steps.cache-node-modules.outputs.cache-hit != 'true' - # See https://github.com/npm/cli/issues/4475 to see why --foreground-scripts - run: npm ci --foreground-scripts - - name: Build packages - # If there's a cache hit we still need to manually build the packages - # this would otherwise have been done automatically as a part of the - # postinstall npm hook - if: steps.cache-node-modules.outputs.cache-hit == 'true' - run: | - npm run build -w packages/commons - npm run build -w packages/logger & npm run build -w packages/tracer & npm run build -w packages/metrics - - name: Lint - run: npm run lint -w packages/commons -w packages/logger -w packages/tracer -w packages/metrics - - name: Run unit tests - run: npm t -w packages/commons -w packages/logger -w packages/tracer -w packages/metrics - check-examples: - runs-on: ubuntu-latest - env: - NODE_ENV: dev - strategy: - matrix: - example: ["sam", "cdk"] - fail-fast: false - defaults: - run: - working-directory: examples/${{ matrix.example }} - steps: - - name: Checkout code - uses: actions/checkout@v3 - - name: Setup NodeJS - uses: actions/setup-node@v3 - with: - node-version: 16 - cache: "npm" - - name: Cache node modules - id: cache-node-modules - uses: actions/cache@v3 - with: - path: "./examples/${{ matrix.example }}/node_modules" - # Use the combo between example, name, and SHA-256 hash of all example lock files as cache key. - # It's not possible to use the ${{ matrix.example }} key in the hashFiles fn so - # if any of the lock files (wich should be fairly similar anyway) changes the cache is - # invalidated/discarded for all. - key: ${{ matrix.example }}-cache-examples-node-modules-${{ hashFiles('./examples/*/package-lock.json') }} - - name: Install dependencies - run: npm ci - - name: Run tests - run: npm t - check-layer-publisher: - runs-on: ubuntu-latest - env: - NODE_ENV: dev - defaults: - run: - working-directory: layer-publisher - steps: - - name: Checkout code - uses: actions/checkout@v3 - - name: Setup NodeJS - uses: actions/setup-node@v3 - with: - node-version: 16 - cache: "npm" - - name: Cache node modules - id: cache-node-modules - uses: actions/cache@v3 - with: - path: "./layer-publisher/node_modules" - # Use the combo between example, name, and SHA-256 hash of the layer-publisher lock files as cache key. - key: cache-layer-publisher-node-modules-${{ hashFiles('./layer-publisher/*/package-lock.json') }} - - name: Install Layer publisher app - run: npm ci \ No newline at end of file + run-unit-tests: + uses: ./.github/workflows/reusable-run-unit-tests.yml diff --git a/.github/workflows/reusable-publish-docs.yml b/.github/workflows/reusable-publish-docs.yml new file mode 100644 index 0000000000..ddd2f8c5a4 --- /dev/null +++ b/.github/workflows/reusable-publish-docs.yml @@ -0,0 +1,104 @@ +name: Publish docs + +on: + workflow_call: + inputs: + workflow_origin: # see https://github.com/awslabs/aws-lambda-powertools-python/issues/1349 + required: true + type: string + prIsMerged: + required: false + default: "false" + type: string + isRelease: + required: false + default: "false" + type: string + secrets: + token: + required: true +concurrency: + group: on-release-publish + +jobs: + publish-docs: + # see https://github.com/awslabs/aws-lambda-powertools-python/issues/1349 + if: inputs.workflow_origin == 'dreamorosi/aws-lambda-powertools-typescript' + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + with: + # Here `token` is needed to avoid incurring in error GH006 Protected Branch Update Failed, + token: ${{ secrets.token }} + # While `fetch-depth` is used to allow the workflow to later commit & push the changes. + fetch-depth: 0 + - name: Setup NodeJS + uses: actions/setup-node@v3 + with: + node-version: "16" + cache: "npm" + # Use the combo between node version, name, and SHA-256 hash of the lock file as cache key so that + # if one of them changes the cache is invalidated/discarded + - name: Cache node modules + id: cache-node-modules + uses: actions/cache@v3 + with: + path: "./node_modules" + key: 16-cache-utils-node-modules-${{ hashFiles('./package-lock.json') }} + # Here we assume that there will always be a cache hit because this workflow can be triggered + # only after tests have already happened on this same code + - name: Build packages + run: | + npm run build -w packages/commons + npm run build -w packages/logger & npm run build -w packages/tracer & npm run build -w packages/metrics + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.8" + # We run this step only when the workflow has been triggered by a release + # in this case we publish the docs to `/latest` + - name: Set RELEASE_VERSION env var to `latest` + if: ${{ inputs.isRelease == 'true' }} + run: | + RELEASE_VERSION=$(cat packages/commons/package.json | jq '.version' -r) + echo "RELEASE_VERSION=${RELEASE_VERSION}" >> $GITHUB_ENV + # We run this step only when the workflow has been triggered by a PR merge + # in this case we publish the docs to `/dev` + - name: Set RELEASE_VERSION env var to `dev` + if: ${{ inputs.prIsMerged == 'true' }} + run: | + echo "RELEASE_VERSION=dev" >> $GITHUB_ENV + - name: Install doc generation dependencies + run: | + pip install --upgrade pip + pip install -r docs/requirements.txt + - name: Setup doc deploy + run: | + git config --global user.name Docs deploy + git config --global user.email docs@dummy.bot.com + - name: Publish docs to latest + if: ${{ env.RELEASE_VERSION != 'dev' }} + run: | + rm -rf site + mkdocs build + mike deploy --push --update-aliases --no-redirect "${{ env.RELEASE_VERSION }}" "latest" + # Set latest version as a default + mike set-default --push latest + - name: Publish docs to dev + if: ${{ env.RELEASE_VERSION == 'dev' }} + run: | + rm -rf site + mkdocs build + mike deploy --push dev + - name: Build API docs + run: | + rm -rf api + npm run docs-generateApiDoc + - name: Release API docs + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./api + keep_files: true + destination_dir: ${{ env.RELEASE_VERSION }}/api diff --git a/.github/workflows/reusable-run-unit-tests.yml b/.github/workflows/reusable-run-unit-tests.yml new file mode 100644 index 0000000000..b2e29ce068 --- /dev/null +++ b/.github/workflows/reusable-run-unit-tests.yml @@ -0,0 +1,110 @@ +name: Run unit tests + +on: + workflow_call: + +jobs: + run-unit-tests-on-utils: + runs-on: ubuntu-latest + env: + NODE_ENV: dev + strategy: + matrix: + version: [12, 14, 16] + fail-fast: false + steps: + - name: Checkout code + uses: actions/checkout@v3 + - name: Setup NodeJS + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.version }} + cache: "npm" + - name: Setup npm + run: npm i -g npm@next-8 + - name: Cache node modules + id: cache-node-modules + uses: actions/cache@v3 + with: + path: "./node_modules" + # Use the combo between node version, name, and SHA-256 hash of the lock file as cache key so that + # if one of them changes the cache is invalidated/discarded + key: ${{ matrix.version }}-cache-utils-node-modules-${{ hashFiles('./package-lock.json') }} + - name: Install dependencies + # We can skip the install if there was a cache hit + if: steps.cache-node-modules.outputs.cache-hit != 'true' + # See https://github.com/npm/cli/issues/4475 to see why --foreground-scripts + run: npm ci --foreground-scripts + - name: Build packages + # If there's a cache hit we still need to manually build the packages + # this would otherwise have been done automatically as a part of the + # postinstall npm hook + if: steps.cache-node-modules.outputs.cache-hit == 'true' + run: | + npm run build -w packages/commons + npm run build -w packages/logger & npm run build -w packages/tracer & npm run build -w packages/metrics + - name: Lint + run: npm run lint -w packages/commons -w packages/logger -w packages/tracer -w packages/metrics + - name: Run unit tests + run: npm t -w packages/commons -w packages/logger -w packages/tracer -w packages/metrics + check-examples: + runs-on: ubuntu-latest + env: + NODE_ENV: dev + strategy: + matrix: + example: ["sam", "cdk"] + fail-fast: false + defaults: + run: + working-directory: examples/${{ matrix.example }} + steps: + - name: Checkout code + uses: actions/checkout@v3 + - name: Setup NodeJS + uses: actions/setup-node@v3 + with: + node-version: 16 + cache: "npm" + - name: Cache node modules + id: cache-node-modules + uses: actions/cache@v3 + with: + path: "./examples/${{ matrix.example }}/node_modules" + # Use the combo between example, name, and SHA-256 hash of all example lock files as cache key. + # It's not possible to use the ${{ matrix.example }} key in the hashFiles fn so + # if any of the lock files (wich should be fairly similar anyway) changes the cache is + # invalidated/discarded for all. + key: ${{ matrix.example }}-cache-examples-node-modules-${{ hashFiles('./examples/*/package-lock.json') }} + - name: Install dependencies + # We can skip the install if there was a cache hit + if: steps.cache-node-modules.outputs.cache-hit != 'true' + run: npm ci + - name: Run tests + run: npm t + check-layer-publisher: + runs-on: ubuntu-latest + env: + NODE_ENV: dev + defaults: + run: + working-directory: layer-publisher + steps: + - name: Checkout code + uses: actions/checkout@v3 + - name: Setup NodeJS + uses: actions/setup-node@v3 + with: + node-version: 16 + cache: "npm" + - name: Cache node modules + id: cache-node-modules + uses: actions/cache@v3 + with: + path: "./layer-publisher/node_modules" + # Use the combo between example, name, and SHA-256 hash of the layer-publisher lock files as cache key. + key: cache-layer-publisher-node-modules-${{ hashFiles('./layer-publisher/*/package-lock.json') }} + - name: Install Layer publisher + # We can skip the install if there was a cache hit + if: steps.cache-node-modules.outputs.cache-hit != 'true' + run: npm ci From 21a9e2835a0ba9bb37bdb075fc75eb334529c497 Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Fri, 12 Aug 2022 12:08:19 +0200 Subject: [PATCH 3/3] Update .github/workflows/reusable-publish-docs.yml --- .github/workflows/reusable-publish-docs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/reusable-publish-docs.yml b/.github/workflows/reusable-publish-docs.yml index ddd2f8c5a4..4177e09570 100644 --- a/.github/workflows/reusable-publish-docs.yml +++ b/.github/workflows/reusable-publish-docs.yml @@ -23,7 +23,7 @@ concurrency: jobs: publish-docs: # see https://github.com/awslabs/aws-lambda-powertools-python/issues/1349 - if: inputs.workflow_origin == 'dreamorosi/aws-lambda-powertools-typescript' + if: inputs.workflow_origin == 'awslabs/aws-lambda-powertools-typescript' runs-on: ubuntu-latest steps: - name: Checkout code