Skip to content

Commit ed8a13a

Browse files
committed
enable caching by default
1 parent cf9eb85 commit ed8a13a

File tree

1 file changed

+37
-5
lines changed

1 file changed

+37
-5
lines changed

action.yml

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ inputs:
216216
use the number of all available CPU cores.
217217
required: false
218218
default: 0
219+
cache:
220+
description: enable caching of cpp-linter dependencies
221+
required: false
222+
default: true
219223
outputs:
220224
checks-failed:
221225
description: An integer that can be used as a boolean value to indicate if any checks failed by clang-tidy and clang-format.
@@ -244,6 +248,37 @@ runs:
244248
fi
245249
fi
246250
251+
- name: Setup nu shell
252+
# I'm done writing everything twice (in bash and powershell)
253+
# With nu shell, we use the same shell/script for all platforms
254+
uses: hustcer/setup-nu@v3
255+
with:
256+
version: '0.106.1'
257+
258+
- name: Compute cache key
259+
if: inputs.cache == 'true' || inputs.cache == true
260+
id: compute-cache-key
261+
shell: nu {0}
262+
run: |-
263+
let action_path = $env.GITHUB_ACTION_PATH | str trim --right --char '/'
264+
let lock_file = $action_path | path join 'uv.lock'
265+
let key = (
266+
if ($lock_file | path exists) {
267+
open $lock_file --raw | hash sha256
268+
} else {
269+
let action_file = $action_path | path join 'action.yml'
270+
open $action_file --raw | hash sha256
271+
}
272+
)
273+
$'key=($key)\n' | save --append $env.GITHUB_OUTPUT
274+
275+
- name: Enable cache
276+
if: inputs.cache == 'true' || inputs.cache == true
277+
uses: actions/cache@v4
278+
with:
279+
path: ${{ runner.temp }}/cpp-linter-action-cache
280+
key: cpp-linter-action_${{ steps.compute-cache-key.outputs.key }}
281+
247282
- name: Install MacOS clang dependencies
248283
if: runner.os == 'macOS'
249284
shell: bash
@@ -253,11 +288,6 @@ runs:
253288
ln -s "$(brew --prefix llvm@${{ inputs.version }})/bin/clang-format" "/usr/local/bin/clang-format-${{ inputs.version }}"
254289
ln -s "$(brew --prefix llvm@${{ inputs.version }})/bin/clang-tidy" "/usr/local/bin/clang-tidy-${{ inputs.version }}"
255290
256-
- name: Setup nu shell
257-
uses: hustcer/setup-nu@v3
258-
with:
259-
version: '0.106.1'
260-
261291
- name: Setup cpp-linter dependencies
262292
shell: nu {0}
263293
env:
@@ -266,6 +296,7 @@ runs:
266296
let action_path = $env.GITHUB_ACTION_PATH | str trim --right --char '/'
267297
$env.UV_INSTALL_DIR = $action_path | path join 'bin'
268298
$env.UV_PROJECT_ENVIRONMENT = $action_path | path join '.venv'
299+
$env.UV_CACHE_DIR = ${{ runner.temp }} | path join 'cpp-linter-action-cache'
269300
270301
if ((sys host | get 'name') == 'Windows') {
271302
^powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/0.8.9/install.ps1 | iex"
@@ -286,6 +317,7 @@ runs:
286317
)
287318
$env.UV_INSTALL_DIR = $action_path | path join 'bin'
288319
$env.UV_PROJECT_ENVIRONMENT = $action_path | path join '.venv'
320+
$env.UV_CACHE_DIR = ${{ runner.temp }} | path join 'cpp-linter-action-cache'
289321
290322
let args = [
291323
--style="${{ inputs.style }}"

0 commit comments

Comments
 (0)