diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index c9a0e746..c01b6728 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -12,8 +12,17 @@ jobs: runs-on: ubuntu-latest steps: - name: - uses: actions/checkout@v2 - + uses: actions/checkout@v3 + - name: Pull tags and refs + run: git fetch --prune --unshallow + - name: Check if version is updated + run: | + export ExpectedVersion=$(git describe --tags --abbrev=0) + export DefinedVersion=$(cat cmd/gemini/Version) + if [ "$ExpectedVersion" != "$DefinedVersion" ]; then + echo "Expect to have '$ExpectedVersion', but got '$DefinedVersion'" + exit 1 + fi - name: Setup Go uses: actions/setup-go@v2 with: diff --git a/cmd/gemini/Version b/cmd/gemini/Version new file mode 100644 index 00000000..25b56915 --- /dev/null +++ b/cmd/gemini/Version @@ -0,0 +1 @@ +v1.8.3 \ No newline at end of file diff --git a/cmd/gemini/main.go b/cmd/gemini/main.go index b7e1ea1b..5fbe1c29 100644 --- a/cmd/gemini/main.go +++ b/cmd/gemini/main.go @@ -14,14 +14,19 @@ package main import ( + _ "embed" "fmt" "os" + "runtime/debug" ) +//go:generate sh -c "git describe --tags --abbrev=0 | tr -d '\n' > ./Version" +//go:embed Version +var version string + var ( - commit = "none" - version = "dev" - date = "unknown" + commit = "none" + date = "unknown" ) func main() { @@ -30,3 +35,16 @@ func main() { os.Exit(1) } } + +func init() { + if info, ok := debug.ReadBuildInfo(); ok { + for _, setting := range info.Settings { + switch setting.Key { + case "vcs.revision": + commit = setting.Value + case "vcs.time": + date = setting.Value + } + } + } +}