优化CI缓存

This commit is contained in:
kira1928 committed 2026-03-11 00:50:50 +09:00
1 parent 55e6a73a9d
commit 93cd3eef7b
6 files changed
+93 -12

No files matched your search

+6 -1
View File
@@ -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'
+35
View File
@@ -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
+6 -1
View File
@@ -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
+15 -7
View File
@@ -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
run: make check-agents
+2 -1
View File
@@ -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)
}
}
+29 -2
View File
@@ -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