Skip to content

Commit 5b14452

Browse files
authored
chore(ci): update layer ARN docs and create PR during release (#2240)
1 parent 5850aa8 commit 5b14452

7 files changed

+136
-82
lines changed

.github/actions/create-pr/create_pr_for_staged_changes.sh

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set -uo pipefail # prevent accessing unset env vars, prevent masking pipeline er
33

44
#docs
55
#title :create_pr_for_staged_changes.sh
6-
#description :This script will create a PR for staged changes, detect and close duplicate PRs.
6+
#description :This script will create a PR for staged changes, detect and close duplicate PRs. All PRs will be omitted from Release Notes and Changelogs
77
#author :@heitorlessa
88
#date :May 8th 2023
99
#version :0.1
@@ -61,6 +61,8 @@ function set_environment_variables() {
6161
export readonly PR_BODY="This is an automated PR created from the following workflow"
6262
export readonly FILENAME=".github/scripts/$(basename "$0")"
6363
export readonly NO_DUPLICATES_MESSAGE="No duplicated PRs found"
64+
export readonly SKIP_LABEL="skip-changelog"
65+
6466
end_span
6567
}
6668

@@ -86,7 +88,8 @@ function create_temporary_branch_with_changes() {
8688

8789
function create_pr() {
8890
start_span "Creating PR against ${TEMP_BRANCH} branch"
89-
NEW_PR_URL=$(gh pr create --title "${PR_TITLE}" --body "${PR_BODY}: ${WORKFLOW_URL}" --base "${BASE_BRANCH}" || error "Failed to create PR") # e.g, https://github.com/awslabs/aws-lambda-powertools/pull/13
91+
# TODO: create label
92+
NEW_PR_URL=$(gh pr create --title "${PR_TITLE}" --body "${PR_BODY}: ${WORKFLOW_URL}" --base "${BASE_BRANCH}" --label "${SKIP_LABEL}" || error "Failed to create PR") # e.g, https://github.com/awslabs/aws-lambda-powertools/pull/13
9093

9194
# greedy remove any string until the last URL path, including the last '/'. https://opensource.com/article/17/6/bash-parameter-expansion
9295
debug "Extracing PR Number from PR URL: "${NEW_PR_URL}""

.github/workflows/publish_v2_layer.yml

+86-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
name: Deploy v2 layer to all regions
22

3-
permissions:
4-
id-token: write
5-
contents: write
6-
pages: write
7-
83
on:
94
workflow_dispatch:
105
inputs:
@@ -31,7 +26,11 @@ on:
3126
jobs:
3227
build-layer:
3328
permissions:
29+
# lower privilege propagated from parent workflow (release.yml)
3430
contents: read
31+
id-token: none
32+
pages: none
33+
pull-requests: none
3534
runs-on: aws-lambda-powertools_ubuntu-latest_8-core
3635
defaults:
3736
run:
@@ -87,6 +86,12 @@ jobs:
8786

8887
beta:
8988
needs: build-layer
89+
# lower privilege propagated from parent workflow (release.yml)
90+
permissions:
91+
id-token: write
92+
contents: read
93+
pages: write # docs will be updated with latest Layer ARNs
94+
pull-requests: write # creation-action will create a PR with Layer ARN updates
9095
uses: ./.github/workflows/reusable_deploy_v2_layer_stack.yml
9196
secrets: inherit
9297
with:
@@ -97,6 +102,12 @@ jobs:
97102

98103
prod:
99104
needs: beta
105+
# lower privilege propagated from parent workflow (release.yml)
106+
permissions:
107+
id-token: write
108+
contents: read
109+
pages: write # docs will be updated with latest Layer ARNs
110+
pull-requests: write # creation-action will create a PR with Layer ARN updates
100111
uses: ./.github/workflows/reusable_deploy_v2_layer_stack.yml
101112
secrets: inherit
102113
with:
@@ -107,6 +118,12 @@ jobs:
107118

108119
sar-beta:
109120
needs: build-layer
121+
permissions:
122+
# lower privilege propagated from parent workflow (release.yml)
123+
id-token: write
124+
contents: read
125+
pull-requests: none
126+
pages: none
110127
uses: ./.github/workflows/reusable_deploy_v2_sar.yml
111128
secrets: inherit
112129
with:
@@ -117,6 +134,12 @@ jobs:
117134

118135
sar-prod:
119136
needs: [build-layer, sar-beta]
137+
permissions:
138+
# lower privilege propagated from parent workflow (release.yml)
139+
id-token: write
140+
contents: read
141+
pull-requests: none
142+
pages: none
120143
uses: ./.github/workflows/reusable_deploy_v2_sar.yml
121144
secrets: inherit
122145
with:
@@ -125,10 +148,62 @@ jobs:
125148
environment: "layer-prod"
126149
package-version: ${{ inputs.latest_published_version }}
127150

151+
# Updating the documentation with the latest Layer ARNs is a two-phase process
152+
#
153+
# 1. Update layer ARNs with latest deployed locally and create a PR with these changes
154+
# 2. Pull from temporary branch with these changes and update the docs we're releasing
155+
#
156+
# This keeps our permissions tight and we don't run into a conflict,
157+
# where a new release creates a new doc (2.16.0) while layers are still pointing to 2.15
158+
# because the PR has to be merged while release process is running
159+
160+
update_v2_layer_arn_docs:
161+
needs: prod
162+
outputs:
163+
temp_branch: ${{ steps.create-pr.outputs.temp_branch }}
164+
runs-on: ubuntu-latest
165+
permissions:
166+
# lower privilege propagated from parent workflow (release.yml)
167+
contents: write
168+
pull-requests: write
169+
id-token: none
170+
pages: none
171+
steps:
172+
- name: Checkout repository # reusable workflows start clean, so we need to checkout again
173+
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
174+
with:
175+
fetch-depth: 0
176+
- name: Download CDK layer artifact
177+
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
178+
with:
179+
name: cdk-layer-stack
180+
path: cdk-layer-stack/
181+
- name: Replace layer versions in documentation
182+
run: |
183+
ls -la cdk-layer-stack/
184+
./layer/scripts/update_layer_arn.sh cdk-layer-stack
185+
# NOTE: It felt unnecessary creating yet another PR to update changelog w/ latest tag
186+
# since this is the only step in the release where we update docs from a temp branch
187+
- name: Update changelog with latest tag
188+
run: make changelog
189+
- name: Create PR
190+
id: create-pr
191+
uses: ./.github/actions/create-pr
192+
with:
193+
files: "docs/index.md examples CHANGELOG.md"
194+
temp_branch_prefix: "ci-layer-docs"
195+
pull_request_title: "chore(ci): layer docs update"
196+
github_token: ${{ secrets.GITHUB_TOKEN }}
197+
198+
128199
prepare_docs_alias:
129200
runs-on: ubuntu-latest
130201
permissions:
202+
# lower privilege propagated from parent workflow (release.yml)
131203
contents: read
204+
pages: none
205+
id-token: none
206+
pull-requests: none
132207
outputs:
133208
DOCS_ALIAS: ${{ steps.set-alias.outputs.DOCS_ALIAS }}
134209
steps:
@@ -141,13 +216,16 @@ jobs:
141216
fi
142217
echo DOCS_ALIAS="$DOCS_ALIAS" >> "$GITHUB_OUTPUT"
143218
144-
release-docs:
145-
needs: [prod, prepare_docs_alias]
219+
release_docs:
220+
needs: [update_v2_layer_arn_docs, prepare_docs_alias]
146221
permissions:
222+
# lower privilege propagated from parent workflow (release.yml)
147223
contents: write
148224
pages: write
225+
pull-requests: none
226+
id-token: none
149227
uses: ./.github/workflows/reusable_publish_docs.yml
150228
with:
151229
version: ${{ inputs.latest_published_version }}
152230
alias: ${{ needs.prepare_docs_alias.outputs.DOCS_ALIAS }}
153-
detached_mode: true
231+
git_ref: ${{ needs.update_v2_layer_arn_docs.outputs.temp_branch }}

.github/workflows/release.yml

+30-7
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ name: Release
55
# === Automated activities ===
66
#
77
# 1. Run tests, linting, security and complexity base line
8-
# 2. Bump package version, build release artifact, and generate latest Changelog
8+
# 2. Bump package version and build release artifact
99
# 3. Publish package to PyPi prod repository using cached artifact
10-
# 4. Kick off Layers pipeline to compile and publish latest version
11-
# 5. Updates documentation to use the latest Layer ARN for all commercial regions
12-
# 6. Builds a new user guide and API docs with release version; update /latest pointing to newly released version
13-
# 7. Close all issues labeled "pending-release" and notify customers about the release
10+
# 4. Compile Layer and kick off pipeline for beta, prod, and canary releases
11+
# 5. Update docs with latest Layer ARNs and Changelog
12+
# 6. Create PR to update trunk so staged docs also point to the latest Layer ARN, when merged
13+
# 7. Builds a new user guide and API docs with release version; update /latest pointing to newly released version
14+
# 8. Create PR to update package version on trunk
15+
# 9. Close all issues labeled "pending-release" and notify customers about the release
1416
#
1517
# === Manual activities ===
1618
#
@@ -126,15 +128,36 @@ jobs:
126128
# with:
127129
# repository-url: https://test.pypi.org/legacy/
128130

131+
create_tag:
132+
needs: [build, release]
133+
runs-on: ubuntu-latest
134+
permissions:
135+
contents: write
136+
env:
137+
RELEASE_VERSION: ${{ needs.build.outputs.RELEASE_VERSION }}
138+
steps:
139+
- uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
140+
- id: setup-git
141+
name: Git client setup and refresh tip
142+
run: |
143+
git config user.name "Powertools bot"
144+
git config user.email "[email protected]"
145+
git config remote.origin.url >&-
146+
- name: Create Git Tag
147+
run: |
148+
git tag -a v"${RELEASE_VERSION}" -m "release_version: v${RELEASE_VERSION}"
149+
git push origin v"${RELEASE_VERSION}"
150+
129151
# NOTE: Watch out for the depth limit of 4 nested workflow_calls.
130-
# publish_layer -> publish_v2_layer -> reusable_deploy_v2_layer_stack -> reusable_update_v2_layer_arn_docs
152+
# publish_layer -> publish_v2_layer -> reusable_deploy_v2_layer_stack
131153
publish_layer:
132-
needs: [build, release]
154+
needs: [build, release, create_tag]
133155
secrets: inherit
134156
permissions:
135157
id-token: write
136158
contents: write
137159
pages: write
160+
pull-requests: write
138161
uses: ./.github/workflows/publish_v2_layer.yml
139162
with:
140163
latest_published_version: ${{ needs.build.outputs.RELEASE_VERSION }}

.github/workflows/reusable_deploy_v2_layer_stack.yml

+6-11
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
name: Deploy CDK Layer v2 stack
22

3-
permissions:
4-
id-token: write
5-
contents: write
6-
73
on:
84
workflow_call:
95
inputs:
@@ -28,6 +24,12 @@ jobs:
2824
deploy-cdk-stack:
2925
runs-on: ubuntu-latest
3026
environment: ${{ inputs.environment }}
27+
# lower privilege propagated from parent workflow (publish_v2_layer.yml)
28+
permissions:
29+
id-token: write
30+
pull-requests: none
31+
contents: read
32+
pages: none
3133
defaults:
3234
run:
3335
working-directory: ./layer
@@ -149,10 +151,3 @@ jobs:
149151
retention-days: 1
150152
- name: CDK Deploy Canary
151153
run: npx cdk deploy --app cdk.out --context region=${{ matrix.region }} --parameters DeployStage="${{ inputs.stage }}" --parameters HasARM64Support=${{ matrix.has_arm64_support }} 'CanaryV2Stack' --require-approval never --verbose
152-
153-
update_v2_layer_arn_docs:
154-
needs: deploy-cdk-stack
155-
if: ${{ inputs.stage == 'PROD' }}
156-
uses: ./.github/workflows/reusable_update_v2_layer_arn_docs.yml
157-
with:
158-
latest_published_version: ${{ inputs.latest_published_version }}

.github/workflows/reusable_publish_docs.yml

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
name: Reusable publish documentation
22

33
env:
4-
BRANCH: develop
54
ORIGIN: awslabs/aws-lambda-powertools-python
65

76
on:
@@ -20,6 +19,11 @@ on:
2019
required: false
2120
default: false
2221
type: boolean
22+
git_ref:
23+
description: "Branch or commit ID to checkout from"
24+
required: false
25+
type: string
26+
default: develop
2327

2428
permissions:
2529
contents: write
@@ -36,6 +40,7 @@ jobs:
3640
- uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
3741
with:
3842
fetch-depth: 0
43+
ref: ${{ inputs.git_ref }}
3944
- name: Install poetry
4045
run: pipx install poetry
4146
- name: Set up Python
@@ -56,6 +61,8 @@ jobs:
5661
git config pull.rebase true
5762
git config remote.origin.url >&- || git remote add origin https://github.com/"$ORIGIN"
5863
git pull origin "$BRANCH"
64+
env:
65+
BRANCH: ${{ inputs.git_ref }}
5966
- name: Build docs website and API reference
6067
env:
6168
VERSION: ${{ inputs.version }}

.github/workflows/reusable_update_v2_layer_arn_docs.yml

-52
This file was deleted.

layer/scripts/update_layer_arn.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
# This script is run during the reusable_update_v2_layer_arn_docs CI job,
3+
# This script is run during the publish_v2_layer.yml CI job,
44
# and it is responsible for replacing the layer ARN in our documentation,
55
# based on the output files generated by CDK when deploying to each pseudo_region.
66
#

0 commit comments

Comments
 (0)