Skip to content

Commit 474c9b5

Browse files
committed
Add goreleaser and github workflow
1 parent 3f5adc9 commit 474c9b5

2 files changed

Lines changed: 159 additions & 0 deletions

File tree

.github/workflows/releaser.yaml

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
name: Release
2+
3+
on:
4+
pull_request:
5+
push:
6+
7+
permissions:
8+
contents: write
9+
id-token: write
10+
packages: write
11+
12+
jobs:
13+
lint:
14+
name: Lint
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
- name: Set up Go
19+
uses: actions/setup-go@v5
20+
with:
21+
go-version-file: 'go.mod'
22+
- name: golangci-lint
23+
uses: golangci/golangci-lint-action@v8
24+
with:
25+
only-new-issues: true
26+
27+
releaser:
28+
name: Release
29+
runs-on: ubuntu-latest
30+
steps:
31+
- name: Checkout
32+
uses: actions/checkout@v4
33+
with:
34+
fetch-depth: 0
35+
36+
- name: Set up Go
37+
uses: actions/setup-go@v5
38+
with:
39+
go-version-file: 'go.mod'
40+
41+
- name: Set AUTOUPDATE_CHANNEL on tags
42+
run: echo "AUTOUPDATE_CHANNEL=stable" >> $GITHUB_ENV
43+
if: startsWith(github.ref, 'refs/tags/v')
44+
45+
- name: Prepare
46+
run: go generate ./...
47+
48+
- name: Check Git status
49+
id: git
50+
run: |
51+
RESULT=$(git status --untracked-files=no --porcelain)
52+
echo "gitstatus=$RESULT" >> $GITHUB_OUTPUT
53+
54+
- name: Check if go prepare updated generated Go code
55+
if: steps.git.outputs.gitstatus != '' && startsWith(github.ref, 'refs/tags/v')
56+
run: |
57+
echo '"go generate" changed some Go generated code, run "go generate ./" locally and make a Pull Request with the changes'
58+
git diff
59+
exit 1
60+
61+
#- name: Test
62+
# run: go test -v ./...
63+
64+
- name: Validate build
65+
run: go run .
66+
67+
#- name: Set up cosign
68+
# uses: sigstore/cosign-installer@v3
69+
70+
- name: Run GoReleaser for snapshot
71+
uses: goreleaser/goreleaser-action@v6
72+
# only for PRs and push on branches
73+
if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
74+
with:
75+
version: '~> v2'
76+
args: release --clean --snapshot --skip=publish,sign
77+
env:
78+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
79+
80+
- name: Run GoReleaser
81+
uses: goreleaser/goreleaser-action@v6
82+
# only for tags
83+
if: startsWith(github.ref, 'refs/tags/v')
84+
with:
85+
version: '~> v2'
86+
args: release --clean
87+
env:
88+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
89+
90+
- name: Archive binaries
91+
uses: actions/upload-artifact@v4
92+
with:
93+
retention-days: 5
94+
name: binaries
95+
path: dist
96+
97+
- name: Archive Linux binary
98+
uses: actions/upload-artifact@v4
99+
with:
100+
retention-days: 5
101+
name: linux-binary
102+
path: dist/kyx_linux_amd64.tar.gz

.goreleaser.yaml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
version: 2
2+
3+
before:
4+
hooks:
5+
- go mod download
6+
7+
changelog:
8+
sort: desc
9+
use: github
10+
filters:
11+
exclude:
12+
- Merge branch
13+
- Merge pull request
14+
15+
builds:
16+
- env:
17+
- CGO_ENABLED=0
18+
goos:
19+
- linux
20+
- darwin
21+
goarch:
22+
- 386
23+
- amd64
24+
- arm
25+
- arm64
26+
ignore:
27+
- goos: darwin
28+
goarch: 386
29+
- goos: darwin
30+
goarch: arm
31+
main: ./
32+
binary: kyx
33+
ldflags: -s -w -X 'main.channel={{ if index .Env "AUTOUPDATE_CHANNEL" }}{{ .Env.AUTOUPDATE_CHANNEL }}{{ else }}dev{{ end }}' -X 'main.buildDate={{ .Date }}' -X 'main.version={{ .Version }}'
34+
flags:
35+
- -trimpath
36+
37+
archives:
38+
- name_template: '{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'
39+
files:
40+
- README.md
41+
- LICENSE
42+
checksum:
43+
name_template: 'checksums.txt'
44+
45+
source:
46+
enabled: true
47+
48+
snapshot:
49+
version_template: "next"
50+
51+
universal_binaries:
52+
- replace: true
53+
name_template: kyx
54+
55+
release:
56+
footer: |
57+
**Full Changelog**: https://github.com/SoureCode/kyx/compare/{{ .PreviousTag }}...{{ .Tag }}

0 commit comments

Comments
 (0)