Skip to content

Commit 6f5f0d4

Browse files
committed
tools: only save lint caches on push
Assisted-by: Codex Signed-off-by: inoway46 <[email protected]>
1 parent 04904eb commit 6f5f0d4

1 file changed

Lines changed: 28 additions & 7 deletions

File tree

‎.github/workflows/linters.yml‎

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,21 @@ jobs:
9797
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
9898
with:
9999
node-version: ${{ env.NODE_VERSION }}
100-
cache: npm
101-
cache-dependency-path: |
102-
tools/doc/package-lock.json
103-
tools/eslint/package-lock.json
104-
tools/lint-md/package-lock.json
105-
- name: Cache ESLint results
106-
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
100+
package-manager-cache: false
101+
- name: Get npm cache directory
102+
id: npm-cache-dir
103+
run: |
104+
echo "path=$(npm config get cache)" >> "$GITHUB_OUTPUT"
105+
echo "arch=$(node -p 'process.arch')" >> "$GITHUB_OUTPUT"
106+
- name: Restore npm cache
107+
id: npm-cache
108+
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
109+
with:
110+
path: ${{ steps.npm-cache-dir.outputs.path }}
111+
key: node-cache-${{ runner.os }}-${{ steps.npm-cache-dir.outputs.arch }}-npm-${{ hashFiles('tools/doc/package-lock.json', 'tools/eslint/package-lock.json', 'tools/lint-md/package-lock.json') }}
112+
- name: Restore ESLint results
113+
id: eslint-cache
114+
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
107115
env:
108116
# ESLint only invalidates its cache on config changes, so the key also
109117
# covers the custom rules and the files they read.
@@ -148,6 +156,19 @@ jobs:
148156
NODE=$(command -v node) make lint-md ESLINT_CACHE_FLAGS='--cache --cache-strategy content'
149157
env:
150158
NODE_RELEASED_VERSIONS: ${{ steps.get-released-versions.outputs.NODE_RELEASED_VERSIONS }}
159+
# PRs can restore base branch caches, but only trusted pushes populate them.
160+
- name: Save npm cache
161+
if: github.event_name == 'push' && steps.npm-cache.outputs.cache-hit != 'true'
162+
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
163+
with:
164+
path: ${{ steps.npm-cache-dir.outputs.path }}
165+
key: ${{ steps.npm-cache.outputs.cache-primary-key }}
166+
- name: Save ESLint results
167+
if: github.event_name == 'push' && steps.eslint-cache.outputs.cache-hit != 'true'
168+
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
169+
with:
170+
path: .eslintcache
171+
key: ${{ steps.eslint-cache.outputs.cache-primary-key }}
151172

152173
lint-py:
153174
if: github.event.pull_request.draft == false

0 commit comments

Comments
 (0)