Skip to content

Commit aed642f

Browse files
committed
ci: build releases with -trimpath and check reproducibility
1 parent bc55b4e commit aed642f

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
on:
2+
push:
3+
branches: [main]
4+
pull_request:
5+
branches: [main]
6+
7+
permissions: {}
8+
9+
jobs:
10+
reproducibility:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
steps:
15+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
16+
with:
17+
persist-credentials: false
18+
- uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
19+
with:
20+
go-version-file: go.mod
21+
cache: false
22+
- uses: goreleaser/goreleaser-action@f06c13b6b1a9625abc9e6e439d9c05a8f2190e94 # v7
23+
with:
24+
version: v2.15.2
25+
install-only: true
26+
- name: Build the release artifact with goreleaser
27+
run: goreleaser build --snapshot --clean --single-target -o /tmp/goreleaser-build
28+
29+
- name: Rebuild from source and compare digests
30+
run: |
31+
VERSION=$(jq -r .version dist/metadata.json)
32+
COMMIT=$(jq -r .commit dist/metadata.json | cut -c1-7)
33+
cp -a . /tmp/src-elsewhere
34+
cd /tmp/src-elsewhere
35+
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GOAMD64=v1 \
36+
go build -trimpath \
37+
-ldflags="-s -w -X main.Version=$VERSION -X main.Commit=$COMMIT" \
38+
-o /tmp/plain-build .
39+
sha256sum /tmp/goreleaser-build /tmp/plain-build
40+
cmp /tmp/goreleaser-build /tmp/plain-build \
41+
&& echo "Reproducible build confirmed"

.goreleaser.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ before:
77
builds:
88
- env:
99
- CGO_ENABLED=0
10+
flags:
11+
- -trimpath
1012
ldflags:
1113
- -s -w
1214
- -X main.Version={{.Version}}

0 commit comments

Comments
 (0)