Skip to content

Commit cbcea56

Browse files
committed
test: artifact hashes
1 parent 62267e2 commit cbcea56

File tree

2 files changed

+78
-30
lines changed

2 files changed

+78
-30
lines changed

.github/workflows/_build.yaml

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,35 +27,49 @@ on:
2727
type: boolean
2828
required: true
2929
description: Enable or disable running pip_audit to check installed packages for vulnerabilities
30-
outputs:
31-
artifacts-sha256:
32-
value: ${{ jobs.build.outputs.artifacts-sha256 }}
33-
description: The hash of the artifacts
3430
permissions:
3531
contents: read
3632
env:
37-
ARTIFACT_OS: ubuntu-latest # The default OS for release.
38-
ARTIFACT_PYTHON: '3.13' # The default Python version for release.
33+
RELEASE_OS_X86_64: ubuntu-24.04 # Default OS for x86_64-compatible release artifacts.
34+
RELEASE_OS_ARM64: ubuntu-24.04-arm # Default OS for ARM64-compatible release artifacts.
35+
RELEASE_PYTHON_VERSION: '3.13' # Default Python version used for release artifacts.
3936

4037
jobs:
4138
build:
4239
# Uncomment the following to disable checks and tests for Draft pull requests.
4340
# if: github.event.pull_request.draft == false
44-
outputs:
45-
artifacts-sha256: ${{ steps.compute-hash.outputs.artifacts-sha256 }}
4641
name: Build Python ${{ matrix.python }} on ${{ matrix.os }}
4742
runs-on: ${{ matrix.os }}
4843
strategy:
4944
fail-fast: false
5045
matrix:
5146
# It is recommended to pin a Runner version specifically:
5247
# https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners
53-
# os: [ubuntu-24.04, ubuntu-24.04-arm, macos-latest, windows-latest]
54-
os: [ubuntu-24.04, ubuntu-24.04-arm]
48+
os: [ubuntu-24.04, ubuntu-24.04-arm, macos-latest, windows-latest]
5549
python: ['3.10', '3.11', '3.12', '3.13']
5650

51+
outputs:
52+
arch-env: ${{ steps.set-arch-env.outputs.arch_env }}
53+
5754
steps:
5855

56+
# Create a GitHub Actions environment variable that maps a matrix.os value to a more descriptive environment
57+
# value (e.g., ubuntu-x86-64 or ubuntu-arm64).
58+
- name: Determine architecture label
59+
id: set-arch-env
60+
shell: bash
61+
run: |
62+
if [[ "${{ matrix.os }}" == "ubuntu-24.04" ]]; then
63+
echo "arch_env=ubuntu-x86-64" >> "$GITHUB_OUTPUT"
64+
elif [[ "${{ matrix.os }}" == "ubuntu-24.04-arm" ]]; then
65+
echo "arch_env=ubuntu-arm64" >> "$GITHUB_OUTPUT"
66+
else
67+
echo "arch_env=unknown" >> "$GITHUB_OUTPUT"
68+
fi
69+
70+
- name: Test the env variable
71+
run: echo "Architecture-specific value ${{ steps.set-arch-env.outputs.arch_env }}"
72+
5973
- name: Harden Runner
6074
uses: step-security/harden-runner@c6295a65d1254861815972266d5933fd6e532bdf # v2.11.1
6175
with:
@@ -99,24 +113,33 @@ jobs:
99113
HYPOTHESIS_PROFILE: github
100114

101115
# Generate the requirements.txt that contains the hash digests of the dependencies and
102-
# generate the SBOM using CyclonDX SBOM generator.
116+
# generate the SBOM using CyclonDX SBOM generator for the release Python version and
117+
# supported release OS targets.
103118
- name: Generate requirements.txt and SBOM
104-
if: matrix.python == env.ARTIFACT_PYTHON
119+
if: >
120+
matrix.python == env.RELEASE_PYTHON_VERSION &&
121+
(matrix.os == env.RELEASE_OS_X86_64 || matrix.os == env.RELEASE_OS_ARM64)
105122
run: make requirements sbom
106123

107124
# Remove the old requirements.txt file (which includes _all_ packages) and generate a
108-
# new one for the package and its actual and required dependencies only.
125+
# new one for the package and its actual and required dependencies only. Run this step
126+
# for the release Python version and supported release OS targets only.
109127
- name: Prune packages and generate required requirements.txt
110-
if: matrix.python == env.ARTIFACT_PYTHON
128+
if: >
129+
matrix.python == env.RELEASE_PYTHON_VERSION &&
130+
(matrix.os == env.RELEASE_OS_X86_64 || matrix.os == env.RELEASE_OS_ARM64)
111131
run: |
112132
rm requirements.txt
113133
make prune requirements
114134
115135
# Find the paths to the artifact files that will be included in the release, compute
116136
# the SHA digest for all the release files and encode them using Base64, and export it
117-
# from this job.
137+
# from this job. Run this step for the release Python version and supported release
138+
# OS targets only.
118139
- name: Compute package hash
119-
if: matrix.python == env.ARTIFACT_PYTHON
140+
if: >
141+
matrix.python == env.RELEASE_PYTHON_VERSION &&
142+
(matrix.os == env.RELEASE_OS_X86_64 || matrix.os == env.RELEASE_OS_ARM64)
120143
id: compute-hash
121144
shell: bash
122145
run: |
@@ -131,15 +154,28 @@ jobs:
131154
sha256sum --version
132155
DIGEST=$(sha256sum "$TARBALL_PATH" "$WHEEL_PATH" "$REQUIREMENTS_PATH" "$SBOM_PATH" "$HTML_DOCS_PATH" "$MARKDOWN_DOCS_PATH" "$BUILD_EPOCH_PATH" | base64 -w0)
133156
echo "Digest of artifacts is $DIGEST."
134-
echo "artifacts-sha256=$DIGEST" >> "$GITHUB_OUTPUT"
157+
echo "$DIGEST" > artifacts-sha256-file-${{ steps.set-arch-env.outputs.arch_env }}
135158
136-
# For now only generate artifacts for the specified OS and Python version in env variables.
137159
# Currently reusable workflows do not support setting strategy property from the caller workflow.
160+
# Run this step for the release Python version and supported release OS targets only.
138161
- name: Upload the package artifact for debugging and release
139-
if: matrix.python == env.ARTIFACT_PYTHON
162+
if: >
163+
matrix.python == env.RELEASE_PYTHON_VERSION &&
164+
(matrix.os == env.RELEASE_OS_X86_64 || matrix.os == env.RELEASE_OS_ARM64)
140165
uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0
141166
with:
142-
name: artifact-${{ matrix.os }}-python-${{ matrix.python }}
143-
path: dist
167+
name: artifacts-${{ steps.set-arch-env.outputs.arch_env }}
168+
path: ./dist*/
144169
if-no-files-found: error
145170
retention-days: 7
171+
172+
# Run this step for the release Python version and supported release OS targets only.
173+
- name: Upload artifacts-sha256
174+
if: >
175+
matrix.python == env.RELEASE_PYTHON_VERSION &&
176+
(matrix.os == env.RELEASE_OS_X86_64 || matrix.os == env.RELEASE_OS_ARM64)
177+
uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0
178+
with:
179+
name: artifacts-sha256-file-${{ steps.set-arch-env.outputs.arch_env }}
180+
path: artifacts-sha256-file-${{ steps.set-arch-env.outputs.arch_env }}
181+
retention-days: 7

.github/workflows/pr-change-set.yaml

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,30 @@ jobs:
3838
- name: Download artifact
3939
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
4040
with:
41-
path: dist
42-
merge-multiple: true
41+
path: downloads
4342

4443
# Verify hashes by first computing hashes for the artifacts and then comparing them
4544
# against the hashes computed by the build job.
4645
- name: Verify the artifact hash
47-
env:
48-
ARTIFACT_HASH: ${{ needs.build.outputs.artifacts-sha256 }}
4946
run: |
5047
set -euo pipefail
51-
echo "Hash of package should be $ARTIFACT_HASH."
52-
echo "Decoding the artifact hash:"
53-
ls dist
54-
echo "$ARTIFACT_HASH" | base64 --decode
55-
echo "$ARTIFACT_HASH" | base64 --decode | sha256sum --strict --check --status || exit 1
48+
cd downloads
49+
for ARCH in "ubuntu-x86-64" "ubuntu-arm64"; do
50+
HASH_DIR="artifacts-sha256-file-${ARCH}"
51+
ARTIFACT_DIR="artifacts-${ARCH}"
52+
HASH_FILE="${HASH_DIR}/artifacts-sha256-file-${ARCH}"
53+
54+
echo "Verifying artifacts for ${ARCH}"
55+
echo "Decoding expected SHA256 digest:"
56+
DECODED_HASH=$(base64 --decode "${HASH_FILE}")
57+
echo "$DECODED_HASH"
58+
59+
cd "${ARTIFACT_DIR}"
60+
echo "$DECODED_HASH" | sha256sum --strict --check --status || {
61+
echo "Hash verification failed for ${ARCH}!"
62+
exit 1
63+
}
64+
cd - > /dev/null
65+
66+
echo "Hash verified successfully for ${ARCH}"
67+
done

0 commit comments

Comments
 (0)