diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index cac7996..1bf4eeb 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -19,7 +19,12 @@ permissions: contents: read jobs: + # 预热 Go 依赖缓存 + go-cache: + uses: ./.github/workflows/go-cache.yaml + build-web: + needs: go-cache runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -44,7 +49,7 @@ jobs: cache: yarn cache-dependency-path: 'src/webapp/yarn.lock' - - uses: actions/setup-go@v5 + - uses: actions/setup-go@v6 if: ${{ steps.cache_web_build.outputs.cache-hit != 'true' && github.event.inputs.is_force != 'true' }} with: go-version: '1.25' diff --git a/.github/workflows/go-cache.yaml b/.github/workflows/go-cache.yaml new file mode 100644 index 0000000..a1cec6e --- /dev/null +++ b/.github/workflows/go-cache.yaml @@ -0,0 +1,35 @@ +# Go 依赖缓存预热 +# 确保 setup-go 的内置缓存包含所有 Go 模块依赖 +# 其他 workflow 通过 workflow_call 调用此 workflow 作为前置 job +name: Go Cache +on: + # 允许其他 workflow 调用(reusable workflow) + workflow_call: + # go.mod/go.sum 变更时自动预热 + push: + branches: + - '*' + paths: + - 'go.mod' + - 'go.sum' + # 支持手动触发(强制刷新缓存) + workflow_dispatch: + +permissions: + contents: read + +jobs: + warmup: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-go@v6 + with: + go-version: '1.25' + cache: true + cache-dependency-path: '**/go.sum' + + # 显式下载所有依赖,确保 setup-go 的 post step 保存的缓存是完整的 + - name: Download all Go modules + run: go mod download diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index dbbe189..0a13da7 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -22,7 +22,12 @@ env: IS_DRY_RUN: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.dry_run == 'true' }} jobs: + # 预热 Go 依赖缓存 + go-cache: + uses: ./.github/workflows/go-cache.yaml + release-bins-sharded: + needs: go-cache runs-on: ubuntu-latest permissions: contents: read @@ -47,7 +52,7 @@ jobs: else echo "GIT_TAG=`echo $(git describe --tags --abbrev=0)`" >> $GITHUB_ENV fi - - uses: actions/setup-go@v5 + - uses: actions/setup-go@v6 with: go-version: '1.25' cache: true diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 01916bb..5949707 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -7,13 +7,18 @@ on: branches: - '*' jobs: + # 预热 Go 依赖缓存(调用 reusable workflow) + go-cache: + uses: ./.github/workflows/go-cache.yaml + build: + needs: go-cache runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Set up Go - uses: actions/setup-go@v5 + uses: actions/setup-go@v6 with: go-version: '1.25' cache: true @@ -25,12 +30,13 @@ jobs: - name: Build run: make build-web bililive test: + needs: go-cache runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Set up Go - uses: actions/setup-go@v5 + uses: actions/setup-go@v6 with: go-version: '1.25' cache: true @@ -45,6 +51,7 @@ jobs: uses: codecov/codecov-action@v2 lint: name: Lint + needs: go-cache runs-on: ubuntu-latest if: github.event_name == 'pull_request' timeout-minutes: 3 @@ -53,7 +60,7 @@ jobs: with: fetch-depth: 1 - name: Setup Go - uses: actions/setup-go@v5 + uses: actions/setup-go@v6 with: go-version: '1.25' cache: true @@ -64,14 +71,15 @@ jobs: args: --build-tags=dev check-agents: name: Check AI Instruction Files + needs: go-cache runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Setup Go - uses: actions/setup-go@v5 + uses: actions/setup-go@v6 with: go-version: '1.25' cache: true cache-dependency-path: '**/go.sum' - name: Check AI instruction files consistency - run: make check-agents \ No newline at end of file + run: make check-agents diff --git a/src/cmd/build/build_go_binary.go b/src/cmd/build/build_go_binary.go index 7236797..5e50cc9 100644 --- a/src/cmd/build/build_go_binary.go +++ b/src/cmd/build/build_go_binary.go @@ -138,7 +138,8 @@ func BuildGoBinaryWithOutput(isDev bool, outputPath string) { log.Print(cmd.String()) err := cmd.Run() if err != nil { - fmt.Printf("Command finished with error: %v", err) + fmt.Printf("Command finished with error: %v\n", err) + os.Exit(1) } } diff --git a/src/hack/release.sh b/src/hack/release.sh index 27f7fb6..4c3f06d 100755 --- a/src/hack/release.sh +++ b/src/hack/release.sh @@ -46,8 +46,35 @@ if [ "$SHARD_INDEX" -ge "$SHARD_TOTAL" ]; then SHARD_INDEX=$((SHARD_INDEX % SHAR echo "[deps] Warming Go module cache..." go mod download >/dev/null 2>&1 || true -# 生成目标列表并过滤不支持的目标 -TARGETS=$(go tool dist list | awk '!/^(linux\/loong64|android\/|ios\/|js\/wasm)/') +# 明确支持的目标平台列表(白名单) +# 避免使用 go tool dist list 全量列表,因为很多冷门平台的第三方库(如 modernc.org/sqlite、gopsutil)不支持 +TARGETS=" +linux/amd64 +linux/arm64 +linux/arm +linux/386 +linux/mips +linux/mips64 +linux/mips64le +linux/mipsle +linux/ppc64 +linux/ppc64le +linux/riscv64 +linux/s390x +darwin/amd64 +darwin/arm64 +windows/amd64 +windows/arm64 +windows/386 +freebsd/amd64 +freebsd/arm64 +openbsd/amd64 +openbsd/arm64 +netbsd/amd64 +netbsd/arm64 +" +# 去除空行 +TARGETS=$(echo "$TARGETS" | sed '/^$/d') echo "[shard] TOTAL=${SHARD_TOTAL} INDEX=${SHARD_INDEX}" i=0