-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make now generally leans on goreleaser instead of a separate build process version string has much more interesting data in it. better testing .gitignore ignores `dist` CI for goreleaser config
- Loading branch information
1 parent
d130290
commit 1cab76c
Showing
9 changed files
with
191 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: goreleaser config test | ||
|
||
on: | ||
push: | ||
paths: | ||
- '.goreleaser.yaml' | ||
branches: | ||
- main | ||
tags: | ||
- * | ||
pull_request: | ||
paths: | ||
- '.goreleaser.yaml' | ||
workflow_dispatch: | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: ${{ github.ref != format('refs/heads/{0}', github.event.repository.default_branch) }} | ||
|
||
jobs: | ||
test: | ||
name: Test Goreleaser Config | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
name: "Checkout" | ||
with: | ||
fetch-depth: 0 | ||
- uses: actions/setup-go@v5 | ||
name: "Set up Go" | ||
with: | ||
go-version-file: go.mod | ||
- uses: goreleaser/goreleaser-action@v4 | ||
with: | ||
args: check |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pget | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
//go:build !windows | ||
|
||
package cli | ||
|
||
import ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,46 @@ | ||
package version | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
import "fmt" | ||
|
||
const ( | ||
snapshotString = "snapshot" | ||
) | ||
|
||
var ( | ||
// Version Build Time Injected information | ||
Version string | ||
CommitHash string | ||
BuildTime string | ||
Prerelease string | ||
Snapshot string | ||
OS string | ||
Arch string | ||
Branch string | ||
) | ||
|
||
// GetVersion returns the version information in a human consumable way. This is intended to be used | ||
// when the user requests the version information or in the case of the User-Agent. | ||
func GetVersion() string { | ||
if strings.HasPrefix(Version, "development") { | ||
// This is a development build | ||
return Version | ||
return makeVersionString(Version, CommitHash, BuildTime, Prerelease, Snapshot, OS, Arch, Branch) | ||
} | ||
|
||
func makeVersionString(version, commitHash, buildtime, prerelease, snapshot, os, arch, branch string) (versionString string) { | ||
versionString = fmt.Sprintf("%s(%s)", version, commitHash) | ||
if prerelease != "" { | ||
versionString = fmt.Sprintf("%s-%s", versionString, prerelease) | ||
} else if snapshot != "" { | ||
versionString = fmt.Sprintf("%s-%s", versionString, snapshotString) | ||
} | ||
|
||
if branch != "" && branch != "Main" && branch != "HEAD" { | ||
versionString = fmt.Sprintf("%s[%s]", versionString, branch) | ||
} | ||
|
||
if os != "" && arch != "" { | ||
versionString = fmt.Sprintf("%s/%s-%s", versionString, os, arch) | ||
} else if os != "" { | ||
versionString = fmt.Sprintf("%s/%s", versionString, os) | ||
} | ||
// This should be a tagged release | ||
return fmt.Sprintf("%s(%s)", Version, CommitHash) | ||
|
||
return versionString | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package version | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func Test_makeVersionString(t *testing.T) { | ||
type args struct { | ||
version string | ||
commitHash string | ||
buildtime string | ||
prerelease string | ||
snapshot string | ||
os string | ||
arch string | ||
branch string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
expected string | ||
}{ | ||
{ | ||
name: "Typical Development", | ||
args: args{ | ||
version: "1.0.0", | ||
commitHash: "abc123", | ||
os: "darwin", | ||
arch: "amd64", | ||
branch: "Branch1", | ||
}, | ||
expected: "1.0.0(abc123)[Branch1]/darwin-amd64", | ||
}, | ||
{ | ||
name: "With prerelease and snapshot", | ||
args: args{ | ||
version: "1.0.0", | ||
commitHash: "abc123", | ||
prerelease: "alpha", | ||
snapshot: "20221130", | ||
os: "darwin", | ||
arch: "amd64", | ||
branch: "Branch1", | ||
}, | ||
expected: "1.0.0(abc123)-alpha[Branch1]/darwin-amd64", | ||
}, | ||
{ | ||
name: "No os or arch", | ||
args: args{ | ||
version: "1.0.0", | ||
commitHash: "abc123", | ||
branch: "Branch1", | ||
}, | ||
expected: "1.0.0(abc123)[Branch1]", | ||
}, | ||
{ | ||
name: "Branch Main", | ||
args: args{ | ||
version: "1.0.0", | ||
commitHash: "abc123", | ||
os: "darwin", | ||
arch: "amd64", | ||
branch: "Main", | ||
}, | ||
expected: "1.0.0(abc123)/darwin-amd64", | ||
}, | ||
{ | ||
name: "Branch HEAD", | ||
args: args{ | ||
version: "1.0.0", | ||
commitHash: "abc123", | ||
os: "darwin", | ||
arch: "amd64", | ||
branch: "HEAD", | ||
}, | ||
expected: "1.0.0(abc123)/darwin-amd64", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := makeVersionString(tt.args.version, tt.args.commitHash, tt.args.buildtime, tt.args.prerelease, tt.args.snapshot, tt.args.os, tt.args.arch, tt.args.branch); got != tt.expected { | ||
t.Errorf("makeVersionString() = %v, expected %v", got, tt.expected) | ||
} | ||
}) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.