Skip to content

Commit

Permalink
chore(ci): add new script to bump Lambda layer version (#6001)
Browse files Browse the repository at this point in the history
* Adding new script to bump layer version

* Adding new script to bump layer version

* Making changes to work with GNU sed
  • Loading branch information
leandrodamascena authored Feb 5, 2025
1 parent 196529b commit d355fde
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 21 deletions.
40 changes: 19 additions & 21 deletions .github/workflows/publish_v3_layer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ on:
latest_published_version:
description: "Latest PyPi published version to rebuild latest docs for, e.g. 3.0.0, 3.0.0a1 (pre-release)"
required: true
layer_documentation_version:
description: "Version to be updated in our documentation. e.g. if the current layer number is 3, this value must be 4."
required: true
source_code_artifact_name:
description: "Artifact name to restore sealed source code"
type: string
Expand All @@ -52,6 +55,10 @@ on:
type: string
description: "Latest PyPi published version to rebuild latest docs for, e.g. 3.0.0, 3.0.0a1 (pre-release)"
required: true
layer_documentation_version:
type: string
description: "Version to be updated in our documentation. e.g. if the current layer number is 3, this value must be 4."
required: true
pre_release:
description: "Publishes documentation using a pre-release tag (3.0.0a1)."
default: false
Expand Down Expand Up @@ -257,29 +264,20 @@ jobs:
integrity_hash: ${{ inputs.source_code_integrity_hash }}
artifact_name: ${{ inputs.source_code_artifact_name }}

# UNCOMMENT THIS
# - name: Download CDK layer artifacts
# uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4.1.7
# with:
# path: cdk-layer-stack
# pattern: cdk-layer-stack-* # merge all Layer artifacts created per region earlier (reusable_deploy_v2_layer_stack.yml; step "Save Layer ARN artifact")
# merge-multiple: true
# - name: Replace layer versions in documentation
# run: |
# ls -la cdk-layer-stack/
# ./layer_v3/scripts/update_layer_arn.sh cdk-layer-stack
- name: Replace layer versions in documentation
run: ./layer_v3/scripts/update_layer_arn_v3.sh ${{ inputs.layer_documentation_version }}
# NOTE: It felt unnecessary creating yet another PR to update changelog w/ latest tag
# since this is the only step in the release where we update docs from a temp branch
# - name: Update changelog with latest tag
# run: make changelog
# - name: Create PR
# id: create-pr
# uses: ./.github/actions/create-pr
# with:
# files: "docs/index.md examples CHANGELOG.md"
# temp_branch_prefix: "ci-layer-docs"
# pull_request_title: "chore(ci): layer docs update"
# github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Update changelog with latest tag
run: make changelog
- name: Create PR
id: create-pr
uses: ./.github/actions/create-pr
with:
files: "docs/index.md docs/includes/_layer_homepage_arm64.md docs/includes/_layer_homepage_x86.md examples CHANGELOG.md"
temp_branch_prefix: "ci-layer-docs"
pull_request_title: "chore(ci): layer docs update"
github_token: ${{ secrets.GITHUB_TOKEN }}

prepare_docs_alias:
runs-on: ubuntu-latest
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/release-v3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ on:
description: "Version to be released in PyPi, Docs, and Lambda Layer, e.g. v3.0.0, v3.0.0a0 (pre-release)"
default: v3.0.0
required: true
layer_documentation_version:
description: "Lambda layer version to be updated in our documentation. e.g. if the current layer number is 3, this value must be 4."
type: string
required: true
skip_pypi:
description: "Skip publishing to PyPi as it can't publish more than once. Useful for semi-failed releases"
default: false
Expand Down Expand Up @@ -342,6 +346,7 @@ jobs:
uses: ./.github/workflows/publish_v3_layer.yml
with:
latest_published_version: ${{ needs.seal.outputs.RELEASE_VERSION }}
layer_documentation_version: ${{ inputs.layer_documentation_version }}
pre_release: ${{ inputs.pre_release }}
source_code_artifact_name: ${{ needs.seal.outputs.artifact_name }}
source_code_integrity_hash: ${{ needs.seal.outputs.integrity_hash }}
Expand Down
38 changes: 38 additions & 0 deletions layer_v3/scripts/update_layer_arn_v3.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

# This script is run during the publish_v3_layer.yml CI job,
# and it is responsible for replacing the layer ARN in our documentation.
# Our pipeline must generate the same layer number for all commercial regions + gov cloud
# If this doesn't happens, we have an error and we must fix it in the deployment.
#
# see .github/workflows/reusable_deploy_v3_layer_stack.yml


# Get the new version number from the first command-line argument
new_version=$1
if [ -z "$new_version" ]; then
echo "Usage: $0 <new_version>"
exit 1
fi

# Find all files with specified extensions in ./docs and ./examples directories
# -type f: only find files (not directories)
# \( ... \): group conditions
# -o: logical OR
# -print0: use null character as separator (handles filenames with spaces)
find ./docs ./examples -type f \( -name "*.md" -o -name "*.py" -o -name "*.yaml" -o -name "*.txt" -o -name "*.tf" -o -name "*.yml" \) -print0 | while IFS= read -r -d '' file; do
echo "Processing file: $file"

# Use sed to replace the version number in the Lambda layer ARN
# -i: edit files in-place without creating a backup
# -E: use extended regular expressions
# The regex matches the layer name and replaces only the version number at the end
sed -i -E "s/(AWSLambdaPowertoolsPythonV3-python[0-9]+-((arm64)|(x86_64)):)[0-9]+/\1$new_version/g" "$file"
if [ $? -eq 0 ]; then
echo "Updated $file successfully"
grep "arn:aws:lambda:" "$file"
else
echo "Error processing $file"
fi
done
echo "Layer version update attempt completed."

0 comments on commit d355fde

Please sign in to comment.