Skip to content

Commit 2b0f0c0

Browse files
authored
Fix/verify version prefix (#10)
* fix: handle version strings without v prefix in --verify GoReleaser's {{ .Version }} strips the v prefix (e.g. "1.3.0" not "v1.3.0"), causing checksumURL to generate an invalid GitHub release URL. Normalize both the tag (always add v) and the dev build check to handle either format. * fix: use git-cliff --latest for release notes instead of full changelog
1 parent e2960a7 commit 2b0f0c0

4 files changed

Lines changed: 38 additions & 12 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ jobs:
4646
install-only: true
4747

4848
- name: Generate changelog
49-
run: make changelog VERSION=${{ github.event.inputs.version }}
49+
run: |
50+
# Full changelog for CHANGELOG.md (committed to repo)
51+
make changelog VERSION=${{ github.event.inputs.version }}
52+
# Release notes for this version only (passed to goreleaser)
53+
git-cliff --tag ${{ github.event.inputs.version }} --latest --strip header -o RELEASE_NOTES.md
5054
5155
- name: Commit, tag, and push release branch
5256
run: |
@@ -67,7 +71,7 @@ jobs:
6771
- name: Build and release with goreleaser
6872
uses: goreleaser/goreleaser-action@v6
6973
with:
70-
args: release --clean
74+
args: release --clean --release-notes RELEASE_NOTES.md
7175
env:
7276
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
7377

‎.goreleaser.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,6 @@ archives:
3131

3232
checksum:
3333
name_template: verda_{{ .Version }}_SHA256SUMS
34+
35+
changelog:
36+
disable: true

‎internal/verda-cli/cmd/version/verify.go‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ type VerifyResult struct {
2727
// checksumURL returns the GitHub release URL for the checksums file.
2828
func checksumURL(ver string) string {
2929
bare := strings.TrimPrefix(ver, "v")
30+
tag := "v" + bare // GitHub release tags always have v prefix
3031
return fmt.Sprintf(
3132
"https://github.com/verda-cloud/verda-cli/releases/download/%s/verda_%s_binary_SHA256SUMS",
32-
ver, bare,
33+
tag, bare,
3334
)
3435
}
3536

@@ -133,8 +134,9 @@ func verifyBinary(client *http.Client, binPath, url, goos, goarch string) (*Veri
133134
// runVerify is the top-level verify logic, writing output to out and warnings
134135
// to errOut. It uses the provided HTTP client for fetching checksums.
135136
func runVerify(out, errOut io.Writer, outputFormat string, client *http.Client, ver, goos, goarch string) error {
136-
if ver == "v0.0.0-dev" {
137-
_, _ = fmt.Fprintln(errOut, "Warning: cannot verify a development build (v0.0.0-dev)")
137+
bare := strings.TrimPrefix(ver, "v")
138+
if bare == "0.0.0-dev" || bare == "" {
139+
_, _ = fmt.Fprintf(errOut, "Warning: cannot verify a development build (%s)\n", ver)
138140
return errors.New("cannot verify development build")
139141
}
140142

‎internal/verda-cli/cmd/version/verify_test.go‎

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ func TestChecksumURL(t *testing.T) {
189189
version: "v0.5.0",
190190
want: "https://github.com/verda-cloud/verda-cli/releases/download/v0.5.0/verda_0.5.0_binary_SHA256SUMS",
191191
},
192+
{
193+
version: "1.3.0",
194+
want: "https://github.com/verda-cloud/verda-cli/releases/download/v1.3.0/verda_1.3.0_binary_SHA256SUMS",
195+
},
192196
}
193197

194198
for _, tt := range tests {
@@ -304,13 +308,26 @@ func TestVerifyBinaryMismatch(t *testing.T) {
304308
func TestRunVerifyDevBuild(t *testing.T) {
305309
t.Parallel()
306310

307-
var outBuf, errBuf bytes.Buffer
308-
309-
err := runVerify(&outBuf, &errBuf, "", nil, "v0.0.0-dev", "", "")
310-
if err == nil {
311-
t.Fatal("expected error for dev build")
311+
tests := []struct {
312+
name string
313+
version string
314+
}{
315+
{"with v prefix", "v0.0.0-dev"},
316+
{"without v prefix", "0.0.0-dev"},
317+
{"empty", ""},
312318
}
313-
if !strings.Contains(errBuf.String(), "development build") {
314-
t.Errorf("expected warning about development build, got: %q", errBuf.String())
319+
320+
for _, tt := range tests {
321+
t.Run(tt.name, func(t *testing.T) {
322+
t.Parallel()
323+
var outBuf, errBuf bytes.Buffer
324+
err := runVerify(&outBuf, &errBuf, "", nil, tt.version, "", "")
325+
if err == nil {
326+
t.Fatal("expected error for dev build")
327+
}
328+
if !strings.Contains(errBuf.String(), "development build") {
329+
t.Errorf("expected warning about development build, got: %q", errBuf.String())
330+
}
331+
})
315332
}
316333
}

0 commit comments

Comments
 (0)