From 37b330c4d6100b0a6d8767ecd9df02b1e8b4d263 Mon Sep 17 00:00:00 2001 From: coolxitech Date: Sun, 14 Dec 2025 12:46:12 +0800 Subject: [PATCH] =?UTF-8?q?chore(workflow):=20=E4=BC=98=E5=8C=96=E6=9E=84?= =?UTF-8?q?=E5=BB=BA=E4=B8=8E=E5=8F=91=E5=B8=83=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 统一上传步骤命名,增强可读性 - 精确指定上传文件后缀,避免多余目录或文件被上传 - 合并下载与上传步骤,简化 release 流程 - 移除冗余的权限声明与注释 - 修复 release assets 路径引用问题 --- .github/workflows/build.yml | 64 +++++++++++++------------------------ 1 file changed, 23 insertions(+), 41 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 27a6f2f..d2cfe4d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -35,14 +35,15 @@ jobs: - uses: actions/setup-go@v5 with: go-version: '1.21' + - name: Build Frontend & Server run: | pnpm install pnpm run build - [ -f go.mod ] || go mod init ogame-app go mod tidy GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -ldflags="-s -w" -o ${{ matrix.executable }} main.go - - name: Upload + + - name: Upload Server Binaries uses: actions/upload-artifact@v4 with: name: server-${{ matrix.goos }}-${{ matrix.goarch }} @@ -72,6 +73,7 @@ jobs: with: node-version: 20 cache: 'pnpm' + - name: Build Electron run: | pnpm install @@ -79,11 +81,12 @@ jobs: pnpm run build:electron --${{ matrix.platform }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Upload + + # 【关键点】这里只上传安装包后缀,不上传文件夹 + - name: Upload Electron Installers uses: actions/upload-artifact@v4 with: name: electron-${{ matrix.platform }} - # 仅上传 pkg 下的安装包,忽略 unpacked 目录 path: | pkg/*.exe pkg/*.dmg @@ -92,56 +95,35 @@ jobs: # 3. 发布 Release release: - needs: [ build-server, build-electron ] + needs: [build-server, build-electron] runs-on: ubuntu-latest permissions: - contents: write # 必须确保有写权限 - pull-requests: read + contents: write steps: - uses: actions/checkout@v4 - # 1. 获取版本号 - name: Get Version id: get_version - shell: bash - run: | - VERSION=$(node -p "require('./package.json').version") - echo "VERSION=v$VERSION" >> $GITHUB_OUTPUT + run: echo "VERSION=v$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT + + - name: Download All Artifacts + uses: actions/download-artifact@v4 + with: + path: ./release-assets + merge-multiple: true - # 2. 创建 Release (先创建,不上传文件) - # 这一步能有效避免 404,确保 Release 实体已存在 - name: Create GitHub Release - id: create_release uses: softprops/action-gh-release@v1 with: tag_name: ${{ steps.get_version.outputs.VERSION }} name: Release ${{ steps.get_version.outputs.VERSION }} - draft: false - prerelease: false + # 【核心修复】精确指定文件后缀,避免上传 package.json 或 unpacked 目录 + files: | + ./release-assets/*.exe + ./release-assets/*.dmg + ./release-assets/*.AppImage + ./release-assets/*.zip + ./release-assets/ogame-server-* generate_release_notes: true - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - # 3. 下载产物并上传到已创建的 Release - - name: Download and Upload Assets - uses: actions/download-artifact@v4 - with: - path: ./downloads - merge-multiple: true - - - name: Upload Assets to Release - uses: softprops/action-gh-release@v1 - with: - tag_name: ${{ steps.get_version.outputs.VERSION }} - append_body: true - # 显式指定文件名,不带版本号 - files: | - ./downloads/ogame-server-win.exe - ./downloads/ogame-server-linux - ./downloads/ogame-server-linux-arm64 - ./downloads/ogame-Setup.exe - ./downloads/*.dmg - ./downloads/*.AppImage - ./downloads/*.zip env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file