Skip to content

Commit

Permalink
ci: assign version using release-please (#654)
Browse files Browse the repository at this point in the history
This PR changes version number output to the following:

### Release
```
$ hcloud version
hcloud 1.23.4
```

### goreleaser --snapshot
```
$ hcloud version
hcloud 1.23.4-dev+<short commit id>
```

### go build/go install
```
$ hcloud version
hcloud 1.23.4-dev
```

Closes #636

---------

Co-authored-by: jo <ljonas@riseup.net>
  • Loading branch information
phm07 and jooola authored Dec 22, 2023
1 parent 468ef81 commit af9dec4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .github/release-please-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"packages": {
".": {
"release-type": "go",
"package-name": "hcloud-cli"
"package-name": "hcloud-cli",
"extra-files": ["internal/version/version.go"]
}
}
}
11 changes: 9 additions & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ builds:
main: ./cmd/hcloud/main.go
binary: hcloud
ldflags:
- -w -X github.com/hetznercloud/cli/internal/version.Version={{.Version}}
- -w
- -X {{ .ModulePath }}/internal/version.version={{ .Version }}
- -X {{ .ModulePath }}/internal/version.versionPrerelease={{- if .IsSnapshot -}}dev+{{ .ShortCommit }}{{- end -}}
env:
- CGO_ENABLED=0
goos:
Expand All @@ -27,7 +29,9 @@ builds:
main: ./cmd/hcloud/main.go
binary: hcloud
ldflags:
- -w -X github.com/hetznercloud/cli/internal/version.Version={{.Version}}
- -w
- -X {{ .ModulePath }}/internal/version.version={{ .Version }}
- -X {{ .ModulePath }}/internal/version.versionPrerelease={{- if .IsSnapshot -}}dev+{{ .ShortCommit }}{{- end -}}
env:
- CGO_ENABLED=0
goos:
Expand All @@ -40,6 +44,9 @@ builds:
- cmd: bash script/gon.sh "{{ .Path }}"
output: true

snapshot:
name_template: "{{ .Version }}-dev+{{ .ShortCommit }}"

checksum:
name_template: checksums.txt
algorithm: sha256
Expand Down
19 changes: 17 additions & 2 deletions internal/version/version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
package version

// Version is set via compiler flags (see goreleaser config)
var Version = "unknown"
var (
// version is a semver version (https://semver.org).
version = "1.41.1" // x-release-please-version

// versionPrerelease is a semver version pre-release identifier (https://semver.org).
//
// For final releases, we set this to an empty string.
versionPrerelease = "dev"

// Version of the hcloud CLI.
Version = func() string {
if versionPrerelease != "" {
return version + "-" + versionPrerelease
}
return version
}()
)

0 comments on commit af9dec4

Please sign in to comment.