Skip to content

Commit db590da

Browse files
committed
ci(release): automate versioned builds with GoReleaser
1 parent fe28c90 commit db590da

File tree

2 files changed

+192
-0
lines changed

2 files changed

+192
-0
lines changed

.github/workflows/release.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: Release
2+
on:
3+
push:
4+
tags:
5+
- 'v*'
6+
7+
jobs:
8+
build:
9+
name: Build
10+
strategy:
11+
matrix:
12+
include:
13+
- os: ubuntu-latest
14+
goos: linux
15+
goarch: amd64
16+
suffix: linux_amd64
17+
- os: ubuntu-latest
18+
goos: linux
19+
goarch: arm64
20+
suffix: linux_arm64
21+
- os: macos-latest
22+
goos: darwin
23+
goarch: amd64
24+
suffix: darwin_amd64
25+
- os: macos-latest
26+
goos: darwin
27+
goarch: arm64
28+
suffix: darwin_arm64
29+
runs-on: ${{ matrix.os }}
30+
31+
steps:
32+
- uses: actions/checkout@v4
33+
with:
34+
fetch-depth: 0
35+
36+
- name: Install Linux dependencies
37+
if: matrix.os == 'ubuntu-latest'
38+
run: |
39+
sudo apt-get update
40+
sudo apt-get install -y gcc libsqlite3-dev
41+
# ARM64用のクロスコンパイラも追加
42+
if [ "${{ matrix.goarch }}" = "arm64" ]; then
43+
sudo apt-get install -y gcc-aarch64-linux-gnu
44+
fi
45+
46+
- name: Install macOS dependencies
47+
if: matrix.os == 'macos-latest'
48+
run: |
49+
# macOSではXcodeのツールが既に利用可能
50+
echo "macOS dependencies ready"
51+
52+
- uses: actions/setup-go@v4
53+
with:
54+
go-version: '1.24'
55+
56+
- name: Build binary
57+
env:
58+
CGO_ENABLED: 1
59+
GOOS: ${{ matrix.goos }}
60+
GOARCH: ${{ matrix.goarch }}
61+
CC: ${{ matrix.goarch == 'arm64' && matrix.goos == 'linux' && 'aarch64-linux-gnu-gcc' || 'gcc' }}
62+
run: |
63+
go build -tags=libsql -ldflags="-s -w" -o ghosttype_${{ matrix.suffix }} ./main.go
64+
65+
- name: Create archive
66+
run: |
67+
if [ "${{ matrix.goos }}" = "windows" ]; then
68+
7z a ghosttype_${{ matrix.suffix }}.zip ghosttype_${{ matrix.suffix }}
69+
else
70+
tar -czf ghosttype_${{ matrix.suffix }}.tar.gz ghosttype_${{ matrix.suffix }}
71+
fi
72+
73+
- name: Upload artifact
74+
uses: actions/upload-artifact@v3
75+
with:
76+
name: ghosttype_${{ matrix.suffix }}
77+
path: ghosttype_${{ matrix.suffix }}*
78+
79+
release:
80+
name: Release
81+
needs: build
82+
runs-on: ubuntu-latest
83+
steps:
84+
- uses: actions/checkout@v4
85+
86+
- name: Download all artifacts
87+
uses: actions/download-artifact@v3
88+
89+
- name: Create Release
90+
uses: softprops/action-gh-release@v1
91+
with:
92+
files: |
93+
ghosttype_*/ghosttype_*
94+
draft: false
95+
prerelease: false
96+
env:
97+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.goreleaser.yaml

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
2+
version: 2
3+
4+
before:
5+
hooks:
6+
- go mod tidy
7+
- go generate ./...
8+
9+
builds:
10+
- id: linux-amd64
11+
main: ./main.go
12+
binary: ghosttype
13+
env:
14+
- CGO_ENABLED=1
15+
- CC=gcc
16+
flags:
17+
- -tags=libsql
18+
ldflags:
19+
- -s -w
20+
goos:
21+
- linux
22+
goarch:
23+
- amd64
24+
25+
- id: linux-arm64
26+
main: ./main.go
27+
binary: ghosttype
28+
env:
29+
- CGO_ENABLED=1
30+
- CC=aarch64-linux-gnu-gcc
31+
flags:
32+
- -tags=libsql
33+
ldflags:
34+
- -s -w
35+
goos:
36+
- linux
37+
goarch:
38+
- arm64
39+
40+
- id: darwin-amd64
41+
main: ./main.go
42+
binary: ghosttype
43+
env:
44+
- CGO_ENABLED=1
45+
- CC=o64-clang
46+
flags:
47+
- -tags=libsql
48+
ldflags:
49+
- -s -w
50+
goos:
51+
- darwin
52+
goarch:
53+
- amd64
54+
55+
- id: darwin-arm64
56+
main: ./main.go
57+
binary: ghosttype
58+
env:
59+
- CGO_ENABLED=1
60+
- CC=o64-clang
61+
flags:
62+
- -tags=libsql
63+
ldflags:
64+
- -s -w
65+
goos:
66+
- darwin
67+
goarch:
68+
- arm64
69+
70+
archives:
71+
- id: default
72+
builds:
73+
- linux-amd64
74+
- linux-arm64
75+
- darwin-amd64
76+
- darwin-arm64
77+
format: tar.gz
78+
wrap_in_directory: true
79+
name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}"
80+
81+
changelog:
82+
sort: asc
83+
filters:
84+
exclude:
85+
- "^docs:"
86+
- "^test:"
87+
88+
checksum:
89+
name_template: 'checksums.txt'
90+
91+
release:
92+
github:
93+
owner: trknhr
94+
name: ghosttype
95+
draft: false

0 commit comments

Comments
 (0)