浏览代码

添加Windows构建和测试流程

增加了针对Windows平台的测试和构建任务,确保项目在不同操作系统上都能正确编译和运行。同时调整了创建发布版本的步骤,以包含Windows构建产物。
SongZihuan 1 周之前
父节点
当前提交
8d2d281502
共有 1 个文件被更改,包括 77 次插入7 次删除
  1. 77 7
      .github/workflows/go-tag-release.yml

+ 77 - 7
.github/workflows/go-tag-release.yml

@@ -18,7 +18,7 @@ on:
       - master
 
 jobs:
-  test:
+  test-ubuntu:
     runs-on: ubuntu-latest
     steps:
       - name: Checkout code
@@ -38,10 +38,30 @@ jobs:
       - name: Test
         run: GOOS=linux GOARCH=amd64 go test ./...
 
-  build:
+  test-windows:
+    runs-on: windows-latest
+    steps:
+      - name: Checkout code
+        uses: actions/checkout@v4
+
+      - name: Set up Go
+        uses: actions/setup-go@v5
+        with:
+          go-version: '1.23.4' # 根据需要指定Go版本
+
+      - name: Download module
+        run: GOOS=windows GOARCH=amd64 go mod tidy
+
+      - name: Go generate
+        run: GOOS=windows GOARCH=amd64 go generate ./...
+
+      - name: Test
+        run: GOOS=windows GOARCH=amd64 go test ./...
+
+  build-ubuntu:
     runs-on: ubuntu-latest
     needs:
-      - test
+      - test-ubuntu
 
     steps:
       - name: Checkout code
@@ -74,17 +94,61 @@ jobs:
         run: |
           ls -l "${{ github.workspace }}/output"
 
-      - name: Upload artifact
+      - name: Upload ubuntu artifact
         uses: actions/upload-artifact@v4
         with:
           name: linux_amd64_executable_files
           path: "${{ github.workspace }}/output/"
           if-no-files-found: error
 
+  build-windows:
+    runs-on: windows-latest
+    needs:
+      - test-windows
+
+    steps:
+      - name: Checkout code
+        uses: actions/checkout@v4
+
+      - name: Set up Go
+        uses: actions/setup-go@v5
+        with:
+          go-version: '1.23.4' # 根据需要指定Go版本
+
+      - name: Download module
+        run: GOOS=windows GOARCH=amd64 go mod tidy
+
+      - name: Go generate
+        run: GOOS=windows GOARCH=amd64 go generate ./...
+
+      - name: Build lionv1
+        run: |
+          GOOS=windows GOARCH=amd64 go build -o "${{ github.workspace }}/output/windows_amd64_lionv1.exe" -trimpath -ldflags='-s -w -extldflags "-static"' github.com/SongZihuan/BackendServerTemplate/src/cmd/lionv1
+
+      - name: Build tigerv1
+        run: |
+          GOOS=windows GOARCH=amd64 go build -o "${{ github.workspace }}/output/windows_amd64_tigerv1.exe" -trimpath -ldflags='-s -w -extldflags "-static"' github.com/SongZihuan/BackendServerTemplate/src/cmd/tigerv1
+
+      - name: Build catv1
+        run: |
+          GOOS=windows GOARCH=amd64 go build -o "${{ github.workspace }}/output/windows_amd64_catv1.exe" -trimpath -ldflags='-s -w -extldflags "-static"' github.com/SongZihuan/BackendServerTemplate/src/cmd/catv1
+
+      - name: List build directory
+        run: |
+          ls -l "${{ github.workspace }}/output"
+
+      - name: Upload windows artifact
+        uses: actions/upload-artifact@v4
+        with:
+          name: windows_amd64_executable_files
+          path: "${{ github.workspace }}/output/"
+          if-no-files-found: error
+
   create_release:
     runs-on: ubuntu-latest
     needs:
-      - build
+      - build-ubuntu
+      - build-windows
     if: startsWith(github.ref, 'refs/tags/')
 
     steps:
@@ -100,12 +164,18 @@ jobs:
           TAG_NAME=$(echo "${GITHUB_REF}" | sed 's/refs\/tags\///')
           echo "tag=${TAG_NAME}" >> $GITHUB_OUTPUT
 
-      - name: Download artifact
+      - name: Download ubuntu artifact
         uses: actions/download-artifact@v4
         with:
           name: linux_amd64_executable_files
           path: ${{ github.workspace }}/output
 
+      - name: Download windows artifact
+        uses: actions/download-artifact@v4
+        with:
+          name: windows_amd64_executable_files
+          path: ${{ github.workspace }}/output
+
       - name: List directory
         run: ls -l ${{ github.workspace }}/output
 
@@ -113,7 +183,7 @@ jobs:
         id: create_release
         uses: ncipollo/release-action@v1
         with:
-          artifacts: "${{ github.workspace }}/output/linux_amd64_lionv1,${{ github.workspace }}/output/linux_amd64_tigerv1,${{ github.workspace }}/output/linux_amd64_catv1"
+          artifacts: "${{ github.workspace }}/output/linux_amd64_lionv1,${{ github.workspace }}/output/linux_amd64_tigerv1,${{ github.workspace }}/output/linux_amd64_catv1,${{ github.workspace }}/output/windows_amd64_lionv1.exe,${{ github.workspace }}/output/windows_amd64_tigerv1.exe,${{ github.workspace }}/output/windows_amd64_catv1.exe"
           artifactErrorsFailBuild: true
           allowUpdates: false
           body: |