Skip to content

Commit 114bd44

Browse files
EndlessTraxCopilot
andauthored
Update CI/CD workflows (#10)
* Update CI/CD workflows * fix(lint): update golangci-lint config to v2 schema and fix errcheck issue * fix(goreleaser): update Taskfile to find goreleaser in ~/go/bin; update config to v2 * Updates for version consistency * ci(lint): use golangci-lint v2.5.0 in CI and pin Taskfile install; keep v2 config * ci(lint): install golangci-lint using @latest to avoid invalid tag * Update .github/workflows/release.yml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fix lint workflow * Fix Lint config * Fix lint config --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 2aa69b4 commit 114bd44

12 files changed

Lines changed: 264 additions & 101 deletions

File tree

.github/workflows/format.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
name: Format
3+
4+
on:
5+
pull_request:
6+
branches: [main]
7+
paths:
8+
- "**/*.go"
9+
- ".github/workflows/format.yml"
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
format-check:
16+
name: Format Check
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
22+
- name: Setup Go
23+
uses: actions/setup-go@v5
24+
with:
25+
go-version-file: go.mod
26+
cache: true
27+
28+
- name: Check formatting
29+
run: |
30+
if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then
31+
echo "The following files are not properly formatted:";
32+
gofmt -s -l .;
33+
echo "";
34+
echo "Please run 'go fmt ./...' to fix formatting issues.";
35+
exit 1;
36+
fi

.github/workflows/lint.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
name: Lint
3+
4+
on:
5+
pull_request:
6+
branches: [main]
7+
paths:
8+
- "**/*.go"
9+
- ".golangci.yml"
10+
- "go.mod"
11+
- "go.sum"
12+
- ".github/workflows/lint.yml"
13+
14+
permissions:
15+
contents: read
16+
17+
jobs:
18+
golangci:
19+
name: golangci-lint
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
25+
- name: Setup Go
26+
uses: actions/setup-go@v5
27+
with:
28+
go-version-file: go.mod
29+
cache: true
30+
31+
- name: golangci-lint
32+
uses: golangci/golangci-lint-action@v8
33+
with:
34+
version: latest

.github/workflows/pr-checks.yml

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

.github/workflows/release.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*'
7+
8+
permissions:
9+
contents: write
10+
11+
concurrency:
12+
group: release-${{ github.ref }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
goreleaser:
17+
name: Release with GoReleaser
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v4
22+
with:
23+
# GoReleaser needs full history for changelog generation
24+
fetch-depth: 0
25+
26+
- name: Setup Go
27+
uses: actions/setup-go@v5
28+
with:
29+
go-version-file: go.mod
30+
cache: true
31+
32+
- name: Validate version match
33+
run: |
34+
# Extract version from git tag (strip 'v' prefix)
35+
TAG_VERSION="${GITHUB_REF#refs/tags/v}"
36+
echo "Tag version: v${TAG_VERSION}"
37+
38+
# Extract version from cmd/root.go
39+
CODE_VERSION=$(grep -oP 'Version = "\K[^"]+' cmd/root.go)
40+
echo "Code version: ${CODE_VERSION}"
41+
42+
# Compare versions
43+
if [ "${TAG_VERSION}" != "${CODE_VERSION}" ]; then
44+
echo "❌ Error: Version mismatch!"
45+
echo " Git tag: v${TAG_VERSION}"
46+
echo " Code: ${CODE_VERSION}"
47+
echo ""
48+
echo "Please update the version in cmd/root.go to match the tag."
49+
exit 1
50+
fi
51+
52+
echo "✅ Version match confirmed: ${CODE_VERSION}"
53+
54+
- name: Run GoReleaser
55+
uses: goreleaser/goreleaser-action@v6
56+
with:
57+
distribution: goreleaser
58+
version: latest
59+
args: release --clean
60+
env:
61+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/tests.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
name: Tests
3+
4+
on:
5+
pull_request:
6+
branches: [ main ]
7+
paths:
8+
- '**/*.go'
9+
- 'go.mod'
10+
- 'go.sum'
11+
- '.github/workflows/tests.yml'
12+
13+
permissions:
14+
contents: read
15+
16+
jobs:
17+
unit-tests:
18+
name: Unit Tests
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
24+
- name: Setup Go
25+
uses: actions/setup-go@v5
26+
with:
27+
go-version-file: go.mod
28+
cache: true
29+
30+
- name: Download deps
31+
run: go mod download
32+
33+
- name: Run tests
34+
run: go test -v -race

.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
# Binary name
1212
brokli
13+
dist/
1314

1415
# Test binary, built with `go test -c`
1516
*.test
@@ -31,6 +32,3 @@ go.work.sum
3132

3233
# env file
3334
.env
34-
35-
# Binary name
36-
brokli

.golangci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ linters:
2525
- unparam
2626
path: _test\.go
2727
paths:
28+
- third_party
29+
- builtin
30+
- examples
2831
- third_party$
2932
- builtin$
3033
- examples$
3134
formatters:
32-
enable:
33-
- gofmt
34-
- goimports
3535
settings:
3636
gofmt:
3737
simplify: true

.goreleaser.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# GoReleaser config for brokli (v2)
2+
# See https://goreleaser.com for reference
3+
4+
version: 2
5+
6+
project_name: brokli
7+
8+
before:
9+
hooks:
10+
- go mod tidy
11+
12+
builds:
13+
- id: brokli
14+
main: .
15+
binary: brokli
16+
env:
17+
- CGO_ENABLED=0
18+
flags:
19+
- -trimpath
20+
ldflags:
21+
- -s -w
22+
goos: [linux, darwin, windows]
23+
goarch: [amd64, arm64]
24+
goarm: ["7"]
25+
26+
archives:
27+
- name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}'
28+
files:
29+
- LICENSE*
30+
- README*
31+
- CHANGELOG*
32+
33+
checksum:
34+
name_template: 'SHA256SUMS_{{ .Version }}.txt'
35+
36+
changelog:
37+
use: github
38+
39+
release:
40+
prerelease: auto

Taskfile.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,58 @@ tasks:
8484
generates:
8585
- "{{.BINARY_NAME}}"
8686

87+
# Release (GoReleaser)
88+
goreleaser-install:
89+
desc: "Install GoReleaser CLI"
90+
cmd: go install github.com/goreleaser/goreleaser/v2@latest
91+
92+
release-check:
93+
desc: "Validate GoReleaser configuration"
94+
cmds:
95+
- |
96+
if command -v goreleaser >/dev/null 2>&1; then
97+
goreleaser check
98+
elif [ -f ~/go/bin/goreleaser ]; then
99+
~/go/bin/goreleaser check
100+
else
101+
echo "GoReleaser not found. Install it with: task goreleaser-install";
102+
exit 1;
103+
fi
104+
105+
release-snapshot:
106+
desc: "Build a local snapshot release (no publish)"
107+
cmds:
108+
- |
109+
if command -v goreleaser >/dev/null 2>&1; then
110+
goreleaser release --snapshot --clean
111+
elif [ -f ~/go/bin/goreleaser ]; then
112+
~/go/bin/goreleaser release --snapshot --clean
113+
else
114+
echo "GoReleaser not found. Install it with: task goreleaser-install";
115+
exit 1;
116+
fi
117+
118+
release:
119+
desc: "Run GoReleaser (publishes if GITHUB_TOKEN is set and tag is present)"
120+
cmds:
121+
- |
122+
if command -v goreleaser >/dev/null 2>&1; then
123+
goreleaser release --clean
124+
elif [ -f ~/go/bin/goreleaser ]; then
125+
~/go/bin/goreleaser release --clean
126+
else
127+
echo "GoReleaser not found. Install it with: task goreleaser-install";
128+
exit 1;
129+
fi
130+
87131
# Maintenance
88132
clean:
89133
desc: "Clean build artifacts and temporary files"
90134
cmds:
91135
- rm -f {{.BINARY_NAME}}
92136
- rm -f {{.COVERAGE_FILE}}
93137
- rm -f coverage.html
138+
- rm -rf dist
94139
- go clean -cache
95140
- go clean -testcache
96141

0 commit comments

Comments
 (0)