Skip to content

Commit a89f0f4

Browse files
presempathy-awbfarhan-syah
authored andcommitted
ci(release): verify selected prepare artifacts
1 parent 031db94 commit a89f0f4

4 files changed

Lines changed: 136 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,23 @@ jobs:
126126
ref: ${{ inputs.tag }}
127127
fetch-depth: 0
128128

129+
- name: Read prepare run metadata
130+
env:
131+
GITHUB_TOKEN: ${{ github.token }}
132+
PREPARE_RUN_ID: ${{ inputs.prepare_run_id }}
133+
run: |
134+
set -euo pipefail
135+
[[ "$PREPARE_RUN_ID" =~ ^[0-9]+$ ]] || {
136+
echo "::error::prepare_run_id must be numeric"
137+
exit 1
138+
}
139+
curl --fail --location --silent --show-error \
140+
-H "Accept: application/vnd.github+json" \
141+
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
142+
-H "X-GitHub-Api-Version: 2022-11-28" \
143+
"https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/runs/${PREPARE_RUN_ID}" \
144+
--output "$RUNNER_TEMP/prepare-run.json"
145+
129146
- name: Download fsck artifacts
130147
uses: actions/download-artifact@v8
131148
with:
@@ -135,6 +152,17 @@ jobs:
135152
path: ./artifacts
136153
merge-multiple: true
137154

155+
- name: Verify prepared release
156+
env:
157+
VERSION: ${{ needs.validate-version.outputs.version }}
158+
run: |
159+
set -euo pipefail
160+
bash scripts/ci/verify_release_artifacts.sh \
161+
"$RUNNER_TEMP/prepare-run.json" \
162+
./artifacts \
163+
"$VERSION" \
164+
"$(git rev-parse HEAD)"
165+
138166
- name: Create GitHub Release
139167
uses: softprops/action-gh-release@v3
140168
with:

.github/workflows/test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ jobs:
102102
exit 1
103103
fi
104104
105+
- name: Release artifact verification
106+
run: bash scripts/test-release-artifacts.sh
107+
105108
# ─────────────────────────────────────────────────────────────────────────
106109
test:
107110
name: Test (${{ matrix.os }})
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env bash
2+
# Verify that a successful Release Prepare run produced the exact release set.
3+
4+
set -euo pipefail
5+
6+
die() {
7+
printf 'release artifacts: %s\n' "$*" >&2
8+
exit 1
9+
}
10+
11+
run_json="${1:?usage: verify_release_artifacts.sh <run.json> <artifact-dir> <version> <commit>}"
12+
artifact_dir="${2:?usage: verify_release_artifacts.sh <run.json> <artifact-dir> <version> <commit>}"
13+
version="${3:?usage: verify_release_artifacts.sh <run.json> <artifact-dir> <version> <commit>}"
14+
commit="${4:?usage: verify_release_artifacts.sh <run.json> <artifact-dir> <version> <commit>}"
15+
16+
test -f "$run_json" || die "missing workflow-run metadata: $run_json"
17+
test -d "$artifact_dir" || die "missing artifact directory: $artifact_dir"
18+
[[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z][A-Za-z0-9-]*\.[0-9]+)?$ ]] ||
19+
die "invalid release version: $version"
20+
[[ "$commit" =~ ^[0-9a-f]{40}$ ]] || die "invalid release commit: $commit"
21+
22+
jq -e \
23+
--arg commit "$commit" \
24+
'.head_sha == $commit
25+
and .path == ".github/workflows/release-prepare.yml"
26+
and .event == "push"
27+
and .status == "completed"
28+
and .conclusion == "success"' \
29+
"$run_json" >/dev/null ||
30+
die "selected run is not a successful Release Prepare run for the tag commit"
31+
32+
expected=(
33+
"pagedb-fsck-${version}-linux-x64.tar.gz"
34+
"pagedb-fsck-${version}-linux-arm64.tar.gz"
35+
"pagedb-fsck-${version}-macos-arm64.tar.gz"
36+
"pagedb-fsck-${version}-macos-x64.tar.gz"
37+
"pagedb-fsck-${version}-windows-x64.zip"
38+
)
39+
40+
shopt -s nullglob dotglob
41+
entries=("$artifact_dir"/*)
42+
shopt -u nullglob dotglob
43+
test "${#entries[@]}" -eq "${#expected[@]}" ||
44+
die "expected exactly ${#expected[@]} release archives"
45+
46+
for entry in "${entries[@]}"; do
47+
test -f "$entry" && test ! -L "$entry" ||
48+
die "unexpected release artifact: $entry"
49+
done
50+
for archive in "${expected[@]}"; do
51+
test -f "$artifact_dir/$archive" ||
52+
die "missing release archive: $archive"
53+
done
54+
55+
printf 'release artifacts: ok\n'

scripts/test-release-artifacts.sh

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
5+
verifier="$repo_root/scripts/ci/verify_release_artifacts.sh"
6+
work_dir="$(mktemp -d)"
7+
trap 'rm -rf "$work_dir"' EXIT
8+
9+
version="0.2.0-beta.1"
10+
commit="0123456789abcdef0123456789abcdef01234567"
11+
run_json="$work_dir/run.json"
12+
artifacts="$work_dir/artifacts"
13+
14+
expect_failure() {
15+
local label="$1" metadata="$2" expected_commit="$3"
16+
shift
17+
shift 2
18+
if bash "$verifier" "$metadata" "$artifacts" "$version" "$expected_commit" \
19+
>"$work_dir/failure.log" 2>&1; then
20+
printf 'expected failure: %s\n' "$label" >&2
21+
exit 1
22+
fi
23+
}
24+
25+
jq -n --arg head_sha "$commit" \
26+
'{head_sha:$head_sha, path:".github/workflows/release-prepare.yml",
27+
event:"push", status:"completed", conclusion:"success"}' >"$run_json"
28+
mkdir "$artifacts"
29+
touch \
30+
"$artifacts/pagedb-fsck-${version}-linux-x64.tar.gz" \
31+
"$artifacts/pagedb-fsck-${version}-linux-arm64.tar.gz" \
32+
"$artifacts/pagedb-fsck-${version}-macos-arm64.tar.gz" \
33+
"$artifacts/pagedb-fsck-${version}-macos-x64.tar.gz" \
34+
"$artifacts/pagedb-fsck-${version}-windows-x64.zip"
35+
36+
bash "$verifier" "$run_json" "$artifacts" "$version" "$commit"
37+
38+
expect_failure "different tag commit" "$run_json" \
39+
"ffffffffffffffffffffffffffffffffffffffff"
40+
41+
jq '.conclusion = "failure"' "$run_json" >"$work_dir/failed-run.json"
42+
expect_failure "failed prepare run" "$work_dir/failed-run.json" "$commit"
43+
44+
touch "$artifacts/unexpected.txt"
45+
expect_failure "extra artifact" "$run_json" "$commit"
46+
47+
rm "$artifacts/unexpected.txt" "$artifacts/pagedb-fsck-${version}-windows-x64.zip"
48+
expect_failure "missing archive" "$run_json" "$commit"
49+
50+
printf 'release artifact verification: tests passed\n'

0 commit comments

Comments
 (0)