Skip to content

Commit b481845

Browse files
committed
Used the output from the deploy layer workflow to get the latest deployed layer arn
1 parent 71b235b commit b481845

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

.github/scripts/update_layer_arn.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88
# see .github/workflows/publish_layer.yml
99

1010

11-
# Get the current layer version from SSM Parameter
12-
current_layer_arn=$(aws ssm get-parameter --name /aws/service/powertools/typescript/generic/all/latest --query Parameter.Value --output text --region us-east-1)
13-
current_layer_version=$(echo $current_layer_arn | sed 's/.*://')
14-
new_version=$((current_layer_version + 1))
11+
# Get the new layer arn from the first command-line argument
12+
new_layer_arn=$1
13+
if [ -z "$new_layer_arn" ]; then
14+
echo "Usage: $0 <new_layer_arn>"
15+
exit 1
16+
fi
17+
new_version=$(echo $new_layer_arn | sed 's/.*://')
1518

1619
# Find all files with specified extensions in ./docs and ./examples directories
1720
# -type f: only find files (not directories)

.github/workflows/publish_layer.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,9 @@ jobs:
9696
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
9797
with:
9898
ref: ${{ github.sha }}
99-
- id: creds
100-
uses: aws-actions/configure-aws-credentials@7474bc4690e29a8392af63c5b98e7449536d5c3a
101-
with:
102-
aws-region: us-east-1
103-
role-to-assume: ${{ secrets.US_EAST_1 }}
104-
mask-aws-account-id: true
10599
- name: Replace layer versions in documentation
106100
run: |
107-
./.github/scripts/update_layer_arn.sh
101+
./.github/scripts/update_layer_arn.sh ${{ needs.deploy-prod.outputs.layer-arn }}
108102
- name: Stage changes
109103
run: git add .
110104
- name: Create PR

.github/workflows/reusable_deploy_layer_stack.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ on:
1515
description: "Latest version that is published"
1616
required: true
1717
type: string
18+
outputs:
19+
layer-arn:
20+
description: "The latest deployed Layer ARN"
21+
value: ${{ jobs.deploy-cdk-stack.outputs.layer-arn }}
1822
secrets:
1923
target-account-role:
2024
required: true
@@ -65,6 +69,8 @@ jobs:
6569
"il-central-1",
6670
"mx-central-1"
6771
]
72+
outputs:
73+
layer-arn: ${{ steps.store-latest-layer-arn.outputs.layer-arn }}
6874
steps:
6975
- name: checkout
7076
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
@@ -89,11 +95,12 @@ jobs:
8995
- name: Deploy Layer
9096
run: npm run cdk -w layers -- deploy --app cdk.out --context region=${{ matrix.region }} 'LayerPublisherStack' --require-approval never --verbose --outputs-file cdk-outputs.json
9197
- name: Store latest Layer ARN
98+
id: store-latest-layer-arn
9299
if: ${{ inputs.stage == 'PROD' }}
93100
run: |
94101
mkdir cdk-layer-stack
95102
jq -r -c '.LayerPublisherStack.LatestLayerArn' layers/cdk-outputs.json > cdk-layer-stack/${{ matrix.region }}-layer-version.txt
96-
cat cdk-layer-stack/${{ matrix.region }}-layer-version.txt
103+
echo "layer-arn=$(cat cdk-layer-stack/${{ matrix.region }}-layer-version.txt)" | tee -a "$GITHUB_OUTPUT"
97104
- name: Save Layer ARN artifact
98105
if: ${{ inputs.stage == 'PROD' }}
99106
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2

0 commit comments

Comments
 (0)