Skip to content

Commit

Permalink
Version handling fixes (#563)
Browse files Browse the repository at this point in the history
* Version fixes

Signed-off-by: Karl Hepworth <karl@previousnext.com.au>
  • Loading branch information
fubarhouse committed Jun 17, 2024
1 parent dab71c2 commit 8da10ea
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 43 deletions.
23 changes: 2 additions & 21 deletions .github/workflows/goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,6 @@ jobs:
uses: actions/setup-go@v4
with:
go-version: '1.21'
-
name: Create version helper
run: |
cat > service/library/version_state.go << EOF
package library
import (
"fmt"
"strings"
)
var PYGMY_VERSION = "${GITHUB_REF}"
func printversion() bool {
parts := strings.Split(PYGMY_VERSION, "/")
if PYGMY_VERSION == "" {
return false
}
fmt.Printf("Pygmy version v%v\n", parts[len(parts)-1])
return true
}
EOF
-
name: Fetch Dependencies
run: go mod vendor
Expand All @@ -65,13 +46,13 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
-
name: Check GoReleaser
name: Dry-Run GoReleaser
uses: goreleaser/goreleaser-action@v6
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
with:
distribution: goreleaser
version: '~> v2'
args: release --clean --skip=docker --skip=homebrew --skip=publish
args: release --clean --snapshot --skip=docker --skip=homebrew --skip=publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
-
Expand Down
15 changes: 15 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,17 @@ archives:
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}_static"
builds:
- pygmy-static

builds:
- id: pygmy
env:
- CGO_ENABLED=0
ldflags:
- -X main.Version={{.Tag}}
- -X main.CommitSHA={{.FullCommit}}
- -X main.BuildDate={{.CommitDate}}
- -X main.GoOS={{.Os}}
- -X main.GoArch={{.Arch}}
goos:
- linux
- darwin
Expand All @@ -39,6 +46,11 @@ builds:
flags:
- -a
ldflags:
- -X main.Version={{.Tag}}
- -X main.CommitSHA={{.FullCommit}}
- -X main.BuildDate={{.CommitDate}}
- -X main.GoOS={{.Os}}
- -X main.GoArch={{.Arch}}
- -extldflags "-static"
goos:
- linux
Expand All @@ -48,6 +60,9 @@ builds:
- arm
- arm64

snapshot:
name_template: "{{ .Version }}-SNAPSHOT-{{.ShortCommit}}"

brews:
- ids:
- pygmy
Expand Down
3 changes: 2 additions & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
package cmd

import (
"github.com/pygmystack/pygmy/service/library"
"github.com/spf13/cobra"

"github.com/pygmystack/pygmy/service/library"
)

// versionCmd represents the version command
Expand Down
11 changes: 5 additions & 6 deletions service/library/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@ package library

import (
"fmt"
"runtime/debug"
)

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

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

fmt.Printf("Pygmy version unidentifiable.\n")
fmt.Printf("Pygmy %s\n", info.Main.Version)
}
15 changes: 0 additions & 15 deletions service/library/version_state.go

This file was deleted.

0 comments on commit 8da10ea

Please sign in to comment.