Skip to content

Commit 8da10ea

Browse files
authored
Version handling fixes (#563)
* Version fixes Signed-off-by: Karl Hepworth <karl@previousnext.com.au>
1 parent dab71c2 commit 8da10ea

File tree

5 files changed

+24
-43
lines changed

5 files changed

+24
-43
lines changed

.github/workflows/goreleaser.yml

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,6 @@ jobs:
2929
uses: actions/setup-go@v4
3030
with:
3131
go-version: '1.21'
32-
-
33-
name: Create version helper
34-
run: |
35-
cat > service/library/version_state.go << EOF
36-
package library
37-
import (
38-
"fmt"
39-
"strings"
40-
)
41-
var PYGMY_VERSION = "${GITHUB_REF}"
42-
func printversion() bool {
43-
parts := strings.Split(PYGMY_VERSION, "/")
44-
if PYGMY_VERSION == "" {
45-
return false
46-
}
47-
fmt.Printf("Pygmy version v%v\n", parts[len(parts)-1])
48-
return true
49-
}
50-
EOF
5132
-
5233
name: Fetch Dependencies
5334
run: go mod vendor
@@ -65,13 +46,13 @@ jobs:
6546
env:
6647
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6748
-
68-
name: Check GoReleaser
49+
name: Dry-Run GoReleaser
6950
uses: goreleaser/goreleaser-action@v6
7051
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
7152
with:
7253
distribution: goreleaser
7354
version: '~> v2'
74-
args: release --clean --skip=docker --skip=homebrew --skip=publish
55+
args: release --clean --snapshot --skip=docker --skip=homebrew --skip=publish
7556
env:
7657
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7758
-

.goreleaser.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,17 @@ archives:
1212
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}_static"
1313
builds:
1414
- pygmy-static
15+
1516
builds:
1617
- id: pygmy
1718
env:
1819
- CGO_ENABLED=0
20+
ldflags:
21+
- -X main.Version={{.Tag}}
22+
- -X main.CommitSHA={{.FullCommit}}
23+
- -X main.BuildDate={{.CommitDate}}
24+
- -X main.GoOS={{.Os}}
25+
- -X main.GoArch={{.Arch}}
1926
goos:
2027
- linux
2128
- darwin
@@ -39,6 +46,11 @@ builds:
3946
flags:
4047
- -a
4148
ldflags:
49+
- -X main.Version={{.Tag}}
50+
- -X main.CommitSHA={{.FullCommit}}
51+
- -X main.BuildDate={{.CommitDate}}
52+
- -X main.GoOS={{.Os}}
53+
- -X main.GoArch={{.Arch}}
4254
- -extldflags "-static"
4355
goos:
4456
- linux
@@ -48,6 +60,9 @@ builds:
4860
- arm
4961
- arm64
5062

63+
snapshot:
64+
name_template: "{{ .Version }}-SNAPSHOT-{{.ShortCommit}}"
65+
5166
brews:
5267
- ids:
5368
- pygmy

cmd/version.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121
package cmd
2222

2323
import (
24-
"github.com/pygmystack/pygmy/service/library"
2524
"github.com/spf13/cobra"
25+
26+
"github.com/pygmystack/pygmy/service/library"
2627
)
2728

2829
// versionCmd represents the version command

service/library/version.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@ package library
22

33
import (
44
"fmt"
5+
"runtime/debug"
56
)
67

78
// Version describes which version of Pygmy is running.
89
func Version(c Config) {
10+
info, _ := debug.ReadBuildInfo()
911

10-
// printversion is updated as static content via GitHub Actions.
11-
// If this version is not injected as static content, the version
12-
// is deemed unidentifiable - it should be assumed the binary was
13-
// compiled outside of official release management.
14-
if printversion() {
12+
if info.Main.Version == "(devel)" {
13+
fmt.Println("Development version")
1514
return
1615
}
1716

18-
fmt.Printf("Pygmy version unidentifiable.\n")
17+
fmt.Printf("Pygmy %s\n", info.Main.Version)
1918
}

service/library/version_state.go

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)