Skip to content

Commit e462c42

Browse files
[CI] Add OBS cache for pre-commit hooks (vllm-project#12857)
## What this PR does / why we need it? Add OBS-based caching for pre-commit hooks to speed up PR CI. ### Changes: 1. **Add push_build_precommit_cache.yaml** (new file): - Triggers on push to main when .pre-commit-config.yaml or equirements-lint.txt changes - Runs pre-commit to populate the cache, then uploads to OBS (^Gscend-ci-cache-hk bucket) - Uses sha256sum for cache key (not hashFiles() which returns empty on self-hosted runners) - Uses /tmp/pre-commit-cache (ephemeral) instead of ~/.cache/pre-commit (PVC) to ensure cache comes from OBS, not local disk residue - Requires secrets HW_OBS_AK_HK and HW_OBS_SK_HK to be configured in repository settings 2. **Modify pr_test.yaml**: - Add uns-on/cache/restore@v5 step before "Run pre-commit" to restore cache from OBS - Fork PRs can read the cache using the runner's built-in read-only AK/SK (no secrets needed) - Same PRE_COMMIT_HOME: /tmp/pre-commit-cache path ### Principle: - **Write cache**: only on main branch (push trigger), using GitHub secrets for write credentials - **Read cache**: all PRs (including fork PRs), using runner's built-in read-only AK/SK ### Prerequisites: - Configure HW_OBS_AK_HK and HW_OBS_SK_HK secrets in repository settings (Actions → Secrets) - Ensure runners have obs-cache-credentials secret in their pod template for read-only access ## Does this PR introduce any user-facing change? No. ## How was this patch tested? Verified on ^Gscend-gha-runners/vllm-ascend fork — cache write and read both confirmed working. - vLLM version: v0.25.1 - vLLM main: vllm-project/vllm@fe784ff --------- Signed-off-by: ZhangYang <1079854335@qq.com>
1 parent 2a607f0 commit e462c42

2 files changed

Lines changed: 114 additions & 1 deletion

File tree

.github/workflows/pr_test.yaml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,25 @@ jobs:
145145
git config --global --add safe.directory "$GITHUB_WORKSPACE"
146146
chmod +x .github/workflows/scripts/gitleaks.sh
147147
.github/workflows/scripts/gitleaks.sh
148-
148+
149+
- name: Get pre-commit config hash
150+
id: get_hash
151+
run: |
152+
PRE_COMMIT_HASH=$(sha256sum .pre-commit-config.yaml | awk '{print $1}')
153+
echo "PRE_COMMIT_HASH=$PRE_COMMIT_HASH" >> $GITHUB_OUTPUT
154+
155+
- name: Restore pre-commit cache
156+
uses: runs-on/cache/restore@v5
157+
env:
158+
RUNS_ON_S3_BUCKET_CACHE: ascend-ci-cache-hk
159+
RUNS_ON_S3_BUCKET_ENDPOINT: https://obs.ap-southeast-1.myhuaweicloud.com
160+
RUNS_ON_S3_FORCE_PATH_STYLE: "false"
161+
AWS_S3_FORCE_PATH_STYLE: "false"
162+
AWS_REGION: ap-southeast-1
163+
with:
164+
path: /tmp/pre-commit-cache
165+
key: pre-commit-${{ steps.get_hash.outputs.PRE_COMMIT_HASH }}
166+
149167
- name: Run pre-commit
150168
env:
151169
PRE_COMMIT_HOME: /tmp/pre-commit-cache
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#
2+
# Copyright (c) 2026 Huawei Technologies Co., Ltd. All Rights Reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
# This file is a part of the vllm-ascend project.
16+
#
17+
18+
# This workflow populates the pre-commit cache in OBS on push to main.
19+
# Fork PRs can then restore this cache read-only using the runner's built-in AK/SK.
20+
name: 'Cache pre-commit'
21+
on:
22+
push:
23+
branches: ["main"]
24+
paths:
25+
- '.pre-commit-config.yaml'
26+
- 'requirements-lint.txt'
27+
workflow_dispatch:
28+
29+
permissions:
30+
contents: read
31+
32+
defaults:
33+
run:
34+
shell: bash -el {0}
35+
36+
concurrency:
37+
group: precommit-cache-${{ github.ref }}
38+
cancel-in-progress: true
39+
40+
jobs:
41+
build-cache:
42+
runs-on: linux-amd64-cpu-8-hk
43+
container:
44+
image: quay.io/ascend-ci/vllm-ascend:lint
45+
env:
46+
RUNS_ON_S3_BUCKET_CACHE: ascend-ci-cache-hk
47+
RUNS_ON_S3_BUCKET_ENDPOINT: https://obs.ap-southeast-1.myhuaweicloud.com
48+
RUNS_ON_S3_FORCE_PATH_STYLE: "false"
49+
AWS_S3_FORCE_PATH_STYLE: "false"
50+
AWS_REGION: ap-southeast-1
51+
RUNS_ON_RUNNER_NAME: ""
52+
AWS_ACCESS_KEY_ID: ${{ secrets.HW_OBS_AK }}
53+
AWS_SECRET_ACCESS_KEY: ${{ secrets.HW_OBS_SK }}
54+
steps:
55+
- name: Checkout vllm-project/vllm-ascend repo
56+
uses: actions/checkout@v7
57+
with:
58+
fetch-depth: 0
59+
60+
- name: Get pre-commit config hash
61+
id: get_hash
62+
run: |
63+
PRE_COMMIT_HASH=$(sha256sum .pre-commit-config.yaml | awk '{print $1}')
64+
echo "PRE_COMMIT_HASH=$PRE_COMMIT_HASH" >> $GITHUB_OUTPUT
65+
66+
- name: Check if cache exists
67+
id: check-cache
68+
uses: runs-on/cache/restore@v5
69+
with:
70+
path: /tmp/pre-commit-cache
71+
key: pre-commit-${{ steps.get_hash.outputs.PRE_COMMIT_HASH }}
72+
lookup-only: true
73+
74+
- name: Clean stale pre-commit cache
75+
if: steps.check-cache.outputs.cache-hit != 'true'
76+
run: rm -rf /tmp/pre-commit-cache
77+
78+
- name: Run pre-commit (populate cache)
79+
if: steps.check-cache.outputs.cache-hit != 'true'
80+
env:
81+
PRE_COMMIT_HOME: /tmp/pre-commit-cache
82+
PRE_COMMIT_COLOR: always
83+
FORCE_COLOR: "1"
84+
TERM: xterm-256color
85+
SHELLCHECK_OPTS: "--exclude=SC2046,SC2006,SC2086"
86+
run: |
87+
git config --global --add safe.directory /__w/vllm-ascend/vllm-ascend
88+
pre-commit run --all-files --hook-stage manual --show-diff-on-failure
89+
90+
- name: Save pre-commit cache
91+
if: always() && steps.check-cache.outputs.cache-hit != 'true'
92+
uses: runs-on/cache/save@v5
93+
with:
94+
path: /tmp/pre-commit-cache
95+
key: pre-commit-${{ steps.get_hash.outputs.PRE_COMMIT_HASH }}

0 commit comments

Comments
 (0)