ljw 1 год назад
Родитель
Сommit
4ec08cf03a
1 измененных файлов с 16 добавлено и 25 удалено
  1. 16 25
      .github/workflows/test.yml

+ 16 - 25
.github/workflows/test.yml

@@ -5,55 +5,46 @@ name: Go Build and Release
5
 #    tags:
5
 #    tags:
6
 #      - 'v*.*.*'  # 当推送带有版本号的 tag(例如 v1.0.0)时触发工作流
6
 #      - 'v*.*.*'  # 当推送带有版本号的 tag(例如 v1.0.0)时触发工作流
7
 on:
7
 on:
8
-#  push:
9
-#    branches: [ "master" ]
8
+  push:
9
+    branches: [ "master" ]
10
   pull_request:
10
   pull_request:
11
     branches: [ "master" ]
11
     branches: [ "master" ]
12
-    
12
+
13
 jobs:
13
 jobs:
14
   build:
14
   build:
15
     runs-on: ubuntu-latest
15
     runs-on: ubuntu-latest
16
 
16
 
17
     strategy:
17
     strategy:
18
       matrix:
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
     steps:
22
     steps:
24
       - name: Checkout code
23
       - name: Checkout code
25
-        uses: actions/checkout@v3
24
+        uses: actions/checkout@v4
26
 
25
 
27
       - name: Set up Go environment
26
       - name: Set up Go environment
28
         uses: actions/setup-go@v4
27
         uses: actions/setup-go@v4
29
         with:
28
         with:
30
           go-version: '1.22'  # 选择 Go 版本
29
           go-version: '1.22'  # 选择 Go 版本
30
+      - name: install gcc
31
+        run: sudo apt-get install gcc-mingw-w64-x86-64
32
+
31
       - name: tidy
33
       - name: tidy
32
         run: go mod tidy
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
         run: |
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
           else
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
           fi
42
           fi
52
 
43
 
53
       - name: Upload artifact
44
       - name: Upload artifact
54
         uses: actions/upload-artifact@v3
45
         uses: actions/upload-artifact@v3
55
         with:
46
         with:
56
-          name: myapp-${{ matrix.goos }}-${{ matrix.goarch }}-${{ matrix.go_variant }}
47
+          name: myapp-${{ matrix.goos }}-${{ matrix.goarch }}
57
           path: |
48
           path: |
58
-            myapp-${{ matrix.goos }}-${{ matrix.goarch }}
59
-            myapp-alpine-${{ matrix.goos }}-${{ matrix.goarch }}
49
+            release/apimain
50
+            release/apimain.exe