Skip to content

Commit

Permalink
ci: assign version string using release-please and GoReleaser
Browse files Browse the repository at this point in the history
  • Loading branch information
phm07 committed Dec 22, 2023
1 parent 468ef81 commit 21e75d0
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ jobs:
token: ${{ secrets.HCLOUD_BOT_TOKEN }}
config-file: .github/release-please-config.json
manifest-file: .github/release-please-manifest.json

extra-files: |
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 }}"

checksum:
name_template: checksums.txt
algorithm: sha256
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ func NewCommand(cli *state.State) *cobra.Command {
}

func runVersion(cli *state.State, cmd *cobra.Command, args []string) error {
cmd.Printf("hcloud %s\n", version.Version)
cmd.Printf("hcloud %s\n", version.FullVersion)
return nil
}
23 changes: 21 additions & 2 deletions internal/version/version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
package version

// Version is set via compiler flags (see goreleaser config)
var Version = "unknown"
var (
// Version is the main version number that is being run at the moment.
Version = "1.41.1" // x-release-please-version

// Tag is A pre-release marker for the Version. If this is ""
// (empty string) then it means that it is a final release. Otherwise, this
// is a pre-release such as "dev" (in development), "beta", "rc1", etc.
//
// For releases, GoReleaser will automatically set this to an empty string.
Tag = "dev"

// FullVersion is the full version string, including the prerelease tag.
// This is dynamically generated based on the Version and Tag variables.
FullVersion = func() string {
s := Version
if Tag != "" {
s += "-" + Tag
}
return s
}()
)

0 comments on commit 21e75d0

Please sign in to comment.