-
Notifications
You must be signed in to change notification settings - Fork 98
118 lines (98 loc) · 3.86 KB
/
Copy pathreplicate-source.yml
File metadata and controls
118 lines (98 loc) · 3.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
name: Replicate source
on:
workflow_dispatch:
schedule:
# Avoid the start of the hour, when scheduled Actions experience higher load.
- cron: '17 * * * *'
permissions:
contents: read
id-token: write
concurrency:
group: repository-replication
cancel-in-progress: false
env:
AWS_REGION: us-west-2
jobs:
replicate:
name: Replicate source snapshot
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-24.04
timeout-minutes: 15
environment: replication
steps:
- name: Check out triggering commit
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.sha }}
fetch-depth: 1
persist-credentials: false
- name: Create immutable source snapshot
id: snapshot
run: |
set -euo pipefail
commit="$(git rev-parse HEAD)"
archive="/tmp/aws-lambda-cpp-${commit}.tgz"
object_key="source/${commit}.tgz"
git archive \
--format=tar.gz \
--output="${archive}" \
"${commit}"
gzip -t "${archive}"
tar -tzf "${archive}" >/dev/null
archive_sha256="$(sha256sum "${archive}" | awk '{print $1}')"
echo "archive=${archive}" >> "${GITHUB_OUTPUT}"
echo "commit=${commit}" >> "${GITHUB_OUTPUT}"
echo "object_key=${object_key}" >> "${GITHUB_OUTPUT}"
echo "sha256=${archive_sha256}" >> "${GITHUB_OUTPUT}"
- name: Verify source snapshot integrity
env:
SOURCE_ARCHIVE: ${{ steps.snapshot.outputs.archive }}
SOURCE_COMMIT: ${{ steps.snapshot.outputs.commit }}
SOURCE_SHA256: ${{ steps.snapshot.outputs.sha256 }}
TRIGGER_COMMIT: ${{ github.sha }}
run: |
set -euo pipefail
if [[ "${SOURCE_COMMIT}" != "${TRIGGER_COMMIT}" ]]; then
echo "The snapshot commit does not match the triggering commit." >&2
exit 1
fi
if [[ "${SOURCE_COMMIT}" != "$(git rev-parse HEAD)" ]]; then
echo "The snapshot commit does not match the checked-out commit." >&2
exit 1
fi
echo "${SOURCE_SHA256} ${SOURCE_ARCHIVE}" | sha256sum --check --strict
gzip -t "${SOURCE_ARCHIVE}"
while IFS= read -r archive_path; do
if [[ "/${archive_path}/" == *"/.git/"* ]]; then
echo "The snapshot unexpectedly contains Git metadata." >&2
exit 1
fi
done < <(tar -tzf "${SOURCE_ARCHIVE}")
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@e6de054238d6b7531b4efff3b6587d9aade6a06c # v6.2.3
with:
role-to-assume: ${{ secrets.REPLICATION_ROLE_ARN }}
aws-region: ${{ env.AWS_REGION }}
role-session-name: repository-replication-${{ github.run_id }}
mask-aws-account-id: true
- name: Upload source snapshot
env:
REPLICATION_BUCKET_NAME: ${{ secrets.REPLICATION_BUCKET_NAME }}
SOURCE_ARCHIVE: ${{ steps.snapshot.outputs.archive }}
SOURCE_COMMIT: ${{ steps.snapshot.outputs.commit }}
SOURCE_KEY: ${{ steps.snapshot.outputs.object_key }}
SOURCE_SHA256: ${{ steps.snapshot.outputs.sha256 }}
run: |
set -euo pipefail
version_id="$(aws s3api put-object \
--bucket "${REPLICATION_BUCKET_NAME}" \
--key "${SOURCE_KEY}" \
--body "${SOURCE_ARCHIVE}" \
--checksum-algorithm SHA256 \
--metadata "source-commit=${SOURCE_COMMIT},sha256=${SOURCE_SHA256}" \
--query VersionId \
--output text)"
if [[ -z "${version_id}" || "${version_id}" == "None" || "${version_id}" == "null" ]]; then
echo "The upload did not return an S3 object version." >&2
exit 1
fi