Skip to content

Commit e7af7e7

Browse files
author
cyk
committed
perf: optimize CI build speed with smart caching
- Add Go module cache - Add frontend download cache with commit SHA tracking - Add Docker layer cache (registry-based) - Cache will invalidate when frontend repo updates
1 parent 5aa3881 commit e7af7e7

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

.github/workflows/test_docker.yml

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,31 @@ jobs:
3535
steps:
3636
- name: Checkout
3737
uses: actions/checkout@v4
38-
- uses: actions/setup-go@v5
38+
39+
- name: Setup Go
40+
uses: actions/setup-go@v5
3941
with:
4042
go-version: '1.25.0'
43+
cache: true
44+
cache-dependency-path: go.sum
45+
46+
# 获取前端仓库的最新commit SHA
47+
- name: Get Frontend Commit SHA
48+
id: frontend-sha
49+
run: |
50+
FRONTEND_SHA=$(curl -s https://api.github.com/repos/${{ env.FRONTEND_REPO }}/commits/main | jq -r '.sha')
51+
echo "sha=$FRONTEND_SHA" >> $GITHUB_OUTPUT
52+
echo "Frontend repo latest commit: $FRONTEND_SHA"
53+
54+
# 缓存前端下载 - key包含前端仓库的commit SHA
55+
- name: Cache Frontend
56+
id: cache-frontend
57+
uses: actions/cache@v4
58+
with:
59+
path: public/dist
60+
key: frontend-${{ env.FRONTEND_REPO }}-${{ steps.frontend-sha.outputs.sha }}
61+
restore-keys: |
62+
frontend-${{ env.FRONTEND_REPO }}-
4163
4264
# 即使只构建 x64,我们也需要 musl 工具链(因为 BuildDockerMultiplatform 默认会检查它)
4365
- name: Cache Musl
@@ -46,6 +68,7 @@ jobs:
4668
with:
4769
path: build/musl-libs
4870
key: docker-musl-libs-v2
71+
4972
- name: Download Musl Library
5073
if: steps.cache-musl.outputs.cache-hit != 'true'
5174
run: bash build.sh prepare docker-multiplatform
@@ -57,7 +80,7 @@ jobs:
5780
run: bash build.sh beta docker-multiplatform
5881
env:
5982
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
60-
FRONTEND_REPO: ${{ vars.FRONTEND_REPO }}
83+
FRONTEND_REPO: ${{ env.FRONTEND_REPO }}
6184

6285
- name: Upload artifacts
6386
uses: actions/upload-artifact@v4
@@ -77,7 +100,7 @@ jobs:
77100
packages: write
78101
strategy:
79102
matrix:
80-
# 你可以选择只构建 latest,或者保留全部变体
103+
# 构建所有变体
81104
image: ["latest", "ffmpeg", "aria2", "aio"]
82105
include:
83106
- image: "latest"
@@ -137,3 +160,5 @@ jobs:
137160
tags: ${{ steps.meta.outputs.tags }}
138161
labels: ${{ steps.meta.outputs.labels }}
139162
platforms: ${{ env.RELEASE_PLATFORMS }}
163+
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.GHCR_ORG_NAME }}/${{ env.IMAGE_NAME }}:buildcache-${{ matrix.image }}
164+
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.GHCR_ORG_NAME }}/${{ env.IMAGE_NAME }}:buildcache-${{ matrix.image }},mode=max

0 commit comments

Comments
 (0)