Skip to content

Commit 5d8e4db

Browse files
authored
Merge pull request monero-project#2653 from plowsof/deterministic-ci
ci: confirm dist archive is reproducible [beta]
2 parents bf5f826 + f18055f commit 5d8e4db

1 file changed

Lines changed: 75 additions & 16 deletions

File tree

.github/workflows/ci.yml

Lines changed: 75 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@ on:
55
branches: [beta]
66
pull_request:
77
branches: [beta]
8+
release:
9+
types: [published]
810

911
permissions:
1012
contents: read
1113

1214
jobs:
1315
lint:
1416
name: Lint & Format
17+
if: github.event_name != 'release' || github.event.release.target_commitish == 'beta'
1518
runs-on: ubuntu-22.04
1619

1720
steps:
@@ -26,7 +29,7 @@ jobs:
2629
echo "All set:html usages are safe"
2730
2831
- name: Setup pnpm
29-
uses: pnpm/action-setup@v4
32+
uses: pnpm/action-setup@v5
3033

3134
- name: Setup Node.js
3235
uses: actions/setup-node@v6
@@ -49,15 +52,22 @@ jobs:
4952
- name: Type check
5053
run: pnpm check
5154

52-
build:
53-
name: Build & Validate
55+
reproducible-archive:
56+
name: Reproducible Archive (Run ${{ matrix.run }})
57+
if: github.event_name != 'release' || github.event.release.target_commitish == 'beta'
5458
runs-on: ubuntu-22.04
59+
strategy:
60+
matrix:
61+
run: [1, 2]
62+
outputs:
63+
hash-1: ${{ steps.hash.outputs.hash-1 }}
64+
hash-2: ${{ steps.hash.outputs.hash-2 }}
5565

5666
steps:
5767
- uses: actions/checkout@v6
5868

5969
- name: Setup pnpm
60-
uses: pnpm/action-setup@v4
70+
uses: pnpm/action-setup@v5
6171

6272
- name: Setup Node.js
6373
uses: actions/setup-node@v6
@@ -68,20 +78,69 @@ jobs:
6878
- name: Install dependencies
6979
run: pnpm install --frozen-lockfile
7080

71-
- name: Prepare source for CI build
81+
- name: Prepare source for CI/Release build
7282
env:
73-
BASE_BRANCH: ${{ github.event.pull_request.base.ref }} # PR target branch
83+
BASE_BRANCH: ${{ github.event_name != 'release' && github.event.pull_request.base.ref || '' }} # PR target branch
7484
BASE_REF: ${{ github.event_name == 'push' && github.event.before || '' }} # previous commit before the push event
85+
LIMIT_POSTS: ${{ github.event_name != 'release' && '10' || '' }}
86+
SKIP_IMAGE_OPTIMIZATION: ${{ github.event_name != 'release' && 'true' || '' }}
87+
SKIP_OG: ${{ github.event_name != 'release' && 'true' || '' }}
88+
LIMIT_LOCALES: ${{ github.event_name != 'release' && 'true' || '' }}
89+
run: pnpm prepare-build && pnpm build
90+
91+
- name: Create archive
92+
run: |
93+
tar \
94+
--sort=name \
95+
--mtime='@0' \
96+
--owner=0 \
97+
--group=0 \
98+
--numeric-owner \
99+
--mode='u=rwX,go=rX' \
100+
-czf dist.tar.gz dist/
101+
102+
- name: Hash archive
103+
id: hash
75104
run: |
76-
ARGS="--limit-posts 10 --skip-og --limit-locales"
77-
if [ -n "$BASE_BRANCH" ]; then ARGS="$ARGS --base-branch $BASE_BRANCH"; fi
78-
if [ -n "$BASE_REF" ]; then ARGS="$ARGS --base-ref $BASE_REF"; fi
79-
pnpm prepare-build $ARGS
105+
HASH=$(sha256sum dist.tar.gz | awk '{print $1}')
106+
echo "hash-${{ matrix.run }}=$HASH" >> $GITHUB_OUTPUT
80107
81-
- name: Build site
82-
env:
83-
SKIP_IMAGE_OPTIMIZATION: "true"
84-
run: pnpm build
108+
- name: Upload archive
109+
if: github.event_name == 'release' && matrix.run == 1
110+
uses: actions/upload-artifact@v7
111+
with:
112+
name: deploy-dist-archive
113+
path: dist.tar.gz
85114

86-
- name: Validate built HTML
87-
run: pnpm exec htmlhint 'dist/**/*.html'
115+
compare-archives:
116+
name: Compare hashes
117+
if: github.event_name != 'release' || github.event.release.target_commitish == 'beta'
118+
runs-on: ubuntu-22.04
119+
needs: reproducible-archive
120+
121+
permissions:
122+
contents: write
123+
124+
steps:
125+
- name: Compare
126+
run: |
127+
HASH1="${{ needs.reproducible-archive.outputs.hash-1 }}"
128+
HASH2="${{ needs.reproducible-archive.outputs.hash-2 }}"
129+
if [ "$HASH1" = "$HASH2" ]; then
130+
echo "hashes match."
131+
else
132+
echo "hash mismatch."
133+
exit 1
134+
fi
135+
136+
- name: Download release archive
137+
if: github.event_name == 'release'
138+
uses: actions/download-artifact@v8
139+
with:
140+
name: deploy-dist-archive
141+
142+
- name: Upload release asset
143+
if: github.event_name == 'release'
144+
uses: softprops/action-gh-release@v3
145+
with:
146+
files: dist.tar.gz

0 commit comments

Comments
 (0)