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