@@ -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
219223outputs :
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,40 @@ 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 req_file = $action_path | path join 'requirements.txt'
265+ let lock_file = $action_path | path join 'uv.lock'
266+ let action_file = $action_path | path join 'action.yml'
267+ let key = (
268+ if ($lock_file | path exists) {
269+ open $lock_file --raw | hash sha256
270+ } else if ($req_file | path exists) {
271+ open $req_file --raw | hash sha256
272+ } else {
273+ open $action_file --raw | hash sha256
274+ }
275+ )
276+ $'key=($key)\n' | save --append $env.GITHUB_OUTPUT
277+
278+ - name : Enable cache
279+ if : inputs.cache == 'true' || inputs.cache == true
280+ uses : actions/cache@v4
281+ with :
282+ path : ${{ runner.temp }}/cpp-linter-action-cache
283+ key : cpp-linter-action_${{ steps.compute-cache-key.outputs.key }}
284+
247285 - name : Install MacOS clang dependencies
248286 if : runner.os == 'macOS'
249287 shell : bash
@@ -253,11 +291,6 @@ runs:
253291 ln -s "$(brew --prefix llvm@${{ inputs.version }})/bin/clang-format" "/usr/local/bin/clang-format-${{ inputs.version }}"
254292 ln -s "$(brew --prefix llvm@${{ inputs.version }})/bin/clang-tidy" "/usr/local/bin/clang-tidy-${{ inputs.version }}"
255293
256- - name : Setup nu shell
257- uses : hustcer/setup-nu@v3
258- with :
259- version : ' 0.106.1'
260-
261294 - name : Setup cpp-linter dependencies
262295 shell : nu {0}
263296 env :
@@ -267,6 +300,11 @@ runs:
267300 $env.UV_INSTALL_DIR = $action_path | path join 'bin'
268301 $env.UV_PROJECT_ENVIRONMENT = $action_path | path join '.venv'
269302
303+ $env.UV_CACHE_DIR = "${{ runner.temp }}" | path join 'cpp-linter-action-cache'
304+ if (not ($env.UV_CACHE_DIR | path exists)) {
305+ mkdir $env.UV_CACHE_DIR
306+ }
307+
270308 if ((sys host | get 'name') == 'Windows') {
271309 ^powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/0.8.9/install.ps1 | iex"
272310 } else {
@@ -286,6 +324,7 @@ runs:
286324 )
287325 $env.UV_INSTALL_DIR = $action_path | path join 'bin'
288326 $env.UV_PROJECT_ENVIRONMENT = $action_path | path join '.venv'
327+ $env.UV_CACHE_DIR = "${{ runner.temp }}" | path join 'cpp-linter-action-cache'
289328
290329 let args = [
291330 --style="${{ inputs.style }}"
0 commit comments