From 289ff54c0cb4ab556836cedab20da380a95edd9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Fri, 20 Dec 2024 16:10:30 +0100 Subject: [PATCH] Add version info and use go-yaml patched version This branch: https://github.com/goccy/go-yaml/pull/602 For https://github.com/goccy/go-yaml/issues/601 --- go.mod | 2 +- go.sum | 4 ++-- hugoreleaser.env | 2 +- hugoreleaser.yaml | 2 +- internal/config/config_test.go | 2 -- main.go | 39 ++++++++++++++++++++++++++++++++++ 6 files changed, 44 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index afdea22..f55c6b4 100644 --- a/go.mod +++ b/go.mod @@ -29,7 +29,7 @@ require ( ) require ( - github.com/goccy/go-yaml v1.15.11 + github.com/goccy/go-yaml v1.15.13-0.20241221080047-87aec7d7f886 github.com/gohugoio/hugoreleaser-plugins-api v0.7.1-0.20241220094410-1f02562cf9b9 golang.org/x/sync v0.10.0 ) diff --git a/go.sum b/go.sum index 7d048d5..c89b6e6 100644 --- a/go.sum +++ b/go.sum @@ -18,8 +18,8 @@ github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHk github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y= github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8= -github.com/goccy/go-yaml v1.15.11 h1:XeEd/2INF0TXXWMzJ9ALqJLGjGDl4PIi1gmrK+7KpAs= -github.com/goccy/go-yaml v1.15.11/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA= +github.com/goccy/go-yaml v1.15.13-0.20241221080047-87aec7d7f886 h1:DGV2XraUpNBGuKdxYuNFmlm4feqfEFMm+48p2YUQnqw= +github.com/goccy/go-yaml v1.15.13-0.20241221080047-87aec7d7f886/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA= github.com/gohugoio/hugoreleaser-plugins-api v0.7.1-0.20241220094410-1f02562cf9b9 h1:JT6XVa3wBdkwrgcV4EYku7fZOfLX2MjWgWWtHtp5IQs= github.com/gohugoio/hugoreleaser-plugins-api v0.7.1-0.20241220094410-1f02562cf9b9/go.mod h1:Qheg3q6TF7pq9etJBNceTqGaM1VfkYDnm2k2KIIC/Ac= github.com/gohugoio/hugoreleaser/plugins v0.1.1-0.20220822083757-38d81884db04 h1:VNOiFvTuhXc2eoDvBVQHsfxl1TTS2/EF1wFs1YttIlA= diff --git a/hugoreleaser.env b/hugoreleaser.env index 5288ded..2ef8bfc 100644 --- a/hugoreleaser.env +++ b/hugoreleaser.env @@ -1,3 +1,3 @@ # Next release -HUGORELEASER_TAG=v0.59.0 +HUGORELEASER_TAG=v0.60.0 HUGORELEASER_COMMITISH=main diff --git a/hugoreleaser.yaml b/hugoreleaser.yaml index d9f6731..938bbcd 100644 --- a/hugoreleaser.yaml +++ b/hugoreleaser.yaml @@ -21,7 +21,7 @@ build_settings: - exe env: - CGO_ENABLED=0 - ldflags: "" + ldflags: "-s -w -X main.tag=${HUGORELEASER_TAG}" # This can be overridden for each archive. archive_settings: diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 50642ed..628291b 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -71,6 +71,4 @@ func TestDecodeFile(t *testing.T) { } } } - - fmt.Println("===> FI", cfg.ReleaseSettings.ReleaseNotesSettings.Filename) } diff --git a/main.go b/main.go index 57d0c76..204d8ea 100644 --- a/main.go +++ b/main.go @@ -39,6 +39,12 @@ import ( "golang.org/x/sync/errgroup" ) +var ( + commit = "none" + tag = "(devel)" + date = "unknown" +) + func main() { log.SetFlags(0) @@ -70,6 +76,7 @@ func parseAndRun(args []string) (err error) { archiveCommand, releaseCommand, allCommand, + newVersionCommand(), } opts := []ff.Option{ @@ -157,3 +164,35 @@ func parseAndRun(args []string) (err error) { return err } + +func newVersionCommand() *ffcli.Command { + return &ffcli.Command{ + Name: "version", + ShortUsage: "hugoreleaser version", + ShortHelp: "Print the version", + LongHelp: "Print the version", + Exec: func(context.Context, []string) error { + initVersionInfo() + fmt.Printf("hugoreleaser %v, commit %v, built at %v\n", tag, commit, date) + return nil + }, + } +} + +func initVersionInfo() { + bi, ok := debug.ReadBuildInfo() + if !ok { + return + } + + for _, s := range bi.Settings { + switch s.Key { + case "vcs": + case "vcs.revision": + commit = s.Value + case "vcs.time": + date = s.Value + case "vcs.modified": + } + } +}