Skip to content

Commit 719e1b9

Browse files
authored
chore(ci): refactor release workflow (#2028)
* Update GitHub Actions workflows * remove env, use git sha * Update GitHub Actions references to use github.sha * change publish from package using sha instead of tag * remove unnecessary token for checkout * add workflow docs and comments * small wording changes
1 parent ff70f22 commit 719e1b9

File tree

4 files changed

+66
-35
lines changed

4 files changed

+66
-35
lines changed

.github/workflows/make-release.yml

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
11
name: Make Release
2+
3+
# RELEASE PROCESS
4+
#
5+
# === Automated activities ===
6+
# 1. [Quality check] run unit tests, linting, examples, layer, doc snippets
7+
# 2. [Release] publish all packages to npmjs.org using the latest git commit, ensure provenance with NPM_CONFIG_PROVENANCE=true
8+
# 3. [Create tag] create a new git tag using released version, i.e. v1.13.1
9+
# 4. [Publish layer] build and package layer, kick off the workflow for beta and prod deployment, including canary tests
10+
# 5. [Publish layer] update documentation with the latest layer ARN version of the prod deployment
11+
# 6. [Publish layer] create PR to merge the updated documentation
12+
#
13+
# === Manual activities ===
14+
# 1. Kick off `make-version` workflow to bump and review the version changes and changelog for each package
15+
# 2. Merge the PR created by `make-version` workflow
16+
# 3. Kick off this workflow to make the release
17+
# 4. Merge the PR created by the `publish_layer` workflow to update the documentation
18+
# 5. Update draft release notes with the latest changes and publish the release on GitHub
19+
220
on:
321
workflow_dispatch: {}
422

@@ -7,9 +25,15 @@ permissions:
725

826
concurrency:
927
group: on-release-publish
28+
29+
1030
jobs:
1131
run-unit-tests:
1232
uses: ./.github/workflows/reusable-run-linting-check-and-unit-tests.yml
33+
# This job publishes the packages to npm.
34+
# It uses the latest git commit sha as the version and ensures provenance with NPM_CONFIG_PROVENANCE flag.
35+
# We don't bump the version because we do that in the `make-version` workflow.
36+
# It also sets the RELEASE_VERSION output to be used by the next job to create a git tag.
1337
publish-npm:
1438
needs: run-unit-tests
1539
# Needed as recommended by npm docs on publishing with provenance https://docs.npmjs.com/generating-provenance-statements
@@ -24,35 +48,47 @@ jobs:
2448
- name: Checkout code
2549
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
2650
with:
27-
# Here `token` is needed to avoid incurring in error GH006 Protected Branch Update Failed,
28-
token: ${{ secrets.GH_PUBLISH_TOKEN }}
29-
# While `fetch-depth` is used to allow the workflow to later commit & push the changes.
30-
fetch-depth: 0
51+
ref: ${{ github.sha }}
3152
- name: Setup NodeJS
3253
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
3354
with:
3455
node-version: "20"
3556
cache: "npm"
3657
- name: Setup auth tokens
3758
run: |
38-
git config --global user.name 'github-actions[bot]'
39-
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
40-
git remote set-url origin https://x-access-token:${{ secrets.GH_PUBLISH_TOKEN }}@github.com/$GITHUB_REPOSITORY
4159
npm set "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}"
4260
- name: Setup dependencies
4361
uses: ./.github/actions/cached-node-modules
44-
- name: Version
45-
run: |
46-
npx lerna version minor --force-publish --no-commit-hooks --yes
4762
- name: Publish to npm
4863
run: |
49-
NPM_CONFIG_PROVENANCE=true npx lerna publish from-git --yes
64+
NPM_CONFIG_PROVENANCE=true npx lerna publish from-package --git-head ${{ github.sha }} --yes
5065
- name: Set release version
5166
id: set-release-version
5267
run: |
5368
VERSION=$(cat lerna.json | jq .version -r)
5469
echo RELEASE_VERSION="$VERSION" >> "$GITHUB_OUTPUT"
55-
70+
71+
# This job creates a new git tag using the released version (v1.18.1)
72+
create_tag:
73+
needs: [publish-npm]
74+
permissions:
75+
contents: write
76+
runs-on: ubuntu-latest
77+
steps:
78+
- name: Checkout code
79+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
80+
with:
81+
ref: ${{ github.sha }}
82+
- name: Git client setup
83+
run: |
84+
git config --global user.name 'aws-powertools-bot'
85+
git config --global user.email '151832416+aws-powertools-bot@users.noreply.github.com'
86+
git config remote.origin.url >&-
87+
- name: Create git tag
88+
run : |
89+
git tag -a v${{ needs.publish-npm.outputs.RELEASE_VERSION }} -m "Release v${{ needs.publish-npm.outputs.RELEASE_VERSION }}"
90+
git push origin v${{ needs.publish-npm.outputs.RELEASE_VERSION }}
91+
5692
# NOTE: Watch out for the depth limit of 4 nested workflow_calls.
5793
# publish_layer -> reusable_deploy_layer_stack -> reusable_update_layer_arn_docs
5894
publish_layer:

.github/workflows/make-version.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ on:
44
workflow_dispatch: { }
55

66

7-
env:
8-
RELEASE_COMMIT: ${{ github.sha }}
9-
107
jobs:
118
bump-version:
129
permissions:
@@ -20,7 +17,7 @@ jobs:
2017
- name: Checkout code
2118
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
2219
with:
23-
ref: ${{ github.ref }}
20+
ref: ${{ github.sha }}
2421
- name: Setup NodeJS
2522
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
2623
with:

.github/workflows/publish_layer.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Deploy layer to all regions
22

33
permissions:
4-
contents: write
4+
contents: read
55

66
on:
77
# Manual trigger
@@ -33,7 +33,7 @@ jobs:
3333
- name: checkout
3434
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
3535
with:
36-
fetch-depth: 0
36+
ref: ${{ github.sha }}
3737
- name: Setup Node.js
3838
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
3939
with:

.github/workflows/reusable_update_layer_arn_docs.yml

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
required: true
1010

1111
permissions:
12-
contents: write
12+
contents: read
1313

1414
env:
1515
BRANCH: main
@@ -21,18 +21,15 @@ jobs:
2121
concurrency:
2222
group: changelog-build
2323
runs-on: ubuntu-latest
24+
permissions:
25+
contents: write
26+
pull-requests: write
27+
id-token: none
2428
steps:
2529
- name: Checkout repository # reusable workflows start clean, so we need to checkout again
2630
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
2731
with:
28-
fetch-depth: 0
29-
- name: Git client setup and refresh tip
30-
run: |
31-
git config user.name "Release bot[bot]"
32-
git config user.email "aws-devax-open-source@amazon.com"
33-
git config pull.rebase true
34-
git config remote.origin.url >&- || git remote add origin https://github.com/"${origin}" # Git Detached mode (release notes) doesn't have origin
35-
git pull origin "${BRANCH}"
32+
ref: ${{ github.sha }}
3633
- name: Download CDK layer artifact
3734
uses: actions/download-artifact@6b208ae046db98c579e8a3aa621ab581ff575935 # v4.1.1
3835
with:
@@ -42,11 +39,12 @@ jobs:
4239
run: |
4340
ls -la cdk-layer-stack/
4441
./.github/scripts/update_layer_arn.sh cdk-layer-stack
45-
- name: Update documentation in trunk
46-
run: |
47-
HAS_CHANGE=$(git status --porcelain)
48-
test -z "${HAS_CHANGE}" && echo "Nothing to update" && exit 0
49-
git add docs/index.md
50-
git commit -m "chore: update layer ARN on documentation"
51-
git pull origin "${BRANCH}" # prevents concurrent branch update failing push
52-
git push origin HEAD:refs/heads/"${BRANCH}"
42+
- name: Create PR
43+
id: create-pr
44+
uses: ./.github/actions/create-pr
45+
with:
46+
files: 'docs/index.md'
47+
temp_branch_prefix: 'ci-layer-docs'
48+
pull_request_title: 'chore(ci): update layer ARN on documentation'
49+
github_token: ${{ secrets.GITHUB_TOKEN }}
50+

0 commit comments

Comments
 (0)