Skip to content

优化 Github Actions 构建速度#4745

Merged
Glavo merged 20 commits into
HMCL-dev:mainfrom
CiiLu:gh-actions
Nov 8, 2025
Merged

优化 Github Actions 构建速度#4745
Glavo merged 20 commits into
HMCL-dev:mainfrom
CiiLu:gh-actions

Conversation

@CiiLu
Copy link
Copy Markdown
Contributor

@CiiLu CiiLu commented Nov 2, 2025

Java CI 约 2m -> 30s ~50s
CheckCodes 约 2m -> 30s ~ 1m

Comment thread .github/workflows/gradle.yml Outdated
path: |
HMCL/build/libs/HMCL-*.sh
HMCL/build/libs/HMCL-*.sh.sha256 No newline at end of file
- uses: actions/checkout@v4
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要修改文件的缩进。

Comment thread gradle.properties Outdated
@@ -0,0 +1,2 @@
org.gradle.caching=true
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要开启增量编译。

Comment thread .github/workflows/gradle.yml Outdated
uses: gradle/actions/setup-gradle@v5
with:
cache-cleanup: never
cache-read-only: false
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为什么要无条件关闭 cache-read-only

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

默认只会在主分支上写入缓存,就无法在本分支的 actions 上看到效果了,合并到主分支后就可以删除了(目前已经写入了一些缓存所以删掉也不影响了)

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v5
with:
cache-cleanup: never
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为什么要设置成 never

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果不设置为 never 会在 Post Setup Gradle 任务处花费 30 秒左右整理缓存,HMCL 项目的缓存不大,且一周内未访问的缓存会被 Github 自动清理,到达 10GB 限制也会自动清理

A repository can have up to 10GB of caches. Once the 10GB limit is reached, older caches will be evicted based on when the cache was last accessed. Caches that are not accessed within the last week will also be evicted.

Comment thread .github/workflows/check-codes.yml Outdated
Comment thread .github/workflows/gradle.yml Outdated
cache-cleanup: never
- name: Build with Gradle
run: ./gradlew build --no-daemon
run: ./gradlew build --no-daemon --build-cache --parallel
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要启用 --build-cache

@Glavo Glavo merged commit f4c6a4f into HMCL-dev:main Nov 8, 2025
1 check passed
@CiiLu CiiLu deleted the gh-actions branch January 1, 2026 10:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants