Skip to content

Commit 0abc49e

Browse files
authored
ci: add goreleaser (#17)
Co-authored-by: Ayoub Faouzi <ayoubfaouzi@users.noreply.github.com>
1 parent 8ddbb93 commit 0abc49e

4 files changed

Lines changed: 95 additions & 3 deletions

File tree

.github/workflows/release.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Release
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
permissions:
8+
contents: write
9+
10+
jobs:
11+
goreleaser:
12+
name: GoReleaser
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v6
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Install Go
21+
uses: actions/setup-go@v6
22+
with:
23+
go-version: 1.25.x
24+
25+
- name: Run GoReleaser
26+
uses: goreleaser/goreleaser-action@v6
27+
with:
28+
version: latest
29+
args: release --clean
30+
env:
31+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.goreleaser.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
version: 2
2+
3+
builds:
4+
- id: saferwall-cli
5+
binary: saferwall-cli
6+
main: ./cli.go
7+
env:
8+
- CGO_ENABLED=0
9+
goos:
10+
- linux
11+
- darwin
12+
- windows
13+
goarch:
14+
- amd64
15+
- arm64
16+
ldflags:
17+
- -s -w -X main.version={{.Version}} -X main.commit={{.ShortCommit}} -X main.date={{.Date}}
18+
19+
archives:
20+
- id: saferwall-cli
21+
formats:
22+
- tar.gz
23+
format_overrides:
24+
- goos: windows
25+
formats:
26+
- zip
27+
name_template: >-
28+
{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}
29+
30+
checksum:
31+
name_template: "checksums.txt"
32+
33+
changelog:
34+
sort: asc
35+
filters:
36+
exclude:
37+
- "^docs:"
38+
- "^test:"
39+
- "^ci:"

cli.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ import (
88
"github.com/saferwall/cli/cmd"
99
)
1010

11+
var (
12+
version = "dev"
13+
commit = "none"
14+
date = "unknown"
15+
)
16+
1117
func main() {
18+
cmd.SetVersionInfo(version, commit, date)
1219
cmd.Execute()
1320
}

cmd/version.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,30 @@ import (
1010
"github.com/spf13/cobra"
1111
)
1212

13-
const (
14-
version = "0.5.0"
13+
var (
14+
version = "dev"
15+
commit = "none"
16+
date = "unknown"
1517
)
1618

19+
// SetVersionInfo sets the build-time version information.
20+
func SetVersionInfo(v, c, d string) {
21+
if v != "" {
22+
version = v
23+
}
24+
if c != "" {
25+
commit = c
26+
}
27+
if d != "" {
28+
date = d
29+
}
30+
}
31+
1732
var versionCmd = &cobra.Command{
1833
Use: "version",
1934
Short: "Print the version number",
2035
Long: "Print the version number",
2136
Run: func(cmd *cobra.Command, args []string) {
22-
fmt.Printf("You are using version %s\n", version)
37+
fmt.Printf("You are using version %s (commit: %s, built: %s)\n", version, commit, date)
2338
},
2439
}

0 commit comments

Comments
 (0)