From 4343602cf928e7016d6d65ed54f5e5173c562c3e Mon Sep 17 00:00:00 2001 From: Leandro Damascena Date: Fri, 28 Aug 2026 11:57:54 +0100 Subject: [PATCH 1/2] adding workflows --- .github/workflows/simulate-release.yml | 76 ++++++++++++++++++++++++++ .github/workflows/sync-to-s3.yml | 45 +++++++++++++++ 2 files changed, 121 insertions(+) create mode 100644 .github/workflows/simulate-release.yml create mode 100644 .github/workflows/sync-to-s3.yml diff --git a/.github/workflows/simulate-release.yml b/.github/workflows/simulate-release.yml new file mode 100644 index 0000000..494a706 --- /dev/null +++ b/.github/workflows/simulate-release.yml @@ -0,0 +1,76 @@ +name: Simulate release + +on: + workflow_dispatch: + +permissions: + contents: write + id-token: write + +concurrency: + group: simulate-release + cancel-in-progress: false + +env: + AWS_REGION: us-west-2 + RELEASE_TAG: sync-test-${{ github.run_number }}-${{ github.run_attempt }} + +jobs: + release: + name: Create and sync release + runs-on: ubuntu-latest + timeout-minutes: 15 + + steps: + - name: Check out repository + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - name: Create test artifacts + run: | + set -euo pipefail + mkdir -p release-assets + + for platform in linux-x86_64 linux-arm64 macos-arm64; do + mkdir -p "staging/${platform}" + printf '%s\n' \ + "Dummy aws-lambda-cpp release artifact" \ + "Platform: ${platform}" \ + "Release: ${RELEASE_TAG}" \ + "Commit: ${GITHUB_SHA}" \ + > "staging/${platform}/README.txt" + + ( + cd "staging/${platform}" + zip -q "../../release-assets/aws-lambda-cpp-${platform}.zip" README.txt + ) + done + + - name: Create GitHub prerelease + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + set -euo pipefail + gh release create "${RELEASE_TAG}" release-assets/*.zip \ + --repo "${GITHUB_REPOSITORY}" \ + --target "${GITHUB_SHA}" \ + --title "Sync test ${RELEASE_TAG}" \ + --notes "Automated test release containing three dummy ZIP artifacts." \ + --prerelease + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@e6de054238d6b7531b4efff3b6587d9aade6a06c # v6.2.3 + with: + role-to-assume: ${{ secrets.AWS_ROLE_ARN }} + aws-region: ${{ env.AWS_REGION }} + role-session-name: github-actions-release-${{ github.run_id }} + + - name: Sync release artifacts to S3 + env: + S3_BUCKET_NAME: ${{ secrets.S3_BUCKET_NAME }} + run: | + set -euo pipefail + aws s3 sync release-assets/ \ + "s3://${S3_BUCKET_NAME}/releases/${RELEASE_TAG}/" \ + --no-progress diff --git a/.github/workflows/sync-to-s3.yml b/.github/workflows/sync-to-s3.yml new file mode 100644 index 0000000..97b4cd4 --- /dev/null +++ b/.github/workflows/sync-to-s3.yml @@ -0,0 +1,45 @@ +name: Sync repository to S3 + +on: + workflow_dispatch: + +permissions: + contents: read + id-token: write + +concurrency: + group: sync-repository-to-s3 + cancel-in-progress: false + +env: + AWS_REGION: us-west-2 + +jobs: + sync: + name: Sync repository + runs-on: ubuntu-latest + timeout-minutes: 15 + + steps: + - name: Check out repository + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@e6de054238d6b7531b4efff3b6587d9aade6a06c # v6.2.3 + with: + role-to-assume: ${{ secrets.AWS_ROLE_ARN }} + aws-region: ${{ env.AWS_REGION }} + role-session-name: github-actions-s3-sync-${{ github.run_id }} + + - name: Sync repository to S3 + env: + S3_BUCKET_NAME: ${{ secrets.S3_BUCKET_NAME }} + run: | + set -euo pipefail + aws s3 sync . "s3://${S3_BUCKET_NAME}/" \ + --delete \ + --exclude ".git/*" \ + --exclude "releases/*" \ + --no-progress From feb773fbcc981f59c8287c2f7557f7ce668d9ef5 Mon Sep 17 00:00:00 2001 From: Leandro Damascena Date: Fri, 28 Aug 2026 13:40:24 +0100 Subject: [PATCH 2/2] Adding additional permissions to e2e test --- .github/workflows/simulate-release.yml | 43 +++++++++++++++++- .github/workflows/sync-to-s3.yml | 61 ++++++++++++++++++++++---- 2 files changed, 93 insertions(+), 11 deletions(-) diff --git a/.github/workflows/simulate-release.yml b/.github/workflows/simulate-release.yml index 494a706..7b93c89 100644 --- a/.github/workflows/simulate-release.yml +++ b/.github/workflows/simulate-release.yml @@ -8,7 +8,7 @@ permissions: id-token: write concurrency: - group: simulate-release + group: repository-replication cancel-in-progress: false env: @@ -73,4 +73,43 @@ jobs: set -euo pipefail aws s3 sync release-assets/ \ "s3://${S3_BUCKET_NAME}/releases/${RELEASE_TAG}/" \ - --no-progress + --no-progress \ + --only-show-errors + + - name: Replicate release artifacts + env: + SYNC_FUNCTION_ARN: ${{ secrets.SYNC_FUNCTION_ARN }} + SYNC_REQUEST_CONFIG: ${{ secrets.SYNC_REQUEST_CONFIG }} + run: | + set -euo pipefail + + for artifact in release-assets/*.zip; do + artifact_key="releases/${RELEASE_TAG}/$(basename "${artifact}")" + + jq -n \ + --argjson config "${SYNC_REQUEST_CONFIG}" \ + --arg source_path "${artifact_key}" \ + --arg repository "${GITHUB_REPOSITORY}" \ + --arg commit "${GITHUB_SHA}" \ + '$config + { + s3FilePath: $source_path, + gitHubRepo: $repository, + gitHubCommit: $commit, + extractArchive: false + }' > /tmp/sync-request.json + + function_error="$(aws lambda invoke \ + --function-name "${SYNC_FUNCTION_ARN}" \ + --cli-binary-format raw-in-base64-out \ + --payload file:///tmp/sync-request.json \ + --query FunctionError \ + --output text \ + /tmp/sync-response.json)" + + if [[ "${function_error}" != "None" ]]; then + echo "Replication failed; inspect the function logs for details." >&2 + exit 1 + fi + + printf 'Replicated %s successfully.\n' "${artifact_key}" + done diff --git a/.github/workflows/sync-to-s3.yml b/.github/workflows/sync-to-s3.yml index 97b4cd4..f96f278 100644 --- a/.github/workflows/sync-to-s3.yml +++ b/.github/workflows/sync-to-s3.yml @@ -1,4 +1,4 @@ -name: Sync repository to S3 +name: Replicate repository on: workflow_dispatch: @@ -8,15 +8,16 @@ permissions: id-token: write concurrency: - group: sync-repository-to-s3 + group: repository-replication cancel-in-progress: false env: AWS_REGION: us-west-2 + SOURCE_SNAPSHOT_KEY: aws-lambda-cpp.tgz jobs: sync: - name: Sync repository + name: Sync source snapshot runs-on: ubuntu-latest timeout-minutes: 15 @@ -33,13 +34,55 @@ jobs: aws-region: ${{ env.AWS_REGION }} role-session-name: github-actions-s3-sync-${{ github.run_id }} - - name: Sync repository to S3 + - name: Create source snapshot + run: | + set -euo pipefail + tar \ + --exclude=".git" \ + -czf "/tmp/${SOURCE_SNAPSHOT_KEY}" \ + -C "${GITHUB_WORKSPACE}" \ + . + + - name: Upload source snapshot to S3 env: S3_BUCKET_NAME: ${{ secrets.S3_BUCKET_NAME }} run: | set -euo pipefail - aws s3 sync . "s3://${S3_BUCKET_NAME}/" \ - --delete \ - --exclude ".git/*" \ - --exclude "releases/*" \ - --no-progress + aws s3 cp \ + "/tmp/${SOURCE_SNAPSHOT_KEY}" \ + "s3://${S3_BUCKET_NAME}/${SOURCE_SNAPSHOT_KEY}" \ + --no-progress \ + --only-show-errors + + - name: Replicate source snapshot + env: + SYNC_FUNCTION_ARN: ${{ secrets.SYNC_FUNCTION_ARN }} + SYNC_REQUEST_CONFIG: ${{ secrets.SYNC_REQUEST_CONFIG }} + run: | + set -euo pipefail + + jq -e \ + --arg source_path "${SOURCE_SNAPSHOT_KEY}" \ + --arg repository "${GITHUB_REPOSITORY}" \ + --arg commit "${GITHUB_SHA}" \ + '. + { + s3FilePath: $source_path, + gitHubRepo: $repository, + gitHubCommit: $commit, + extractArchive: true + }' <<< "${SYNC_REQUEST_CONFIG}" > /tmp/sync-request.json + + function_error="$(aws lambda invoke \ + --function-name "${SYNC_FUNCTION_ARN}" \ + --cli-binary-format raw-in-base64-out \ + --payload file:///tmp/sync-request.json \ + --query FunctionError \ + --output text \ + /tmp/sync-response.json)" + + if [[ "${function_error}" != "None" ]]; then + echo "Replication failed; inspect the function logs for details." >&2 + exit 1 + fi + + echo "Source snapshot replicated successfully."