Skip to content

Commit 696bd99

Browse files
authored
ci: cache pre-commit environments (NVIDIA#58)
#### Overview Add CI caching for pre-commit hook environments and update local hooks to use managed pre-commit language environments where applicable. This should reduce repeated hook bootstrap cost in GitHub Actions while keeping cache invalidation tied to the hook config and CI tool versions. - [x] I confirm this contribution is my own work, or I have the right to submit it under this project's license. - [x] I searched existing issues and open pull requests, and this does not duplicate existing work. #### Details - Set `PRE_COMMIT_HOME` in the reusable Check workflow and cache it with pinned `actions/cache`. - Key the pre-commit cache by runner OS/arch, CI Python/Node/Rust versions, pre-commit version, and `.pre-commit-config.yaml`. - Convert local hooks from `system` to the matching managed `python`, `rust`, and `node` pre-commit languages so their environments can be reused. #### Where should the reviewer start? Start with `.github/workflows/ci_check.yml` for the cache behavior, then review `.pre-commit-config.yaml` for the hook language changes that make the cache useful. #### Related Issues: (use one of the action keywords Closes / Fixes / Resolves / Relates to) - Relates to: none Signed-off-by: Will Killian <wkillian@nvidia.com>
1 parent 7645295 commit 696bd99

3 files changed

Lines changed: 17 additions & 1 deletion

File tree

.github/actions/load-ci-tool-versions/action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ outputs:
2020
uv_version:
2121
description: uv version
2222
value: ${{ steps.load.outputs.uv_version }}
23+
pre_commit_version:
24+
description: pre-commit version
25+
value: ${{ steps.load.outputs.pre_commit_version }}
2326
just_version:
2427
description: just version
2528
value: ${{ steps.load.outputs.just_version }}
@@ -55,6 +58,7 @@ runs:
5558
NEMO_FLOW_CI_RUST_VERSION
5659
NEMO_FLOW_CI_NODE_VERSION
5760
NEMO_FLOW_CI_UV_VERSION
61+
NEMO_FLOW_CI_PRE_COMMIT_VERSION
5862
NEMO_FLOW_CI_JUST_VERSION
5963
NEMO_FLOW_CI_WASM_PACK_VERSION
6064
NEMO_FLOW_CI_CARGO_LLVM_COV_VERSION
@@ -76,6 +80,7 @@ runs:
7680
printf 'rust_version=%s\n' "$NEMO_FLOW_CI_RUST_VERSION"
7781
printf 'node_version=%s\n' "$NEMO_FLOW_CI_NODE_VERSION"
7882
printf 'uv_version=%s\n' "$NEMO_FLOW_CI_UV_VERSION"
83+
printf 'pre_commit_version=%s\n' "$NEMO_FLOW_CI_PRE_COMMIT_VERSION"
7984
printf 'just_version=%s\n' "$NEMO_FLOW_CI_JUST_VERSION"
8085
printf 'wasm_pack_version=%s\n' "$NEMO_FLOW_CI_WASM_PACK_VERSION"
8186
printf 'cargo_llvm_cov_version=%s\n' "$NEMO_FLOW_CI_CARGO_LLVM_COV_VERSION"

.github/ci-tool-versions.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ NEMO_FLOW_CI_DEFAULT_PYTHON_VER=3.11
66
NEMO_FLOW_CI_RUST_VERSION=1.93.0
77
NEMO_FLOW_CI_NODE_VERSION=24
88
NEMO_FLOW_CI_UV_VERSION=0.9.28
9+
NEMO_FLOW_CI_PRE_COMMIT_VERSION=4.5
910
NEMO_FLOW_CI_JUST_VERSION=1.47.1
1011
NEMO_FLOW_CI_WASM_PACK_VERSION=0.14.0
1112
NEMO_FLOW_CI_CARGO_LLVM_COV_VERSION=0.8.5

.github/workflows/ci_check.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,26 @@ jobs:
8989
with:
9090
tool: cargo-about@${{ steps.ci-config.outputs.cargo_about_version }}
9191

92+
- name: Cache pre-commit environments
93+
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
94+
with:
95+
path: ${{ runner.temp }}/.cache/pre-commit
96+
key: >-
97+
nemo-flow-pre-commit-${{ runner.os }}-${{ runner.arch }}-py${{ steps.ci-config.outputs.default_python_version }}-node${{ steps.ci-config.outputs.node_version }}-rust${{ steps.ci-config.outputs.rust_version }}-pc${{ steps.ci-config.outputs.pre_commit_version }}-${{ hashFiles('.pre-commit-config.yaml') }}
98+
restore-keys: |
99+
nemo-flow-pre-commit-${{ runner.os }}-${{ runner.arch }}-py${{ steps.ci-config.outputs.default_python_version }}-node${{ steps.ci-config.outputs.node_version }}-rust${{ steps.ci-config.outputs.rust_version }}-pc${{ steps.ci-config.outputs.pre_commit_version }}-
100+
92101
- name: pre-commit
93102
working-directory: ${{ env.NEMO_FLOW_CI_WORKSPACE }}
94103
env:
95104
FULL_CI: ${{ inputs.full_ci }}
96105
PRE_COMMIT_BASE: ${{ inputs.base }}
106+
PRE_COMMIT_HOME: ${{ runner.temp }}/.cache/pre-commit
97107
# The attribution hook syncs docs deps; do not apply repo warning policy to third-party Rust builds.
98108
RUSTFLAGS: ""
99109
run: |
100110
set -e
101-
uv tool install pre-commit==4.5
111+
uv tool install pre-commit==${{ steps.ci-config.outputs.pre_commit_version }}
102112
if [[ "$FULL_CI" == "true" || -z "$PRE_COMMIT_BASE" ]]; then
103113
pre-commit run --all-files --show-diff-on-failure
104114
else

0 commit comments

Comments
 (0)