|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+name: Go Build and Release
|
|
|
2
|
+
|
|
|
3
|
+on:
|
|
|
4
|
+ push:
|
|
|
5
|
+ tags:
|
|
|
6
|
+ - 'v*.*.*' # 当推送带有版本号的 tag(例如 v1.0.0)时触发工作流
|
|
|
7
|
+
|
|
|
8
|
+jobs:
|
|
|
9
|
+ build:
|
|
|
10
|
+ runs-on: ubuntu-latest
|
|
|
11
|
+
|
|
|
12
|
+ strategy:
|
|
|
13
|
+ matrix:
|
|
|
14
|
+ goos: [linux, windows] # 指定要构建的操作系统
|
|
|
15
|
+ goarch: [amd64] # 指定架构
|
|
|
16
|
+ go_variant: [default, alpine] # 使用默认和 Alpine 版本打包 Linux
|
|
|
17
|
+
|
|
|
18
|
+ steps:
|
|
|
19
|
+ - name: Checkout code
|
|
|
20
|
+ uses: actions/checkout@v3
|
|
|
21
|
+
|
|
|
22
|
+ - name: Set up Go environment
|
|
|
23
|
+ uses: actions/setup-go@v4
|
|
|
24
|
+ with:
|
|
|
25
|
+ go-version: '1.22' # 选择 Go 版本
|
|
|
26
|
+
|
|
|
27
|
+ # 如果是 Linux 或 Alpine,需要安装 SQLite 依赖
|
|
|
28
|
+ - name: Install SQLite dependencies (Linux/Alpine)
|
|
|
29
|
+ if: matrix.goos == 'linux' # 仅在 Linux 下运行
|
|
|
30
|
+ run: |
|
|
|
31
|
+ if [ "${{ matrix.go_variant }}" = "alpine" ]; then
|
|
|
32
|
+ sudo apt-get update
|
|
|
33
|
+ sudo apt-get install -y musl-dev sqlite3
|
|
|
34
|
+ else
|
|
|
35
|
+ sudo apt-get update
|
|
|
36
|
+ sudo apt-get install -y libsqlite3-dev
|
|
|
37
|
+ fi
|
|
|
38
|
+
|
|
|
39
|
+ - name: Build for ${{ matrix.goos }}-${{ matrix.goarch }}-${{ matrix.go_variant }}
|
|
|
40
|
+ run: |
|
|
|
41
|
+ if [ "${{ matrix.go_variant }}" = "alpine" ]; then
|
|
|
42
|
+ GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} CGO_ENABLED=1 CC=/usr/bin/gcc go build -ldflags "-s -w" -o myapp-alpine-${{ matrix.goos }}-${{ matrix.goarch }} .
|
|
|
43
|
+ else
|
|
|
44
|
+ GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} CGO_ENABLED=1 go build -o myapp-${{ matrix.goos }}-${{ matrix.goarch }} .
|
|
|
45
|
+ fi
|
|
|
46
|
+
|
|
|
47
|
+ - name: Upload artifact
|
|
|
48
|
+ uses: actions/upload-artifact@v3
|
|
|
49
|
+ with:
|
|
|
50
|
+ name: myapp-${{ matrix.goos }}-${{ matrix.goarch }}-${{ matrix.go_variant }}
|
|
|
51
|
+ path: |
|
|
|
52
|
+ myapp-${{ matrix.goos }}-${{ matrix.goarch }}
|
|
|
53
|
+ myapp-alpine-${{ matrix.goos }}-${{ matrix.goarch }}
|