Skip to content

Commit b99f725

Browse files
committed
set release version via ldflags
1 parent 0869244 commit b99f725

3 files changed

Lines changed: 10 additions & 4 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ jobs:
1515
runs-on: ubuntu-latest
1616
steps:
1717
- uses: actions/checkout@v6
18+
- id: version
19+
run: echo "version=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"
1820
- uses: cli/gh-extension-precompile@v2
1921
with:
2022
generate_attestations: true
2123
go_version_file: go.mod
24+
go_build_options: >-
25+
-ldflags '-X github.com/github/gh-stack/cmd.Version=${{ steps.version.outputs.version }}'

‎cmd/root.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ func RootCmd() *cobra.Command {
2121
SilenceErrors: true,
2222
}
2323

24+
root.SetVersionTemplate("gh stack version {{.Version}}\n")
25+
2426
root.SetOut(cfg.Out)
2527
root.SetErr(cfg.Err)
2628

‎cmd/version.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package cmd
22

33
// Version is the current version of gh-stack.
4-
// It can be overridden at build time via:
5-
//
6-
// go build -ldflags="-X github.com/github/gh-stack/cmd.Version=1.2.3"
7-
var Version = "0.0.1"
4+
// In release builds, this is overridden at build time via ldflags
5+
// (see .github/workflows/release.yml).
6+
// The "dev" default indicates a local development build.
7+
var Version = "dev"

0 commit comments

Comments
 (0)