Skip to content

Commit 3ceedbe

Browse files
holllclaude
andcommitted
新增 GitHub Actions 自动编译工作流
- Push/PR → main:go vet + 5 平台交叉编译验证 - Push tag v*:自动编译并发布 GitHub Release - 编译目标:linux/amd64、linux/arm64、windows/amd64、darwin/amd64、darwin/arm64 - CGO_ENABLED=0 纯静态二进制(modernc.org/sqlite 无需 CGO) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 9969395 commit 3ceedbe

1 file changed

Lines changed: 84 additions & 0 deletions

File tree

.github/workflows/build.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: Build & Release
2+
3+
on:
4+
push:
5+
branches: [main]
6+
tags: ['v*']
7+
pull_request:
8+
branches: [main]
9+
10+
jobs:
11+
build:
12+
name: Build (${{ matrix.goos }}/${{ matrix.goarch }})
13+
runs-on: ubuntu-latest
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
include:
18+
- goos: linux
19+
goarch: amd64
20+
- goos: linux
21+
goarch: arm64
22+
- goos: windows
23+
goarch: amd64
24+
- goos: darwin
25+
goarch: amd64
26+
- goos: darwin
27+
goarch: arm64
28+
steps:
29+
- uses: actions/checkout@v4
30+
31+
- uses: actions/setup-go@v5
32+
with:
33+
go-version-file: go.mod
34+
cache: true
35+
36+
# 只在 linux/amd64 运行 vet,避免重复
37+
- name: Vet
38+
if: matrix.goos == 'linux' && matrix.goarch == 'amd64'
39+
run: go vet ./...
40+
41+
- name: Build
42+
env:
43+
GOOS: ${{ matrix.goos }}
44+
GOARCH: ${{ matrix.goarch }}
45+
CGO_ENABLED: "0"
46+
run: |
47+
EXT=""
48+
[ "${{ matrix.goos }}" = "windows" ] && EXT=".exe"
49+
OUTPUT="tikdownloader-${{ matrix.goos }}-${{ matrix.goarch }}${EXT}"
50+
go build -trimpath -ldflags="-s -w" -o "${OUTPUT}" .
51+
echo "Built: ${OUTPUT}"
52+
53+
# 仅在 tag 触发时上传产物,供 release 作业使用
54+
- name: Upload artifact
55+
if: startsWith(github.ref, 'refs/tags/v')
56+
uses: actions/upload-artifact@v4
57+
with:
58+
name: tikdownloader-${{ matrix.goos }}-${{ matrix.goarch }}
59+
path: tikdownloader-${{ matrix.goos }}-${{ matrix.goarch }}*
60+
if-no-files-found: error
61+
62+
release:
63+
name: Publish Release
64+
needs: build
65+
if: startsWith(github.ref, 'refs/tags/v')
66+
runs-on: ubuntu-latest
67+
permissions:
68+
contents: write
69+
steps:
70+
- name: Download all artifacts
71+
uses: actions/download-artifact@v4
72+
with:
73+
path: dist
74+
merge-multiple: true
75+
76+
- name: List artifacts
77+
run: ls -lh dist/
78+
79+
- name: Create GitHub Release
80+
uses: softprops/action-gh-release@v2
81+
with:
82+
files: dist/*
83+
generate_release_notes: true
84+
fail_on_unmatched_files: true

0 commit comments

Comments
 (0)