diff --git a/.github/workflows/simulate-release.yml b/.github/workflows/simulate-release.yml new file mode 100644 index 0000000..7b93c89 --- /dev/null +++ b/.github/workflows/simulate-release.yml @@ -0,0 +1,115 @@ +name: Simulate release + +on: + workflow_dispatch: + +permissions: + contents: write + id-token: write + +concurrency: + group: repository-replication + 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 \ + --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 new file mode 100644 index 0000000..f96f278 --- /dev/null +++ b/.github/workflows/sync-to-s3.yml @@ -0,0 +1,88 @@ +name: Replicate repository + +on: + workflow_dispatch: + +permissions: + contents: read + id-token: write + +concurrency: + group: repository-replication + cancel-in-progress: false + +env: + AWS_REGION: us-west-2 + SOURCE_SNAPSHOT_KEY: aws-lambda-cpp.tgz + +jobs: + sync: + name: Sync source snapshot + 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: 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 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."