Skip to content

Commit cc5efb5

Browse files
committed
Build and release go binaries using goreleaser-cross
1 parent 60cae23 commit cc5efb5

3 files changed

Lines changed: 124 additions & 21 deletions

File tree

.github/workflows/build.yaml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
on:
2+
pull_request:
3+
branches:
4+
- master
5+
6+
permissions:
7+
contents: write # needed to write releases
8+
9+
name: Build
10+
jobs:
11+
test-releaser:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Setup go
15+
uses: actions/setup-go@v2
16+
with:
17+
go-version: 1.23.x
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0 # this is important, otherwise it won't checkout the full tree (i.e. no previous tags)
22+
- name: Build
23+
env:
24+
PACKAGE_NAME: github.com/lets-cli/lets
25+
GOLANG_CROSS_VERSION: v1.23
26+
run: |
27+
docker run \
28+
--rm \
29+
-e CGO_ENABLED=1 \
30+
-v /var/run/docker.sock:/var/run/docker.sock \
31+
-v `pwd`:/go/src/${PACKAGE_NAME}\
32+
-v `pwd`/sysroot:/sysroot \
33+
-w /go/src/${PACKAGE_NAME} \
34+
ghcr.io/goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
35+
--clean --skip=validate --skip=publish --snapshot
36+
# - name: Releaser build
37+
# uses: goreleaser/goreleaser-action@v4
38+
# with:
39+
# distribution: goreleaser
40+
# version: v2.6.1
41+
# args: build --clean --skip=validate --snapshot --single-target
42+
# env:
43+
# GOOS: darwin
44+
# GOARCH: amd64
45+
# ZIG_LOCAL_CACHE_DIR: ${{ steps.set_env.outputs.current_dir }}
46+
# ZIG_GLOBAL_CACHE_DIR: ${{ steps.set_env.outputs.current_dir }}
47+
# SDK_PATH: ${{ steps.set_env.outputs.sdk_path }}

.github/workflows/release.yaml

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,39 @@ jobs:
1616
uses: actions/setup-go@v1
1717
with:
1818
go-version: 1.23.x
19+
- name: Run GoReleaser (dry run)
20+
run: |
21+
docker run \
22+
--rm \
23+
-e CGO_ENABLED=1 \
24+
-v /var/run/docker.sock:/var/run/docker.sock \
25+
-v `pwd`:/go/src/${PACKAGE_NAME}\
26+
-v `pwd`/sysroot:/sysroot \
27+
-w /go/src/${PACKAGE_NAME} \
28+
ghcr.io/goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
29+
--clean --skip=validate --skip=publish
30+
- name: Setup release environment
31+
run: |-
32+
echo 'GITHUB_TOKEN=${{secrets.GITHUB_TOKEN}}' > .release-env
33+
echo 'HOMEBREW_TAP_GITHUB_TOKEN=${{secrets.GH_PAT}}' > .release-env
34+
echo 'AUR_GITHUB_TOKEN=${{secrets.AUR_SSH_PRIVATE_KEY}}' > .release-env
1935
- name: Run GoReleaser
20-
uses: goreleaser/goreleaser-action@v4
21-
with:
22-
distribution: goreleaser
23-
version: v2.6.1
24-
args: release --clean
2536
env:
26-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27-
HOMEBREW_TAP_GITHUB_TOKEN: ${{ secrets.GH_PAT }}
28-
AUR_GITHUB_TOKEN: ${{ secrets.AUR_SSH_PRIVATE_KEY }}
37+
PACKAGE_NAME: github.com/lets-cli/lets
38+
GOLANG_CROSS_VERSION: v1.23
39+
run: |
40+
if [ ! -f ".release-env" ]; then
41+
echo ".release-env is required for release";
42+
exit 1;
43+
fi
44+
45+
docker run \
46+
--rm \
47+
-e CGO_ENABLED=1 \
48+
--env-file .release-env \
49+
-v /var/run/docker.sock:/var/run/docker.sock \
50+
-v `pwd`:/go/src/${PACKAGE_NAME}\
51+
-v `pwd`/sysroot:/sysroot \
52+
-w /go/src/${PACKAGE_NAME} \
53+
ghcr.io/goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
54+
release --clean

.goreleaser.yml

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,49 @@ release:
99
prerelease: auto
1010

1111
builds:
12-
- env:
13-
- CGO_ENABLED=1
14-
goos:
15-
- linux
16-
- darwin
17-
goarch:
18-
- amd64
19-
- arm64
20-
ignore:
21-
- goos: linux
22-
goarch: arm64
23-
ldflags:
24-
- -X main.version={{.Version}}
12+
- id: darwin-amd64
13+
main: .
14+
goos:
15+
- darwin
16+
goarch:
17+
- amd64
18+
env:
19+
- PKG_CONFIG_SYSROOT_DIR=/sysroot/macos/amd64
20+
- PKG_CONFIG_PATH=/sysroot/macos/amd64/usr/local/lib/pkgconfig
21+
- CC=o64-clang
22+
- CXX=o64-clang++
23+
flags:
24+
- -mod=readonly
25+
ldflags:
26+
- -s -w -X main.version={{.Version}}
27+
- id: darwin-arm64
28+
main: .
29+
goos:
30+
- darwin
31+
goarch:
32+
- arm64
33+
env:
34+
- PKG_CONFIG_SYSROOT_DIR=/sysroot/macos/arm64
35+
- PKG_CONFIG_PATH=/sysroot/macos/arm64/usr/local/lib/pkgconfig
36+
- CC=oa64-clang
37+
- CXX=oa64-clang++
38+
flags:
39+
- -mod=readonly
40+
ldflags:
41+
- -s -w -X main.version={{.Version}}
42+
- id: linux-amd64
43+
main: .
44+
goos:
45+
- linux
46+
goarch:
47+
- amd64
48+
env:
49+
- CC=x86_64-linux-gnu-gcc
50+
- CXX=x86_64-linux-gnu-g++
51+
flags:
52+
- -mod=readonly
53+
ldflags:
54+
- -s -w -X main.version={{.Version}}
2555

2656
archives:
2757
- formats: [tar.gz]

0 commit comments

Comments
 (0)