Skip to content

Commit c377df4

Browse files
committed
ci(release): migrate to goreleaser with zig-based cross-compilation
Update release workflow to use goreleaser for streamlined cross-platform builds with zig for macOS, Linux, and Windows. Add `.goreleaser.yaml` configuration and update `.dockerignore` and `.gitignore` for build artifacts.
1 parent 5951fa9 commit c377df4

File tree

4 files changed

+135
-23
lines changed

4 files changed

+135
-23
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ db
2323
nginx
2424
templates
2525
backup
26+
dist
2627

2728
# Patterns
2829
**/.DS_Store

.github/workflows/release.yml

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
1-
name : Release Go Binary
1+
name: Release gGi Binary
22

33
on:
4-
release:
5-
types: [created]
4+
push:
5+
tags:
6+
- 'v*'
67

78
permissions:
8-
contents: write
9-
packages: write
9+
contents: write # needed to write releases
1010

1111
jobs:
12-
releases-matrix:
13-
name: Release Go Binary
14-
runs-on: ubuntu-latest
15-
strategy:
16-
matrix:
17-
goos: [linux, windows, darwin]
18-
goarch: [amd64]
19-
# exclude:
20-
# - goarch: arm64
21-
# goos: windows
12+
release:
13+
runs-on: macos-latest
2214
steps:
2315
- uses: actions/checkout@v4
24-
- uses: wangyoucao577/go-release-action@v1
2516
with:
26-
github_token: ${{ secrets.GITHUB_TOKEN }}
27-
goos: ${{ matrix.goos }}
28-
goarch: ${{ matrix.goarch }}
29-
ldflags: -w -s
30-
extra_files: LICENSE README.md .env.example relays_blastr.example.json relays_import.example.json templates
31-
overwrite: true
32-
binary_name: haven
17+
fetch-depth: 0
18+
- uses: actions/setup-go@v5
19+
with:
20+
go-version-file: go.mod
21+
- uses: mlugg/setup-zig@v2
22+
- name: Set output
23+
id: macos_sdk
24+
run: echo "path=$(xcrun --show-sdk-path)" >> $GITHUB_OUTPUT
25+
- uses: goreleaser/goreleaser-action@v6
26+
with:
27+
version: latest
28+
args: release --clean
29+
env:
30+
SDK_PATH: ${{ steps.macos_sdk.outputs.path }}
31+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ haven
66
.idea/
77
db.zip
88
db/
9+
dist/
910
blossom/

.goreleaser.yaml

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
project_name: haven
2+
before:
3+
hooks:
4+
- go mod tidy
5+
builds:
6+
- id: haven-zig-cross-compilation-macos
7+
goos:
8+
- darwin
9+
goarch:
10+
- amd64
11+
- arm64
12+
ldflags:
13+
- -s -w
14+
flags:
15+
- -trimpath
16+
- -buildmode=pie
17+
env:
18+
- CGO_ENABLED=1
19+
- >-
20+
{{- if eq .Os "darwin" }}
21+
{{- if eq .Arch "amd64"}}CC=zig c -target x86_64-macos-none -F{{ .Env.SDK_PATH }}/System/Library/Frameworks{{- end }}
22+
{{- if eq .Arch "arm64"}}CC=zig c -target aarch64-macos-none -F{{ .Env.SDK_PATH }}/System/Library/Frameworks{{- end }}
23+
{{- end }}
24+
- >-
25+
{{- if eq .Os "darwin" }}
26+
{{- if eq .Arch "amd64"}}CC=zig c++ -target x86_64-macos-none -F{{ .Env.SDK_PATH }}/System/Library/Frameworks{{- end }}
27+
{{- if eq .Arch "arm64"}}CC=zig c++ -target aarch64-macos-none -F{{ .Env.SDK_PATH }}/System/Library/Frameworks{{- end }}
28+
{{- end }}
29+
30+
- id: haven-zig-cross-compilation-linux
31+
goos:
32+
- linux
33+
goarch:
34+
- amd64
35+
- arm64
36+
ldflags:
37+
- -s -w
38+
flags:
39+
- -trimpath
40+
env:
41+
- CGO_ENABLED=1
42+
- >-
43+
{{- if eq .Os "linux" }}
44+
{{- if eq .Arch "amd64" }}CC=zig c -target x86_64-linux-musl{{- end }}
45+
{{- if eq .Arch "arm64"}}CC=zig c -target aarch64-linux-musl{{- end }}
46+
{{- end }}
47+
- >-
48+
{{- if eq .Os "linux" }}
49+
{{- if eq .Arch "amd64" }}CC=zig c++ -target x86_64-linux-musl{{- end }}
50+
{{- if eq .Arch "arm64"}}CC=zig c++ -target aarch64-linux-musl{{- end }}
51+
{{- end }}
52+
53+
- id: haven-zig-cross-compilation-windows
54+
goos:
55+
- windows
56+
goarch:
57+
- amd64
58+
- arm64
59+
ldflags:
60+
- -s -w
61+
flags:
62+
- -trimpath
63+
env:
64+
- CGO_ENABLED=1
65+
- >-
66+
{{- if eq .Os "windows" }}
67+
{{- if eq .Arch "amd64" }}CC=zig c -target x86_64-windows-gnu{{- end }}
68+
{{- if eq .Arch "arm64"}}CC=zig c -target aarch64-windows-gnu{{- end }}
69+
{{- end }}
70+
- >-
71+
{{- if eq .Os "windows" }}
72+
{{- if eq .Arch "amd64" }}CC=zig c++ -target x86_64-windows-gnu{{- end }}
73+
{{- if eq .Arch "arm64"}}CC=zig c++ -target aarch64-windows-gnu{{- end }}
74+
{{- end }}
75+
76+
archives:
77+
- format: tar.gz
78+
# this name template makes the OS and Arch compatible with the results of uname.
79+
name_template: >-
80+
{{ .ProjectName }}_
81+
{{- title .Os }}_
82+
{{- if eq .Arch "amd64" }}x86_64
83+
{{- else if eq .Arch "386" }}i386
84+
{{- else }}{{ .Arch }}{{ end }}
85+
{{- if .Arm }}v{{ .Arm }}{{ end }}
86+
# use zip for windows archives
87+
format_overrides:
88+
- goos: windows
89+
format: zip
90+
files:
91+
- LICENSE
92+
- README.md
93+
- .env.example
94+
- relays_blastr.example.json
95+
- relays_import.example.json
96+
- templates/**/*
97+
checksum:
98+
name_template: 'checksums.txt'
99+
snapshot:
100+
name_template: "{{ incpatch .Version }}-next"
101+
changelog:
102+
sort: asc
103+
filters:
104+
exclude:
105+
- '^docs:'
106+
- '^test:'
107+
108+
# The lines beneath this are called `modelines`. See `:help modeline`
109+
# Feel free to remove those if you don't want/use them.
110+
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
111+
# vim: set ts=2 sw=2 tw=0 fo=cnqoj

0 commit comments

Comments
 (0)