Skip to content

Commit a996229

Browse files
rubenfonsecaheitorlessa
authored andcommitted
fix(ci): secret and OIDC inheritance in nested children workflow
1 parent 4298a0b commit a996229

7 files changed

+140
-83
lines changed

Diff for: .github/workflows/on_release_notes.yml

+17-39
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ on:
3131
workflow_dispatch:
3232
inputs:
3333
version_to_publish:
34-
description: "Version to be released in PyPi, Docs, and Lambda Layer, e.g. v1.26.4"
34+
description: "Version to be released in PyPi, Docs, and Lambda Layer, e.g. v2.0.0, v2.0.0.a0 (pre-release)"
3535
default: v2.0.0
3636
required: true
3737
skip_pypi:
@@ -44,19 +44,24 @@ on:
4444
default: false
4545
type: boolean
4646
required: false
47+
# Only use this until v1 is completely dropped, and for manual releases
48+
skip_version_guard:
49+
description: "Skips conditions to prevent v1 into v2 releases"
50+
default: false
51+
type: boolean
52+
required: false
4753
pre_release:
48-
description: "Publishes documentation using a pre-release tag. You are still responsible for passing a pre-release version tag to the workflow."
54+
description: "Publishes documentation using a pre-release tag (v2.0.0.a0). You are still responsible for passing a pre-release version tag to the workflow."
4955
default: false
5056
type: boolean
5157
required: false
5258

5359
jobs:
5460
release:
55-
if: ${{ startsWith(github.ref, 'refs/tags/v2') }}
61+
if: ${{ startsWith(github.ref, 'refs/tags/v2') || inputs.skip_version_guard }}
5662
environment: release
5763
runs-on: ubuntu-latest
5864
permissions:
59-
id-token: write
6065
contents: read
6166
outputs:
6267
RELEASE_VERSION: ${{ steps.release_version.outputs.RELEASE_VERSION }}
@@ -102,56 +107,29 @@ jobs:
102107
env:
103108
PYPI_USERNAME: __token__
104109
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
105-
- name: aws credentials
106-
uses: aws-actions/configure-aws-credentials@v1
107-
with:
108-
aws-region: eu-west-1
109-
role-to-assume: ${{ secrets.AWS_SAR_ROLE_ARN }}
110-
- name: publish lambda layer in SAR by triggering the internal codepipeline
111-
run: |
112-
aws ssm put-parameter --name "powertools-python-release-version" --value "$RELEASE_VERSION" --overwrite
113-
aws codepipeline start-pipeline-execution --name ${{ secrets.AWS_SAR_PIPELINE_NAME }}
114110

115111
changelog:
116112
needs: release
117113
permissions:
118114
contents: write
119115
uses: ./.github/workflows/reusable_publish_changelog.yml
120116

121-
# When doing a pre-release, we want to publish the docs as "alpha" instead of replacing the latest docs
122-
prepare_docs_alias:
123-
runs-on: ubuntu-latest
124-
outputs:
125-
DOCS_ALIAS: ${{ steps.set-alias.outputs.DOCS_ALIAS }}
126-
steps:
127-
- name: Set docs alias
128-
id: set-alias
129-
run: |
130-
DOCS_ALIAS=latest
131-
if [[ "${{ github.event.release.prerelease || inputs.pre_release }}" == true ]] ; then
132-
DOCS_ALIAS=alpha
133-
fi
134-
echo DOCS_ALIAS="$DOCS_ALIAS" >> "$GITHUB_OUTPUT"
135-
136-
docs:
137-
needs: [release, changelog, prepare_docs_alias]
117+
# NOTE: Watch out for the depth limit of 4 nested workflow_calls.
118+
# publish_layer -> publish_v2_layer -> reusable_deploy_v2_layer_stack -> reusable_update_v2_layer_arn_docs
119+
publish_layer:
120+
needs: release
121+
secrets: inherit
138122
permissions:
123+
id-token: write
139124
contents: write
140125
pages: write
141-
uses: ./.github/workflows/reusable_publish_docs.yml
142-
with:
143-
version: ${{ needs.release.outputs.RELEASE_VERSION }}
144-
alias: ${{ needs.prepare_docs_alias.outputs.DOCS_ALIAS }}
145-
detached_mode: true
146-
147-
publish_layer:
148-
needs: release
149126
uses: ./.github/workflows/publish_v2_layer.yml
150127
with:
151128
latest_published_version: ${{ needs.release.outputs.RELEASE_VERSION }}
129+
pre_release: ${{ github.event.release.prerelease || inputs.pre_release }}
152130

153131
post_release:
154-
needs: release
132+
needs: [release, publish_layer]
155133
permissions:
156134
contents: read
157135
issues: write

Diff for: .github/workflows/publish_v2_layer.yml

+50-15
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,44 @@ name: Deploy v2 layer to all regions
22

33
permissions:
44
id-token: write
5-
contents: read
5+
contents: write
6+
pages: write
67

78
on:
89
workflow_dispatch:
910
inputs:
1011
latest_published_version:
11-
description: "Latest PyPi published version to rebuild latest docs for, e.g. v2.0.0"
12+
description: "Latest PyPi published version to rebuild latest docs for, e.g. 2.0.0, v2.0.0.a0 (pre-release)"
1213
required: true
14+
pre_release:
15+
description: "Publishes documentation using a pre-release tag (v2.0.0.a0)."
16+
default: false
17+
type: boolean
18+
required: false
19+
test_role:
20+
type: string
21+
description: "Test IAM Role ARN"
22+
required: false
1323
workflow_call:
1424
inputs:
1525
latest_published_version:
1626
type: string
17-
description: "Latest PyPi published version to rebuild latest docs for, e.g. v2.0.0"
27+
description: "Latest PyPi published version to rebuild latest docs for, e.g. 2.0.0, v2.0.0.a0 (pre-release)"
1828
required: true
29+
pre_release:
30+
description: "Publishes documentation using a pre-release tag (v2.0.0.a0)."
31+
default: false
32+
type: boolean
33+
required: false
1934

2035
jobs:
2136
build-layer:
37+
permissions:
38+
contents: read
2239
runs-on: ubuntu-latest
2340
defaults:
2441
run:
2542
working-directory: ./layer
26-
outputs:
27-
release-tag-version: ${{ steps.release-notes-tag.outputs.RELEASE_TAG_VERSION }}
2843
steps:
2944
- name: checkout
3045
uses: actions/checkout@v3
@@ -47,13 +62,6 @@ jobs:
4762
run: |
4863
poetry export --format requirements.txt --output requirements.txt
4964
pip install -r requirements.txt
50-
- name: Set release notes tag
51-
id: release-notes-tag
52-
run: |
53-
RELEASE_INPUT=${{ inputs.latest_published_version }}
54-
LATEST_TAG=$(git describe --tag --abbrev=0)
55-
RELEASE_TAG_VERSION=${RELEASE_INPUT:-$LATEST_TAG}
56-
echo RELEASE_TAG_VERSION="${RELEASE_TAG_VERSION:1}" >> "$GITHUB_OUTPUT"
5765
- name: Set up QEMU
5866
uses: docker/setup-qemu-action@8b122486cedac8393e77aa9734c3528886e4a1a8 # v2.0.0
5967
# NOTE: we need QEMU to build Layer against a different architecture (e.g., ARM)
@@ -65,7 +73,7 @@ jobs:
6573
npm install -g [email protected]
6674
cdk --version
6775
- name: CDK build
68-
run: cdk synth --context version="${{ steps.release-notes-tag.outputs.RELEASE_TAG_VERSION }}" -o cdk.out
76+
run: cdk synth --context version="${{ inputs.latest_published_version }}" -o cdk.out
6977
- name: zip output
7078
run: zip -r cdk.out.zip cdk.out
7179
- name: Archive CDK artifacts
@@ -102,7 +110,7 @@ jobs:
102110
stage: "BETA"
103111
artefact-name: "cdk-layer-artefact"
104112
environment: "layer-beta"
105-
package-version: ${{ needs.build-layer.outputs.release-tag-version }}
113+
package-version: ${{ inputs.latest_published_version }}
106114

107115
deploy-sar-prod:
108116
needs: [build-layer, deploy-sar-beta]
@@ -112,4 +120,31 @@ jobs:
112120
stage: "PROD"
113121
artefact-name: "cdk-layer-artefact"
114122
environment: "layer-prod"
115-
package-version: ${{ needs.build-layer.outputs.release-tag-version }}
123+
package-version: ${{ inputs.latest_published_version }}
124+
125+
prepare_docs_alias:
126+
runs-on: ubuntu-latest
127+
permissions:
128+
contents: read
129+
outputs:
130+
DOCS_ALIAS: ${{ steps.set-alias.outputs.DOCS_ALIAS }}
131+
steps:
132+
- name: Set docs alias
133+
id: set-alias
134+
run: |
135+
DOCS_ALIAS=latest
136+
if [[ "${{ inputs.pre_release }}" == true ]] ; then
137+
DOCS_ALIAS=alpha
138+
fi
139+
echo DOCS_ALIAS="$DOCS_ALIAS" >> "$GITHUB_OUTPUT"
140+
141+
release-docs:
142+
needs: [deploy-prod, prepare_docs_alias]
143+
permissions:
144+
contents: write
145+
pages: write
146+
uses: ./.github/workflows/reusable_publish_docs.yml
147+
with:
148+
version: ${{ inputs.latest_published_version }}
149+
alias: ${{ needs.prepare_docs_alias.outputs.DOCS_ALIAS }}
150+
detached_mode: true

Diff for: .github/workflows/reusable_deploy_v2_layer_stack.yml

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
name: Deploy CDK Layer v2 stack
22

3-
permissions:
4-
id-token: write
5-
contents: read
6-
73
env:
84
CDK_VERSION: 2.44.0
95

6+
permissions:
7+
id-token: write
8+
contents: write
9+
1010
on:
1111
workflow_call:
1212
inputs:
@@ -68,7 +68,7 @@ jobs:
6868
- name: Install poetry
6969
run: pipx install poetry
7070
- name: aws credentials
71-
uses: aws-actions/configure-aws-credentials@v1
71+
uses: aws-actions/configure-aws-credentials@67fbcbb121271f7775d2e7715933280b06314838
7272
with:
7373
aws-region: ${{ matrix.region }}
7474
role-to-assume: ${{ secrets.AWS_LAYERS_ROLE_ARN }}
@@ -110,14 +110,14 @@ jobs:
110110
- name: CDK Deploy Canary
111111
run: cdk deploy --app cdk.out --context region=${{ matrix.region}} --parameters DeployStage="${{ inputs.stage }}" 'CanaryV2Stack' --require-approval never --verbose
112112
- name: Save Layer ARN artifact
113-
uses: actions/upload-artifacts@v3
113+
uses: actions/upload-artifact@v3
114114
with:
115115
name: cdk-layer-stack
116116
path: cdk-layer-stack*
117117

118118
update_v2_layer_arn_docs:
119-
permissions:
120-
contents: write
119+
needs: deploy-cdk-stack
120+
if: ${{ inputs.stage == 'PROD' }}
121121
uses: ./.github/workflows/reusable_update_v2_layer_arn_docs.yml
122122
with:
123123
latest_published_version: ${{ inputs.latest_published_version }}

Diff for: .github/workflows/reusable_deploy_v2_sar.yml

+30-6
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ jobs:
5050
- name: Checkout
5151
uses: actions/checkout@v3
5252
- name: AWS credentials
53-
uses: aws-actions/configure-aws-credentials@v1
53+
uses: aws-actions/configure-aws-credentials@67fbcbb121271f7775d2e7715933280b06314838
5454
with:
5555
aws-region: ${{ env.AWS_REGION }}
5656
role-to-assume: ${{ secrets.AWS_LAYERS_ROLE_ARN }}
5757
- name: AWS credentials SAR role
58-
uses: aws-actions/configure-aws-credentials@v1
58+
uses: aws-actions/configure-aws-credentials@67fbcbb121271f7775d2e7715933280b06314838
5959
id: aws-credentials-sar-role
6060
with:
6161
aws-access-key-id: ${{ env.AWS_ACCESS_KEY_ID }}
@@ -83,18 +83,35 @@ jobs:
8383
- name: Adds arm64 suffix to SAR name
8484
if: ${{ matrix.architecture == 'arm64' }}
8585
run: echo SAR_NAME="${SAR_NAME}-arm64" >> "$GITHUB_ENV"
86-
- name: Deploy SAR
86+
- name: Normalize semantic version
87+
id: semantic-version # v2.0.0.a0 -> v2.0.0-a0
88+
env:
89+
VERSION: ${{ inputs.package-version }}
90+
run: |
91+
VERSION="${VERSION/.a/-a}"
92+
echo "VERSION=${VERSION}" >> "$GITHUB_OUTPUT"
93+
- name: Prepare SAR App
94+
env:
95+
VERSION: ${{ steps.semantic-version.outputs.VERSION }}
8796
run: |
8897
# From the generated LayerStack cdk.out artifact, find the layer asset path for the correct architecture.
8998
# We'll use this as the source directory of our SAR. This way we are re-using the same layer asset for our SAR.
9099
asset=$(jq -jc '.Resources[] | select(.Properties.CompatibleArchitectures == ["${{ matrix.architecture }}"]) | .Metadata."aws:asset:path"' cdk.out/LayerV2Stack.template.json)
91100
92101
# fill in the SAR SAM template
93-
sed -e "s|<VERSION>|${{ inputs.package-version }}|g" -e "s/<SAR_APP_NAME>/${{ env.SAR_NAME }}/g" -e "s|<LAYER_CONTENT_PATH>|./cdk.out/$asset|g" layer/sar/template.txt > template.yml
102+
sed \
103+
-e "s|<VERSION>|${VERSION}|g" \
104+
-e "s/<SAR_APP_NAME>/${{ env.SAR_NAME }}/g" \
105+
-e "s|<LAYER_CONTENT_PATH>|./cdk.out/$asset|g" \
106+
layer/sar/template.txt > template.yml
94107
95108
# SAR needs a README and a LICENSE, so just copy the ones from the repo
96109
cp README.md LICENSE "./cdk.out/$asset/"
97110
111+
# Debug purposes
112+
cat template.yml
113+
- name: Deploy SAR
114+
run: |
98115
# Package the SAR to our SAR S3 bucket, and publish it
99116
sam package --template-file template.yml --output-template-file packaged.yml --s3-bucket ${{ secrets.AWS_SAR_S3_BUCKET }}
100117
sam publish --template packaged.yml --region "$AWS_REGION"
@@ -116,11 +133,16 @@ jobs:
116133
117134
echo "Creating canary stack"
118135
echo "Stack name: $TEST_STACK_NAME"
119-
aws serverlessrepo create-cloud-formation-change-set --application-id arn:aws:serverlessrepo:${{ env.AWS_REGION }}:${{ steps.aws-credentials-sar-role.outputs.aws-account-id }}:applications/${{ env.SAR_NAME }} --stack-name "${TEST_STACK_NAME/serverlessrepo-/}" --capabilities CAPABILITY_NAMED_IAM
136+
aws serverlessrepo create-cloud-formation-change-set \
137+
--application-id arn:aws:serverlessrepo:${{ env.AWS_REGION }}:${{ steps.aws-credentials-sar-role.outputs.aws-account-id }}:applications/${{ env.SAR_NAME }} \
138+
--stack-name "${TEST_STACK_NAME/serverlessrepo-/}" \
139+
--capabilities CAPABILITY_NAMED_IAM
140+
120141
CHANGE_SET_ID=$(aws cloudformation list-change-sets --stack-name "$TEST_STACK_NAME" --query 'Summaries[*].ChangeSetId' --output text)
121142
aws cloudformation wait change-set-create-complete --change-set-name "$CHANGE_SET_ID"
122143
aws cloudformation execute-change-set --change-set-name "$CHANGE_SET_ID"
123144
aws cloudformation wait stack-create-complete --stack-name "$TEST_STACK_NAME"
145+
124146
echo "Waiting until stack deployment completes..."
125147
126148
echo "Exit with error if stack is not in CREATE_COMPLETE"
@@ -136,4 +158,6 @@ jobs:
136158
# wait until SAR registers the app, otherwise it fails to make it public
137159
sleep 15
138160
echo "Make SAR app public"
139-
aws serverlessrepo put-application-policy --application-id arn:aws:serverlessrepo:${{ env.AWS_REGION }}:${{ steps.aws-credentials-sar-role.outputs.aws-account-id }}:applications/${{ env.SAR_NAME }} --statements Principals='*',Actions=Deploy
161+
aws serverlessrepo put-application-policy \
162+
--application-id arn:aws:serverlessrepo:${{ env.AWS_REGION }}:${{ steps.aws-credentials-sar-role.outputs.aws-account-id }}:applications/${{ env.SAR_NAME }} \
163+
--statements Principals='*',Actions=Deploy

Diff for: .github/workflows/reusable_update_v2_layer_arn_docs.yml

-10
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,3 @@ jobs:
4848
git commit -m "chore: update v2 layer ARN on documentation"
4949
git pull origin "${BRANCH}" # prevents concurrent branch update failing push
5050
git push origin HEAD:refs/heads/"${BRANCH}"
51-
52-
release-docs:
53-
needs: publish_v2_layer_arn
54-
permissions:
55-
contents: write
56-
pages: write
57-
uses: ./.github/workflows/reusable_publish_docs.yml
58-
with:
59-
version: ${{ inputs.latest_published_version }}
60-
alias: latest

0 commit comments

Comments
 (0)