Skip to content

Commit 90ee938

Browse files
committed
Use git tag version for amesh --version output
- Add runtime/debug to get module version from go install - Inject version via -ldflags in release workflow - Fallback priority: ldflags > ReadBuildInfo > "dev"
1 parent 16e358f commit 90ee938

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
- name: Get dependencies
2727
run: go get -v -t -d ./...
2828
- name: Build
29-
run: go build -v -o amesh .
29+
run: go build -v -ldflags "-X main.version=${{ env.RELEASE_TAG }}" -o amesh .
3030
- name: Zip
3131
id: zip-file
3232
run: |

main.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,24 @@ import (
77
_ "image/gif"
88
_ "image/jpeg"
99
"os"
10+
"runtime/debug"
1011

1112
"github.com/otiai10/amesh/cli"
1213
"github.com/otiai10/amesh/lib/tenki"
1314
"github.com/otiai10/gat/render"
1415
)
1516

16-
const version = "v1.4.0"
17+
var version = ""
18+
19+
func getVersion() string {
20+
if version != "" {
21+
return version // -ldflags で設定された場合
22+
}
23+
if info, ok := debug.ReadBuildInfo(); ok && info.Main.Version != "" {
24+
return info.Main.Version // go install で取得できる場合
25+
}
26+
return "dev"
27+
}
1728

1829
var (
1930
geo, mask bool
@@ -37,7 +48,7 @@ func setup() {
3748
flag.BoolVar(&usepix, "p", false, "iTermであってもピクセル画で表示")
3849
flag.Float64Var(&scale, "s", 1.2, "表示拡大倍率")
3950
flag.Usage = func() {
40-
fmt.Fprintf(os.Stderr, "東京アメッシュをCLIに表示するコマンドです。(%v)\n利用可能なオプション:\n", version)
51+
fmt.Fprintf(os.Stderr, "東京アメッシュをCLIに表示するコマンドです。(%s)\n利用可能なオプション:\n", getVersion())
4152
flag.PrintDefaults()
4253
}
4354
flag.Parse()

0 commit comments

Comments
 (0)