Skip to content

Commit 96bb794

Browse files
committed
feat: add artifact integrity verification in workflows
1 parent 176c74a commit 96bb794

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

.github/workflows/reusable-build-package.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,11 @@ on:
6666
description: 'Export path where the package was generated'
6767
value: ${{ jobs.build-package.outputs.export-path }}
6868
artifact-url:
69-
description: 'URL to download an Artifact.'
69+
description: 'URL to download an Artifact'
7070
value: ${{ jobs.build-package.outputs.artifact-url }}
71+
artifact-digest:
72+
description: 'SHA-256 digest of an Artifact'
73+
value: ${{ jobs.build-package.outputs.artifact-digest }}
7174

7275
env:
7376
TARGET_PLATFORM: StandaloneLinux64
@@ -88,6 +91,7 @@ jobs:
8891
package-name: ${{ steps.path-normalizer.outputs.normalized-package-name }}
8992
export-path: ${{ steps.path-normalizer.outputs.export-path }}
9093
artifact-url: ${{ steps.upload-artifact.outputs.artifact-url }}
94+
artifact-digest: ${{ steps.upload-artifact.outputs.artifact-digest }}
9195
steps:
9296
- name: Normalize Path
9397
id: path-normalizer
@@ -155,4 +159,4 @@ jobs:
155159
with:
156160
name: ${{ steps.path-normalizer.outputs.normalized-package-name }}
157161
path: ${{ steps.path-normalizer.outputs.export-path }}
158-
retention-days: ${{ inputs.retention-days }}
162+
retention-days: ${{ inputs.retention-days }}

.github/workflows/reusable-release-package-upload.yaml

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ on:
1111
description: 'The name of the package uploaded as an artifact.'
1212
required: true
1313
type: string
14+
artifact-digest:
15+
description: 'SHA-256 digest of an Artifact. https://github.com/actions/upload-artifact?tab=readme-ov-file#outputs'
16+
required: true
17+
type: string
1418
dry-run:
1519
description: 'true = dry-run: The upload will not actually be performed.'
1620
required: false
@@ -30,13 +34,43 @@ jobs:
3034
name: ${{ inputs.artifact-package-name }}
3135
path: ./artifacts
3236

37+
- name: Define Path for Artifact File
38+
id: artifact-path
39+
run: |
40+
file="${{ inputs.artifact-package-name }}"
41+
echo "path=./artifacts/$file" >> "$GITHUB_OUTPUT"
42+
43+
- name: Verify Artifact Exists
44+
run: |
45+
artifact_file="${{ steps.artifact-path.outputs.path }}"
46+
if [ ! -f "$artifact_file" ]; then
47+
echo "::error file=$artifact_file::Artifact file not found!"
48+
exit 1
49+
fi
50+
echo "Artifact exists: $artifact_file"
51+
52+
- name: Verify Artifact Integrity
53+
run: |
54+
artifact_file="${{ steps.artifact-path.outputs.path }}"
55+
calculated_hash=$(sha256sum "$artifact_file" | awk '{ print $1 }')
56+
uploaded_hash="${{ inputs.artifact_digest }}"
57+
58+
echo "Uploaded hash: $uploaded_hash"
59+
echo "Calculated hash: $calculated_hash"
60+
61+
if [ "$calculated_hash" != "$uploaded_hash" ]; then
62+
echo "::error::Artifact integrity check failed! Hash mismatch."
63+
exit 1
64+
fi
65+
echo "Artifact Verified: Integrity check passed. Hash matches."
66+
3367
- name: Upload Package
3468
if: ${{ !inputs.dry-run }}
3569
env:
3670
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3771
run: |
3872
file="${{ inputs.artifact-package-name }}"
39-
file_path="./artifacts/$file"
73+
file_path="${{ steps.artifact-path.outputs.path }}"
4074
tag="${{ inputs.release-tag }}"
4175
gh release upload "$tag" "$file_path"
4276
echo "::notice title=Uploaded asset::$file"
@@ -45,6 +79,6 @@ jobs:
4579
if: ${{ inputs.dry-run }}
4680
run: |
4781
file="${{ inputs.artifact-package-name }}"
48-
file_path="./artifacts/$file"
82+
file_path="${{ steps.artifact-path.outputs.path }}"
4983
tag="${{ inputs.release-tag }}"
5084
echo "::notice title=Dry Run::Simulating upload of '$file_path' to release tag '$tag'."

0 commit comments

Comments
 (0)