Skip to content

Commit d06a98a

Browse files
committed
Add GitHub Actions workflows for CI, auto-release, and manual release processes; enhance Makefile and documentation
1 parent 0b32b39 commit d06a98a

8 files changed

Lines changed: 1074 additions & 13 deletions

File tree

.github/workflows/auto-release.yml

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
name: Auto Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v[0-9]+.[0-9]+.[0-9]+'
7+
- 'v[0-9]+.[0-9]+.[0-9]+-*'
8+
9+
permissions:
10+
contents: write
11+
12+
jobs:
13+
create-release:
14+
name: Create Release
15+
runs-on: ubuntu-latest
16+
17+
outputs:
18+
upload_url: ${{ steps.create_release.outputs.upload_url }}
19+
tag_name: ${{ steps.get_tag.outputs.tag }}
20+
21+
steps:
22+
- name: Checkout code
23+
uses: actions/checkout@v4
24+
with:
25+
fetch-depth: 0
26+
27+
- name: Get tag
28+
id: get_tag
29+
run: echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
30+
31+
- name: Generate changelog
32+
id: changelog
33+
run: |
34+
# Get the previous tag
35+
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
36+
37+
if [ -z "$PREV_TAG" ]; then
38+
echo "changelog=Initial release" >> $GITHUB_OUTPUT
39+
else
40+
# Generate changelog between tags
41+
CHANGELOG=$(git log --pretty=format:"- %s" ${PREV_TAG}..HEAD | head -20)
42+
echo "changelog<<EOF" >> $GITHUB_OUTPUT
43+
echo "$CHANGELOG" >> $GITHUB_OUTPUT
44+
echo "EOF" >> $GITHUB_OUTPUT
45+
fi
46+
47+
- name: Create Release
48+
id: create_release
49+
uses: actions/create-release@v1
50+
env:
51+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52+
with:
53+
tag_name: ${{ steps.get_tag.outputs.tag }}
54+
release_name: Release ${{ steps.get_tag.outputs.tag }}
55+
body: |
56+
## Changes in ${{ steps.get_tag.outputs.tag }}
57+
58+
${{ steps.changelog.outputs.changelog }}
59+
60+
## Downloads
61+
62+
Choose the appropriate binary for your platform below.
63+
64+
### Installation Instructions
65+
66+
1. Download the appropriate binary for your platform
67+
2. Extract the archive if needed
68+
3. Move the binary to a directory in your PATH
69+
4. Make it executable (Linux/macOS): `chmod +x tunn`
70+
71+
### Verification
72+
73+
All binaries are signed and can be verified using the provided checksums.
74+
draft: false
75+
prerelease: ${{ contains(steps.get_tag.outputs.tag, '-') }}
76+
77+
build-and-upload:
78+
name: Build and Upload Assets
79+
needs: create-release
80+
runs-on: ubuntu-latest
81+
strategy:
82+
matrix:
83+
include:
84+
# Windows
85+
- os: windows
86+
arch: amd64
87+
goos: windows
88+
goarch: amd64
89+
- os: windows
90+
arch: 386
91+
goos: windows
92+
goarch: 386
93+
- os: windows
94+
arch: arm64
95+
goos: windows
96+
goarch: arm64
97+
98+
# Linux
99+
- os: linux
100+
arch: amd64
101+
goos: linux
102+
goarch: amd64
103+
- os: linux
104+
arch: 386
105+
goos: linux
106+
goarch: 386
107+
- os: linux
108+
arch: arm64
109+
goos: linux
110+
goarch: arm64
111+
- os: linux
112+
arch: arm
113+
goos: linux
114+
goarch: arm
115+
116+
# macOS
117+
- os: darwin
118+
arch: amd64
119+
goos: darwin
120+
goarch: amd64
121+
- os: darwin
122+
arch: arm64
123+
goos: darwin
124+
goarch: arm64
125+
126+
# FreeBSD
127+
- os: freebsd
128+
arch: amd64
129+
goos: freebsd
130+
goarch: amd64
131+
132+
steps:
133+
- name: Checkout code
134+
uses: actions/checkout@v4
135+
136+
- name: Set up Go
137+
uses: actions/setup-go@v5
138+
with:
139+
go-version: '1.21'
140+
141+
- name: Build binary
142+
env:
143+
GOOS: ${{ matrix.goos }}
144+
GOARCH: ${{ matrix.goarch }}
145+
run: |
146+
binary_name="tunn"
147+
if [ "${{ matrix.goos }}" = "windows" ]; then
148+
binary_name="${binary_name}.exe"
149+
fi
150+
151+
# Build with version info
152+
go build -ldflags="-s -w -X main.Version=${{ needs.create-release.outputs.tag_name }}" -o "${binary_name}" .
153+
154+
# Create archive
155+
if [ "${{ matrix.goos }}" = "windows" ]; then
156+
zip "tunn-${{ matrix.os }}-${{ matrix.arch }}.zip" "${binary_name}"
157+
echo "ASSET_NAME=tunn-${{ matrix.os }}-${{ matrix.arch }}.zip" >> $GITHUB_ENV
158+
echo "ASSET_PATH=tunn-${{ matrix.os }}-${{ matrix.arch }}.zip" >> $GITHUB_ENV
159+
else
160+
tar -czf "tunn-${{ matrix.os }}-${{ matrix.arch }}.tar.gz" "${binary_name}"
161+
echo "ASSET_NAME=tunn-${{ matrix.os }}-${{ matrix.arch }}.tar.gz" >> $GITHUB_ENV
162+
echo "ASSET_PATH=tunn-${{ matrix.os }}-${{ matrix.arch }}.tar.gz" >> $GITHUB_ENV
163+
fi
164+
165+
- name: Upload Release Asset
166+
uses: actions/upload-release-asset@v1
167+
env:
168+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
169+
with:
170+
upload_url: ${{ needs.create-release.outputs.upload_url }}
171+
asset_path: ${{ env.ASSET_PATH }}
172+
asset_name: ${{ env.ASSET_NAME }}
173+
asset_content_type: application/octet-stream
174+
175+
generate-checksums:
176+
name: Generate Checksums
177+
needs: [create-release, build-and-upload]
178+
runs-on: ubuntu-latest
179+
180+
steps:
181+
- name: Download release assets
182+
run: |
183+
# Download all assets from the release
184+
mkdir -p assets
185+
cd assets
186+
187+
# Get release info
188+
RELEASE_ID=$(curl -s "https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ needs.create-release.outputs.tag_name }}" | jq -r '.id')
189+
190+
# Download all assets
191+
curl -s "https://api.github.com/repos/${{ github.repository }}/releases/${RELEASE_ID}/assets" | \
192+
jq -r '.[].browser_download_url' | \
193+
while read url; do
194+
curl -L -O "$url"
195+
done
196+
197+
- name: Generate checksums
198+
run: |
199+
cd assets
200+
sha256sum * > checksums.txt
201+
cat checksums.txt
202+
203+
- name: Upload checksums
204+
uses: actions/upload-release-asset@v1
205+
env:
206+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
207+
with:
208+
upload_url: ${{ needs.create-release.outputs.upload_url }}
209+
asset_path: assets/checksums.txt
210+
asset_name: checksums.txt
211+
asset_content_type: text/plain

.github/workflows/ci.yml

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main, master, develop ]
6+
pull_request:
7+
branches: [ main, master, develop ]
8+
9+
jobs:
10+
test:
11+
name: Test
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Set up Go
18+
uses: actions/setup-go@v5
19+
with:
20+
go-version: '1.21'
21+
22+
- name: Cache Go modules
23+
uses: actions/cache@v4
24+
with:
25+
path: ~/go/pkg/mod
26+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
27+
restore-keys: |
28+
${{ runner.os }}-go-
29+
30+
- name: Download dependencies
31+
run: go mod download
32+
33+
- name: Verify dependencies
34+
run: go mod verify
35+
36+
- name: Format check
37+
run: |
38+
if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then
39+
gofmt -s -l .
40+
echo "Please run 'go fmt ./...' to format your code"
41+
exit 1
42+
fi
43+
44+
- name: Vet
45+
run: go vet ./...
46+
47+
- name: Run tests
48+
run: go test -race -coverprofile=coverage.out -covermode=atomic ./...
49+
50+
- name: Upload coverage to Codecov
51+
if: github.event_name == 'push'
52+
uses: codecov/codecov-action@v4
53+
with:
54+
file: ./coverage.out
55+
fail_ci_if_error: false
56+
57+
build:
58+
name: Build
59+
runs-on: ubuntu-latest
60+
needs: test
61+
strategy:
62+
matrix:
63+
goos: [linux, windows, darwin]
64+
goarch: [amd64, arm64]
65+
exclude:
66+
# Exclude combinations that are not supported
67+
- goos: windows
68+
goarch: arm64
69+
70+
steps:
71+
- name: Checkout code
72+
uses: actions/checkout@v4
73+
74+
- name: Set up Go
75+
uses: actions/setup-go@v5
76+
with:
77+
go-version: '1.21'
78+
79+
- name: Cache Go modules
80+
uses: actions/cache@v4
81+
with:
82+
path: ~/go/pkg/mod
83+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
84+
restore-keys: |
85+
${{ runner.os }}-go-
86+
87+
- name: Build
88+
env:
89+
GOOS: ${{ matrix.goos }}
90+
GOARCH: ${{ matrix.goarch }}
91+
run: |
92+
mkdir -p dist
93+
binary_name="tunn"
94+
if [ "${{ matrix.goos }}" = "windows" ]; then
95+
binary_name="${binary_name}.exe"
96+
fi
97+
go build -ldflags="-s -w" -o "dist/${binary_name}" .
98+
99+
- name: Upload build artifacts
100+
uses: actions/upload-artifact@v4
101+
with:
102+
name: tunn-${{ matrix.goos }}-${{ matrix.goarch }}
103+
path: dist/
104+
retention-days: 7

0 commit comments

Comments
 (0)