Skip to content

Commit ba1ae61

Browse files
authored
Hermetic Builds 🔒 (#40)
* more hermetic builds * match go versions * run `script/update` * Fix shebang formatting in env script * Refactor build environment variables and ldflags in .goreleaser.yaml * goreleaser updates * fix build * add check * Update build scripts to use single target mode and pass arguments to goreleaser
1 parent e2ef6bf commit ba1ae61

File tree

120 files changed

+2955
-791
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+2955
-791
lines changed

.github/workflows/build.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,14 @@ jobs:
2323
go-version-file: 'go.mod'
2424
cache: true
2525

26+
- name: goreleaser
27+
uses: goreleaser/goreleaser-action@9c156ee8a17a598857849441385a2041ef570552 # pin@v6
28+
with:
29+
install-only: true
30+
31+
- name: bootstrap
32+
run: script/bootstrap
33+
34+
# run a build in single target mode to save ci time
2635
- name: build
27-
run: go build -v ./cmd/gh-combine
36+
run: script/build --single-target

.github/workflows/golangci-lint.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,8 @@ jobs:
2323
go-version-file: 'go.mod'
2424
cache: true
2525

26+
- name: bootstrap
27+
run: script/bootstrap
28+
2629
- name: run golangci-lint
2730
uses: golangci/golangci-lint-action@v8

.github/workflows/lint.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ jobs:
2323
go-version-file: 'go.mod'
2424
cache: true
2525

26+
- name: bootstrap
27+
run: script/bootstrap
28+
2629
# Taken from https://github.com/cli/cli/blob/trunk/.github/workflows/lint.yml
2730
- name: lint
2831
run: |

.github/workflows/release.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ jobs:
2929
go-version-file: "go.mod"
3030
cache: false
3131

32+
- name: bootstrap
33+
run: script/bootstrap
34+
3235
- name: goreleaser
3336
uses: goreleaser/goreleaser-action@9c156ee8a17a598857849441385a2041ef570552 # pin@v6
3437
with:

.github/workflows/test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,8 @@ jobs:
2323
go-version-file: 'go.mod'
2424
cache: true
2525

26+
- name: bootstrap
27+
run: script/bootstrap
28+
2629
- name: test
2730
run: script/test

.goreleaser.yaml

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,56 @@
33

44
version: 2
55

6-
before:
7-
hooks:
8-
- go mod tidy
9-
106
builds:
11-
- main: ./cmd/gh-combine
7+
- main: ./cmd/gh-combine # Default: `.`.
8+
dir: "."
9+
binary: gh-combine # Default: Project directory name.
1210
env:
1311
- CGO_ENABLED=0
12+
- GOPROXY=off
13+
- GOSUMDB=off
14+
- SOURCE_DATE_EPOCH={{ .CommitTimestamp }}
15+
flags:
16+
- -trimpath
17+
- -mod=vendor
18+
- -v
1419
goos:
1520
- linux
1621
- darwin
22+
- windows
23+
- freebsd
1724
ldflags:
18-
- -s -w -X github.com/github/gh-combine/internal/version.tag={{.Tag}}
25+
- -s -w -X github.com/github/gh-combine/internal/version.tag={{.Tag}} -X github.com/github/gh-combine/internal/version.commit={{.FullCommit}} -X github.com/github/gh-combine/internal/version.buildTime={{.CommitDate}}
1926

2027
archives:
21-
- name_template: "{{ .Os }}-{{ .Arch }}"
22-
format: binary
23-
28+
- formats:
29+
- binary
30+
meta: true
31+
# Archive name.
32+
#
33+
# Default:
34+
# - if format is `binary`:
35+
# - `{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ with .Arm }}v{{ . }}{{ end }}{{ with .Mips }}_{{ . }}{{ end }}{{ if not (eq .Amd64 "v1") }}{{ .Amd64 }}{{ end }}`
36+
# - if format is anything else:
37+
# - `{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ with .Arm }}v{{ . }}{{ end }}{{ with .Mips }}_{{ . }}{{ end }}{{ if not (eq .Amd64 "v1") }}{{ .Amd64 }}{{ end }}`
38+
# Templates: allowed.
39+
name_template: '{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ with .Arm }}v{{ . }}{{ end }}{{ with .Mips }}_{{ . }}{{ end }}{{ if not (eq .Amd64 "v1") }}{{ .Amd64 }}{{ end }}'
40+
41+
# snapshots are used for testing and development purposes
42+
# build snapshots with `goreleaser build --snapshot --clean`
2443
snapshot:
25-
name_template: "{{ .Tag }}-next"
44+
version_template: "{{ .Version }}-dev-{{.ShortCommit}}"
45+
46+
checksum:
47+
name_template: "checksums.txt"
2648

2749
changelog:
2850
use: github-native
2951

52+
report_sizes: true
53+
3054
release:
3155
draft: false
56+
include_meta: true
3257

3358
dist: "./dist"

go.mod

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,34 @@
11
module github.com/github/gh-combine
22

3-
go 1.23.0
4-
5-
toolchain go1.23.8
3+
go 1.23.8
64

75
require github.com/briandowns/spinner v1.23.2
86

97
require (
10-
github.com/cli/go-gh/v2 v2.12.1
8+
github.com/cli/go-gh/v2 v2.12.2
119
github.com/cli/shurcooL-graphql v0.0.4
1210
github.com/spf13/cobra v1.9.1
1311
github.com/stretchr/testify v1.10.0
1412
)
1513

1614
require (
1715
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
18-
github.com/cli/safeexec v1.0.0 // indirect
16+
github.com/cli/safeexec v1.0.1 // indirect
1917
github.com/davecgh/go-spew v1.1.1 // indirect
20-
github.com/fatih/color v1.7.0 // indirect
21-
github.com/henvic/httpretty v0.0.6 // indirect
18+
github.com/fatih/color v1.18.0 // indirect
19+
github.com/henvic/httpretty v0.1.4 // indirect
2220
github.com/inconshreveable/mousetrap v1.1.0 // indirect
2321
github.com/kr/pretty v0.1.0 // indirect
2422
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
25-
github.com/mattn/go-colorable v0.1.13 // indirect
23+
github.com/mattn/go-colorable v0.1.14 // indirect
2624
github.com/mattn/go-isatty v0.0.20 // indirect
2725
github.com/muesli/termenv v0.16.0 // indirect
2826
github.com/pmezard/go-difflib v1.0.0 // indirect
2927
github.com/rivo/uniseg v0.4.7 // indirect
30-
github.com/spf13/pflag v1.0.6 // indirect
31-
github.com/thlib/go-timezone-local v0.0.0-20210907160436-ef149e42d28e // indirect
32-
golang.org/x/sys v0.31.0 // indirect
33-
golang.org/x/term v0.30.0 // indirect
34-
golang.org/x/text v0.23.0 // indirect
28+
github.com/spf13/pflag v1.0.7 // indirect
29+
github.com/thlib/go-timezone-local v0.0.7 // indirect
30+
golang.org/x/sys v0.35.0 // indirect
31+
golang.org/x/term v0.34.0 // indirect
32+
golang.org/x/text v0.28.0 // indirect
3533
gopkg.in/yaml.v3 v3.0.1 // indirect
3634
)

go.sum

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@ github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiE
22
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
33
github.com/briandowns/spinner v1.23.2 h1:Zc6ecUnI+YzLmJniCfDNaMbW0Wid1d5+qcTq4L2FW8w=
44
github.com/briandowns/spinner v1.23.2/go.mod h1:LaZeM4wm2Ywy6vO571mvhQNRcWfRUnXOs0RcKV0wYKM=
5-
github.com/cli/go-gh/v2 v2.12.1 h1:SVt1/afj5FRAythyMV3WJKaUfDNsxXTIe7arZbwTWKA=
6-
github.com/cli/go-gh/v2 v2.12.1/go.mod h1:+5aXmEOJsH9fc9mBHfincDwnS02j2AIA/DsTH0Bk5uw=
7-
github.com/cli/safeexec v1.0.0 h1:0VngyaIyqACHdcMNWfo6+KdUYnqEr2Sg+bSP1pdF+dI=
8-
github.com/cli/safeexec v1.0.0/go.mod h1:Z/D4tTN8Vs5gXYHDCbaM1S/anmEDnJb1iW0+EJ5zx3Q=
5+
github.com/cli/go-gh/v2 v2.12.2 h1:EtocmDAH7dKrH2PscQOQVo7PbFD5G6uYx4rSKY2w1SY=
6+
github.com/cli/go-gh/v2 v2.12.2/go.mod h1:g2IjwHEo27fgItlS9wUbRaXPYurZEXPp1jrxf3piC6g=
7+
github.com/cli/safeexec v1.0.1 h1:e/C79PbXF4yYTN/wauC4tviMxEV13BwljGj0N9j+N00=
8+
github.com/cli/safeexec v1.0.1/go.mod h1:Z/D4tTN8Vs5gXYHDCbaM1S/anmEDnJb1iW0+EJ5zx3Q=
99
github.com/cli/shurcooL-graphql v0.0.4 h1:6MogPnQJLjKkaXPyGqPRXOI2qCsQdqNfUY1QSJu2GuY=
1010
github.com/cli/shurcooL-graphql v0.0.4/go.mod h1:3waN4u02FiZivIV+p1y4d0Jo1jc6BViMA73C+sZo2fk=
1111
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
1212
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
1313
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
14-
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
15-
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
14+
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
15+
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
1616
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw=
1717
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI=
18-
github.com/henvic/httpretty v0.0.6 h1:JdzGzKZBajBfnvlMALXXMVQWxWMF/ofTy8C3/OSUTxs=
19-
github.com/henvic/httpretty v0.0.6/go.mod h1:X38wLjWXHkXT7r2+uK8LjCMne9rsuNaBLJ+5cU2/Pmo=
18+
github.com/henvic/httpretty v0.1.4 h1:Jo7uwIRWVFxkqOnErcoYfH90o3ddQyVrSANeS4cxYmU=
19+
github.com/henvic/httpretty v0.1.4/go.mod h1:Dn60sQTZfbt2dYsdUSNsCljyF4AfdqnuJFDLJA1I4AM=
2020
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
2121
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
2222
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
@@ -26,9 +26,8 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
2626
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
2727
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
2828
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
29-
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
30-
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
31-
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
29+
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
30+
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
3231
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
3332
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
3433
github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=
@@ -40,21 +39,23 @@ github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUc
4039
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
4140
github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=
4241
github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
43-
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
4442
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
43+
github.com/spf13/pflag v1.0.7 h1:vN6T9TfwStFPFM5XzjsvmzZkLuaLX+HS+0SeFLRgU6M=
44+
github.com/spf13/pflag v1.0.7/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
4545
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
4646
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
47-
github.com/thlib/go-timezone-local v0.0.0-20210907160436-ef149e42d28e h1:BuzhfgfWQbX0dWzYzT1zsORLnHRv3bcRcsaUk0VmXA8=
48-
github.com/thlib/go-timezone-local v0.0.0-20210907160436-ef149e42d28e/go.mod h1:/Tnicc6m/lsJE0irFMA0LfIwTBo4QP7A8IfyIv4zZKI=
47+
github.com/thlib/go-timezone-local v0.0.7 h1:fX8zd3aJydqLlTs/TrROrIIdztzsdFV23OzOQx31jII=
48+
github.com/thlib/go-timezone-local v0.0.7/go.mod h1:/Tnicc6m/lsJE0irFMA0LfIwTBo4QP7A8IfyIv4zZKI=
4949
golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
50-
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
5150
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
52-
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
53-
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
54-
golang.org/x/term v0.30.0 h1:PQ39fJZ+mfadBm0y5WlL4vlM7Sx1Hgf13sMIY2+QS9Y=
55-
golang.org/x/term v0.30.0/go.mod h1:NYYFdzHoI5wRh/h5tDMdMqCqPJZEuNqVR5xJLd/n67g=
56-
golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
57-
golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
51+
golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
52+
golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
53+
golang.org/x/term v0.34.0 h1:O/2T7POpk0ZZ7MAzMeWFSg6S5IpWd/RXDlM9hgM3DR4=
54+
golang.org/x/term v0.34.0/go.mod h1:5jC53AEywhIVebHgPVeg0mj8OD3VO9OzclacVrqpaAw=
55+
golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
56+
golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
57+
golang.org/x/tools v0.35.0 h1:mBffYraMEf7aa0sB+NuKnuCy8qI/9Bughn8dC2Gu5r0=
58+
golang.org/x/tools v0.35.0/go.mod h1:NKdj5HkL/73byiZSJjqJgKn3ep7KjFkBOkR/Hps3VPw=
5859
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
5960
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
6061
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

internal/version/version.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import (
66
)
77

88
var (
9-
tag = "dev" // set via ldflags
10-
commit = "123abc"
11-
date = "now"
9+
tag = "dev" // set via ldflags
10+
commit = "123abc"
11+
buildTime = "now"
1212
)
1313

1414
const template = "%s (%s) built at %s\nhttps://github.com/github/gh-combine/releases/tag/%s"
@@ -22,18 +22,22 @@ func defaultBuildInfoReader() (*debug.BuildInfo, bool) {
2222
}
2323

2424
func String() string {
25-
info, ok := buildInfoReader()
25+
// Start with ldflags values
26+
currentCommit := commit
27+
currentDate := buildTime
2628

29+
// Override with VCS info if available and ldflags weren't set
30+
info, ok := buildInfoReader()
2731
if ok {
2832
for _, setting := range info.Settings {
29-
if setting.Key == "vcs.revision" {
30-
commit = setting.Value
33+
if setting.Key == "vcs.revision" && commit == "123abc" {
34+
currentCommit = setting.Value
3135
}
32-
if setting.Key == "vcs.time" {
33-
date = setting.Value
36+
if setting.Key == "vcs.time" && buildTime == "now" {
37+
currentDate = setting.Value
3438
}
3539
}
3640
}
3741

38-
return fmt.Sprintf(template, tag, commit, date, tag)
42+
return fmt.Sprintf(template, tag, currentCommit, currentDate, tag)
3943
}

internal/version/version_test.go

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ func TestString(t *testing.T) {
99
// Save original values
1010
origTag := tag
1111
origCommit := commit
12-
origDate := date
12+
origBuildTime := buildTime
1313
origBuildInfoReader := buildInfoReader
1414

1515
// Restore original values after the test
1616
defer func() {
1717
tag = origTag
1818
commit = origCommit
19-
date = origDate
19+
buildTime = origBuildTime
2020
buildInfoReader = origBuildInfoReader
2121
}()
2222

@@ -25,7 +25,7 @@ func TestString(t *testing.T) {
2525
// Set known values for testing
2626
tag = "v1.0.0"
2727
commit = "abc123"
28-
date = "2025-04-15"
28+
buildTime = "2025-04-15"
2929

3030
// Mock the buildInfoReader to return false so that preset values are used
3131
buildInfoReader = func() (*debug.BuildInfo, bool) {
@@ -43,10 +43,10 @@ func TestString(t *testing.T) {
4343

4444
// Test 2: With mock build info that updates commit and date
4545
t.Run("with mock build info", func(t *testing.T) {
46-
// Set initial values
46+
// Set sentinel values so VCS info will override
4747
tag = "dev"
48-
commit = "initial-commit"
49-
date = "initial-date"
48+
commit = "123abc"
49+
buildTime = "now"
5050

5151
// Create mock build info with specific values
5252
mockSettings := []debug.BuildSetting{
@@ -75,7 +75,7 @@ func TestString(t *testing.T) {
7575
// Set initial values
7676
tag = "dev"
7777
commit = "unchanged-commit"
78-
date = "unchanged-date"
78+
buildTime = "unchanged-date"
7979

8080
// Empty build settings
8181
buildInfoReader = func() (*debug.BuildInfo, bool) {
@@ -92,4 +92,32 @@ func TestString(t *testing.T) {
9292
t.Errorf("Expected version string to be:\n%q\nbut got:\n%q", expected, result)
9393
}
9494
})
95+
96+
// Test 4: ldflags values should take precedence over VCS info
97+
t.Run("ldflags precedence over vcs", func(t *testing.T) {
98+
// Set non-sentinel values (simulating ldflags)
99+
tag = "v2.0.0"
100+
commit = "ldflags-commit"
101+
buildTime = "ldflags-time"
102+
103+
// VCS info that should be ignored
104+
mockSettings := []debug.BuildSetting{
105+
{Key: "vcs.revision", Value: "vcs-commit-hash"},
106+
{Key: "vcs.time", Value: "vcs-build-time"},
107+
}
108+
109+
buildInfoReader = func() (*debug.BuildInfo, bool) {
110+
return &debug.BuildInfo{
111+
Settings: mockSettings,
112+
}, true
113+
}
114+
115+
result := String()
116+
117+
// ldflags values should be used, not VCS
118+
expected := "v2.0.0 (ldflags-commit) built at ldflags-time\nhttps://github.com/github/gh-combine/releases/tag/v2.0.0"
119+
if result != expected {
120+
t.Errorf("Expected version string to be:\n%q\nbut got:\n%q", expected, result)
121+
}
122+
})
95123
}

0 commit comments

Comments
 (0)