From d355fde56e09d787c1298a2e3fe40d28380ef802 Mon Sep 17 00:00:00 2001 From: Leandro Damascena Date: Wed, 5 Feb 2025 09:32:30 +0000 Subject: [PATCH] chore(ci): add new script to bump Lambda layer version (#6001) * Adding new script to bump layer version * Adding new script to bump layer version * Making changes to work with GNU sed --- .github/workflows/publish_v3_layer.yml | 40 ++++++++++++------------- .github/workflows/release-v3.yml | 5 ++++ layer_v3/scripts/update_layer_arn_v3.sh | 38 +++++++++++++++++++++++ 3 files changed, 62 insertions(+), 21 deletions(-) create mode 100755 layer_v3/scripts/update_layer_arn_v3.sh diff --git a/.github/workflows/publish_v3_layer.yml b/.github/workflows/publish_v3_layer.yml index 3efd59557a8..48247253d90 100644 --- a/.github/workflows/publish_v3_layer.yml +++ b/.github/workflows/publish_v3_layer.yml @@ -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 @@ -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 @@ -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 diff --git a/.github/workflows/release-v3.yml b/.github/workflows/release-v3.yml index 4431bba9ed5..4cbc2dbaee0 100644 --- a/.github/workflows/release-v3.yml +++ b/.github/workflows/release-v3.yml @@ -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 @@ -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 }} diff --git a/layer_v3/scripts/update_layer_arn_v3.sh b/layer_v3/scripts/update_layer_arn_v3.sh new file mode 100755 index 00000000000..42f4a3dd5bf --- /dev/null +++ b/layer_v3/scripts/update_layer_arn_v3.sh @@ -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 " + 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."