Skip to content

Commit 32d0896

Browse files
authored
Multiplatform goreleaser (#106)
This PR moves `sq` to using GitHub workflows for publishing.
1 parent ccb4150 commit 32d0896

8 files changed

+557
-198
lines changed

.github/workflows/go.yml

+205-35
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,221 @@
1-
name: Go
2-
on:
3-
push:
4-
paths-ignore:
5-
- 'README.md'
6-
- 'sq.json'
7-
branches:
8-
- master
9-
10-
pull_request:
11-
paths-ignore:
12-
- 'README.md'
13-
- 'sq.json'
14-
branches:
15-
- master
1+
name: Main pipeline
2+
on: push
3+
4+
env:
5+
GO_VERSION: 1.19.3
6+
GORELEASER_VERSION: 1.12.3
167

178
jobs:
18-
build:
9+
go-test:
1910
strategy:
2011
matrix:
21-
os: [ macos-latest, ubuntu-latest, windows-latest]
12+
os: [ macos-12, ubuntu-22.04, windows-2022]
2213

2314
runs-on: ${{ matrix.os }}
2415

2516
steps:
26-
- name: Set up Go 1.19
27-
uses: actions/setup-go@v1
17+
- name: Checkout
18+
uses: actions/checkout@v3
19+
with:
20+
fetch-depth: 0
21+
22+
- name: Set up Go
23+
uses: actions/setup-go@v3
2824
with:
29-
go-version: 1.19
30-
id: go
25+
go-version: ${{ env.GO_VERSION }}
26+
27+
- name: Build
28+
run: go build -v ./...
3129

32-
- name: Check out code into the Go module directory
33-
uses: actions/checkout@v2
30+
- name: Test
31+
run: go test -v ./...
32+
33+
goreleaser-gate:
34+
needs: go-test
35+
runs-on: ubuntu-22.04
36+
37+
steps:
38+
- name: Gate
39+
run: echo "GoReleaser gate"
40+
41+
build-binaries-darwin:
42+
needs: goreleaser-gate
43+
runs-on: macos-12
44+
45+
steps:
46+
- name: Checkout
47+
uses: actions/checkout@v3
48+
with:
49+
fetch-depth: 0
50+
51+
- name: Set up Go
52+
uses: actions/setup-go@v3
53+
with:
54+
go-version: ${{ env.GO_VERSION }}
55+
56+
- name: GoReleaser (build darwin binaries)
57+
uses: goreleaser/goreleaser-action@v3
58+
with:
59+
distribution: goreleaser-pro
60+
version: ${{ env.GORELEASER_VERSION }}
61+
args: build --skip-validate --rm-dist -f .goreleaser-darwin.yml
62+
env:
63+
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
64+
GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
65+
66+
- name: Upload assets (darwin)
67+
uses: actions/upload-artifact@v3
68+
with:
69+
name: dist-darwin
70+
path: dist-darwin
71+
72+
build-binaries-linux-amd64:
73+
needs: goreleaser-gate
74+
runs-on: ubuntu-22.04
75+
76+
steps:
77+
- name: Checkout
78+
uses: actions/checkout@v3
79+
with:
80+
fetch-depth: 0
81+
82+
- name: Set up Go
83+
uses: actions/setup-go@v3
84+
with:
85+
go-version: ${{ env.GO_VERSION }}
86+
87+
- name: GoReleaser (build linux-amd64 binaries)
88+
uses: goreleaser/goreleaser-action@v3
89+
with:
90+
distribution: goreleaser-pro
91+
version: ${{ env.GORELEASER_VERSION }}
92+
args: build --skip-validate --rm-dist -f .goreleaser-linux-amd64.yml
93+
env:
94+
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
95+
GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
96+
97+
- name: Upload assets (linux-amd64)
98+
uses: actions/upload-artifact@v3
99+
with:
100+
name: dist-linux-amd64
101+
path: dist-linux
102+
103+
build-binaries-linux-arm64:
104+
needs: goreleaser-gate
105+
runs-on: ubuntu-22.04
106+
107+
steps:
108+
- name: Checkout
109+
uses: actions/checkout@v3
110+
with:
111+
fetch-depth: 0
34112

35-
- name: Cache Go dependencies
36-
uses: actions/cache@v2
113+
- name: Set up Go
114+
uses: actions/setup-go@v3
37115
with:
38-
path: ~/go/pkg/mod
39-
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
40-
restore-keys: |
41-
${{ runner.os }}-go-
116+
go-version: ${{ env.GO_VERSION }}
42117

43-
- name: Get dependencies
118+
- name: Install toolchain dependencies
44119
run: |
45-
go get -v -t -d ./...
120+
sudo apt update
121+
sudo apt install -y gcc-aarch64-linux-gnu
46122
47-
- name: Build
48-
run: go build -v .
123+
- name: GoReleaser (build linux-arm64 binaries)
124+
uses: goreleaser/goreleaser-action@v3
125+
with:
126+
distribution: goreleaser-pro
127+
version: ${{ env.GORELEASER_VERSION }}
128+
args: build --skip-validate --rm-dist -f .goreleaser-linux-arm64.yml
129+
env:
130+
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
131+
GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
49132

50-
- name: Test
51-
run: go test -short -v ./...
133+
- name: Upload assets (linux-arm64)
134+
uses: actions/upload-artifact@v3
135+
with:
136+
name: dist-linux-arm64
137+
path: dist-linux
138+
139+
140+
build-binaries-windows:
141+
needs: goreleaser-gate
142+
runs-on: windows-2022
143+
144+
steps:
145+
- name: Checkout
146+
uses: actions/checkout@v3
147+
with:
148+
fetch-depth: 0
149+
150+
- name: Set up Go
151+
uses: actions/setup-go@v3
152+
with:
153+
go-version: ${{ env.GO_VERSION }}
154+
155+
- name: GoReleaser (build windows binaries)
156+
uses: goreleaser/goreleaser-action@v3
157+
with:
158+
distribution: goreleaser-pro
159+
version: ${{ env.GORELEASER_VERSION }}
160+
args: build --skip-validate --rm-dist -f .goreleaser-windows.yml
161+
env:
162+
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
163+
GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
164+
165+
166+
- name: Upload assets (windows)
167+
uses: actions/upload-artifact@v3
168+
with:
169+
name: dist-windows
170+
path: dist-windows
171+
172+
publish:
173+
if: startsWith(github.ref, 'refs/tags/v') # Only run this if it's a tag, e.g. v1.0.1
174+
needs: [ build-binaries-darwin, build-binaries-linux-amd64, build-binaries-linux-arm64, build-binaries-windows ]
175+
runs-on: ubuntu-22.04
176+
177+
steps:
178+
- name: Checkout
179+
uses: actions/checkout@v3
180+
with:
181+
fetch-depth: 0
182+
183+
- name: Set up Go
184+
uses: actions/setup-go@v3
185+
with:
186+
go-version: ${{ env.GO_VERSION }}
187+
188+
- name: Download darwin artifacts
189+
uses: actions/download-artifact@v3
190+
with:
191+
name: dist-darwin
192+
path: dist-darwin
193+
194+
- name: Download linux-amd64 artifacts
195+
uses: actions/download-artifact@v3
196+
with:
197+
name: dist-linux-amd64
198+
path: dist-linux
199+
200+
- name: Download linux-arm64 artifacts
201+
uses: actions/download-artifact@v3
202+
with:
203+
name: dist-linux-arm64
204+
path: dist-linux
205+
206+
- name: Download windows artifacts
207+
uses: actions/download-artifact@v3
208+
with:
209+
name: dist-windows
210+
path: dist-windows
211+
212+
- name: GoReleaser (publish)
213+
uses: goreleaser/goreleaser-action@v3
214+
with:
215+
distribution: goreleaser-pro
216+
version: ${{ env.GORELEASER_VERSION }}
217+
args: release -f .goreleaser.yml
218+
env:
219+
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
220+
GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
221+
FURY_TOKEN: ${{ secrets.FURY_TOKEN }}

.goreleaser-darwin.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
before:
2+
hooks:
3+
- go mod tidy
4+
5+
dist: dist-darwin
6+
7+
builds:
8+
- main: .
9+
binary: sq
10+
env:
11+
- CGO_ENABLED=1
12+
goos:
13+
- darwin
14+
goarch:
15+
- amd64
16+
- arm64
17+
ldflags:
18+
- -s -w
19+
- -X github.com/neilotoole/sq/cli/buildinfo.Version={{ .Version }}
20+
- -X github.com/neilotoole/sq/cli/buildinfo.Commit={{ .ShortCommit }}
21+
- -X github.com/neilotoole/sq/cli/buildinfo.Timestamp={{ .Date }}
22+
23+
archives:
24+
- format: binary

.goreleaser-linux-amd64.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
before:
2+
hooks:
3+
- go mod tidy
4+
5+
dist: dist-linux
6+
7+
builds:
8+
-
9+
main: .
10+
binary: sq
11+
env:
12+
- CGO_ENABLED=1
13+
- CGO_LDFLAGS=-static
14+
goos:
15+
- linux
16+
goarch:
17+
- amd64
18+
ldflags:
19+
- -s -w
20+
- -X github.com/neilotoole/sq/cli/buildinfo.Version={{ .Version }}
21+
- -X github.com/neilotoole/sq/cli/buildinfo.Commit={{ .ShortCommit }}
22+
- -X github.com/neilotoole/sq/cli/buildinfo.Timestamp={{ .Date }}
23+
24+
archives:
25+
- format: binary

.goreleaser-linux-arm64.yml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
before:
2+
hooks:
3+
- go mod tidy
4+
5+
dist: dist-linux
6+
7+
builds:
8+
-
9+
main: .
10+
binary: sq
11+
env:
12+
- CGO_ENABLED=1
13+
- CGO_LDFLAGS=-static
14+
- CC=aarch64-linux-gnu-gcc
15+
- CXX=aarch64-linux-gnu-g++
16+
goos:
17+
- linux
18+
goarch:
19+
- arm64
20+
ldflags:
21+
- -extld=aarch64-linux-gnu-gcc
22+
- -s -w
23+
- -X github.com/neilotoole/sq/cli/buildinfo.Version={{ .Version }}
24+
- -X github.com/neilotoole/sq/cli/buildinfo.Commit={{ .ShortCommit }}
25+
- -X github.com/neilotoole/sq/cli/buildinfo.Timestamp={{ .Date }}
26+
27+
archives:
28+
- format: binary

0 commit comments

Comments
 (0)