Skip to content

Commit 1ad8f8d

Browse files
committed
chore: add goreleaser
1 parent f88f0aa commit 1ad8f8d

3 files changed

Lines changed: 103 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
goreleaser:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Set up Go
21+
uses: actions/setup-go@v5
22+
with:
23+
go-version: stable
24+
25+
- name: Run GoReleaser
26+
uses: goreleaser/goreleaser-action@v7
27+
with:
28+
distribution: goreleaser
29+
version: "~> v2"
30+
args: release --clean
31+
env:
32+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.goreleaser.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
2+
version: 2
3+
4+
before:
5+
hooks:
6+
- go mod tidy
7+
8+
builds:
9+
- id: codebot
10+
main: ./cmd/codebot
11+
binary: codebot
12+
env:
13+
- CGO_ENABLED=0
14+
ldflags:
15+
- -s -w
16+
- -X main.version={{.Version}}
17+
- -X main.commit={{.Commit}}
18+
- -X main.date={{.CommitDate}}
19+
goos:
20+
- linux
21+
- darwin
22+
- windows
23+
goarch:
24+
- amd64
25+
- arm64
26+
27+
archives:
28+
- id: codebot-archive
29+
ids:
30+
- codebot
31+
formats:
32+
- tar.gz
33+
format_overrides:
34+
- goos: windows
35+
formats:
36+
- zip
37+
name_template: >-
38+
{{ .ProjectName }}_{{ .Version }}_
39+
{{- title .Os }}_
40+
{{- if eq .Arch "amd64" }}x86_64
41+
{{- else }}{{ .Arch }}{{ end }}
42+
43+
checksum:
44+
name_template: "{{ .ProjectName }}_checksums.txt"
45+
algorithm: sha256
46+
47+
changelog:
48+
sort: asc
49+
filters:
50+
exclude:
51+
- "^docs:"
52+
- "^test:"
53+
- "^chore:"
54+
55+
release:
56+
github:
57+
owner: voocel
58+
name: codebot

cmd/codebot/main.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@ import (
1010
"github.com/voocel/codebot/internal/ui"
1111
)
1212

13+
// Set via ldflags by GoReleaser.
14+
var (
15+
version = "dev"
16+
commit = "none"
17+
date = "unknown"
18+
)
19+
1320
func main() {
21+
versionFlag := flag.Bool("version", false, "Print version and exit")
1422
printFlag := flag.Bool("p", false, "Print mode (non-interactive, pipe-friendly)")
1523
jsonFlag := flag.Bool("json", false, "JSON output mode (implies -p)")
1624
continueFlag := flag.Bool("c", false, "Continue most recent session")
@@ -19,6 +27,11 @@ func main() {
1927
policyProfileFlag := flag.String("policy-profile", "balanced", "Policy profile: strict, balanced, off")
2028
flag.Parse()
2129

30+
if *versionFlag {
31+
fmt.Printf("codebot %s (%s %s)\n", version, commit[:min(7, len(commit))], date)
32+
return
33+
}
34+
2235
printMode := *printFlag || *jsonFlag
2336

2437
rt, err := bootstrap.Boot(bootstrap.Options{

0 commit comments

Comments
 (0)