@@ -216,27 +216,23 @@ inputs:
216
216
use the number of all available CPU cores.
217
217
required : false
218
218
default : 0
219
+ cache-enable :
220
+ description : enable caching of cpp-linter dependencies
221
+ required : false
222
+ default : true
219
223
outputs :
220
224
checks-failed :
221
225
description : An integer that can be used as a boolean value to indicate if any checks failed by clang-tidy and clang-format.
222
- value : ${{ steps.cpp-linter-unix.outputs.checks-failed || steps.cpp-linter-windows .outputs.checks-failed }}
226
+ value : ${{ steps.cpp-linter.outputs.checks-failed }}
223
227
clang-tidy-checks-failed :
224
228
description : An integer that can be used as a boolean value to indicate if any checks failed by clang-tidy only.
225
- value : ${{ steps.cpp-linter-unix.outputs.clang-tidy-checks-failed || steps.cpp-linter-windows .outputs.clang-tidy-checks-failed }}
229
+ value : ${{ steps.cpp-linter.outputs.clang-tidy-checks-failed }}
226
230
clang-format-checks-failed :
227
231
description : An integer that can be used as a boolean value to indicate if any checks failed by clang-format only.
228
- value : ${{ steps.cpp-linter-unix.outputs.clang-format-checks-failed || steps.cpp-linter-windows .outputs.clang-format-checks-failed }}
232
+ value : ${{ steps.cpp-linter.outputs.clang-format-checks-failed }}
229
233
runs :
230
234
using : " composite"
231
235
steps :
232
- - name : Install python
233
- uses : actions/setup-python@v5
234
- id : setup-python
235
- with :
236
- # use python version shipped with latest Ubuntu LTS
237
- python-version : ' 3.10'
238
- update-environment : false
239
-
240
236
- name : Install Linux clang dependencies
241
237
if : runner.os == 'Linux'
242
238
shell : bash
@@ -245,13 +241,44 @@ runs:
245
241
# First try installing from default Ubuntu repositories before trying LLVM script
246
242
if ! sudo apt-get install -y clang-format-${{ inputs.version }} clang-tidy-${{ inputs.version }}; then
247
243
# This LLVM script will add the relevant LLVM PPA: https://apt.llvm.org/
248
- wget https://apt.llvm.org/llvm.sh -O $GITHUB_ACTION_PATH/llvm_install.sh
249
- chmod +x $GITHUB_ACTION_PATH/llvm_install.sh
250
- if sudo $GITHUB_ACTION_PATH/llvm_install.sh ${{ inputs.version }}; then
244
+ wget https://apt.llvm.org/llvm.sh -O ${ GITHUB_ACTION_PATH%/} /llvm_install.sh
245
+ chmod +x ${ GITHUB_ACTION_PATH%/} /llvm_install.sh
246
+ if sudo ${ GITHUB_ACTION_PATH%/} /llvm_install.sh ${{ inputs.version }}; then
251
247
sudo apt-get install -y clang-format-${{ inputs.version }} clang-tidy-${{ inputs.version }}
252
248
fi
253
249
fi
254
250
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@985d59ec83ae3e3418f9d36471cda38b9d8b9879 # v3.20.0
255
+ with :
256
+ version : ' 0.106.1'
257
+
258
+ - name : Compute cache key
259
+ if : inputs.cache-enable == 'true' || inputs.cache-enable == true
260
+ id : compute-cache-key
261
+ shell : nu {0}
262
+ run : |-
263
+ let action_path = $env.GITHUB_ACTION_PATH | path expand
264
+ let lock_file = $action_path | path join 'uv.lock'
265
+ let action_file = $action_path | path join 'action.yml'
266
+ let key = (
267
+ if ($lock_file | path exists) {
268
+ open $lock_file --raw | hash sha256
269
+ } else {
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-enable == 'true' || inputs.cache-enable == true
277
+ uses : actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
278
+ with :
279
+ path : ${{ runner.temp }}/cpp-linter-action-cache
280
+ key : cpp-linter-action_${{ runner.os }}_${{ steps.compute-cache-key.outputs.key }}
281
+
255
282
- name : Install MacOS clang dependencies
256
283
if : runner.os == 'macOS'
257
284
shell : bash
@@ -261,82 +288,66 @@ runs:
261
288
ln -s "$(brew --prefix llvm@${{ inputs.version }})/bin/clang-format" "/usr/local/bin/clang-format-${{ inputs.version }}"
262
289
ln -s "$(brew --prefix llvm@${{ inputs.version }})/bin/clang-tidy" "/usr/local/bin/clang-tidy-${{ inputs.version }}"
263
290
264
- - name : Setup python venv (Unix)
265
- if : runner.os == 'Linux' || runner.os == 'macOS'
266
- shell : bash
267
- run : |
268
- ${{ steps.setup-python.outputs.python-path }} -m venv "$GITHUB_ACTION_PATH/venv"
269
- source "$GITHUB_ACTION_PATH/venv/bin/activate"
270
- pip install -r "$GITHUB_ACTION_PATH/requirements.txt"
271
- clang-tools -i ${{ inputs.version }} -b
272
-
273
- - name : Run cpp-linter (Unix)
274
- id : cpp-linter-unix
275
- if : runner.os == 'Linux' || runner.os == 'macOS'
276
- shell : bash
277
- run : |
278
- source "$GITHUB_ACTION_PATH/venv/bin/activate"
279
-
280
- cpp-linter \
281
- --style="${{ inputs.style }}" \
282
- --extensions=${{ inputs.extensions }} \
283
- --tidy-checks="${{ inputs.tidy-checks }}" \
284
- --repo-root=${{ inputs.repo-root }} \
285
- --version=${{ inputs.version }} \
286
- --verbosity=${{ inputs.verbosity }} \
287
- --lines-changed-only=${{ inputs.lines-changed-only }} \
288
- --files-changed-only=${{ inputs.files-changed-only }} \
289
- --thread-comments=${{ inputs.thread-comments }} \
290
- --no-lgtm=${{ inputs.no-lgtm }} \
291
- --step-summary=${{ inputs.step-summary }} \
292
- --ignore="${{ inputs.ignore }}" \
293
- --ignore-tidy="${{ inputs.ignore-tidy }}" \
294
- --ignore-format="${{ inputs.ignore-format }}" \
295
- --database=${{ inputs.database }} \
296
- --file-annotations=${{ inputs.file-annotations }} \
297
- --extra-arg="${{ inputs.extra-args }}" \
298
- --tidy-review="${{ inputs.tidy-review }}" \
299
- --format-review="${{ inputs.format-review }}" \
300
- --passive-reviews="${{ inputs.passive-reviews }}" \
301
- --jobs=${{ inputs.jobs }}
302
-
303
- - name : Setup python venv (Windows)
304
- if : runner.os == 'Windows'
305
- shell : pwsh
306
- run : |
307
- ${{ steps.setup-python.outputs.python-path }} -m venv "$env:GITHUB_ACTION_PATH/venv"
308
- Invoke-Expression -Command "$env:GITHUB_ACTION_PATH/venv/Scripts/Activate.ps1"
309
- pip install -r "$env:GITHUB_ACTION_PATH/requirements.txt"
310
- clang-tools -i ${{ inputs.version }} -b
311
-
312
- - name : Run cpp-linter (Windows)
313
- id : cpp-linter-windows
314
- if : runner.os == 'Windows'
315
- shell : pwsh
316
- run : |
317
- Invoke-Expression -Command "$env:GITHUB_ACTION_PATH/venv/Scripts/Activate.ps1"
318
-
319
- $app = 'cpp-linter' +
320
- ' --style="${{ inputs.style }}"' +
321
- ' --extensions=${{ inputs.extensions }}' +
322
- ' --tidy-checks="${{ inputs.tidy-checks }}"' +
323
- ' --repo-root=${{ inputs.repo-root }}' +
324
- ' --version=${{ inputs.version }}' +
325
- ' --verbosity=${{ inputs.verbosity }}' +
326
- ' --lines-changed-only=${{ inputs.lines-changed-only }}' +
327
- ' --files-changed-only=${{ inputs.files-changed-only }}' +
328
- ' --thread-comments=${{ inputs.thread-comments }}' +
329
- ' --no-lgtm=${{ inputs.no-lgtm }}' +
330
- ' --step-summary=${{ inputs.step-summary }}' +
331
- ' --ignore="${{ inputs.ignore }}"' +
332
- ' --ignore-tidy="${{ inputs.ignore-tidy }}"' +
333
- ' --ignore-format="${{ inputs.ignore-format }}"' +
334
- ' --database=${{ inputs.database }}' +
335
- ' --file-annotations=${{ inputs.file-annotations }}' +
336
- ' --extra-arg="${{ inputs.extra-args }}"' +
337
- ' --tidy-review="${{ inputs.tidy-review }}"' +
338
- ' --format-review="${{ inputs.format-review }}"' +
339
- ' --passive-reviews="${{ inputs.passive-reviews }}"' +
340
- ' --jobs=${{ inputs.jobs }}'
341
-
342
- Invoke-Expression -Command $app
291
+ - name : Setup cpp-linter dependencies
292
+ shell : nu {0}
293
+ env :
294
+ UV_NO_MODIFY_PATH : 1
295
+ UV_VERSION : ' 0.8.9'
296
+ run : |-
297
+ let action_path = $env.GITHUB_ACTION_PATH | path expand
298
+ $env.UV_INSTALL_DIR = $action_path | path join 'bin'
299
+ $env.UV_PROJECT_ENVIRONMENT = $action_path | path join '.venv'
300
+
301
+ $env.UV_CACHE_DIR = $env.RUNNER_TEMP | path join 'cpp-linter-action-cache'
302
+ if (not ($env.UV_CACHE_DIR | path exists)) {
303
+ mkdir $env.UV_CACHE_DIR
304
+ }
305
+
306
+ print $"\n(ansi purple)Installing uv version ($env.UV_VERSION)(ansi reset)"
307
+ if ((sys host | get 'name') == 'Windows') {
308
+ ^powershell -ExecutionPolicy ByPass -c $"irm https://astral.sh/uv/($env.UV_VERSION)/install.ps1 | iex"
309
+ } else {
310
+ ^curl -LsSf $"https://astral.sh/uv/($env.UV_VERSION)/install.sh" | sh
311
+ }
312
+
313
+ print $"\n(ansi purple)Installing workflow dependencies(ansi reset)"
314
+ ^$'($env.UV_INSTALL_DIR)/uv' sync --directory $action_path --group action
315
+
316
+ print $"\n(ansi purple)Ensuring clang-format and clang-tidy ${{ inputs.version }} are present(ansi reset)"
317
+ ^$'($env.UV_INSTALL_DIR)/uv' run clang-tools -i ${{ inputs.version }} -b
318
+
319
+ - name : Run cpp-linter
320
+ id : cpp-linter
321
+ shell : nu {0}
322
+ run : |-
323
+ let action_path = $env.GITHUB_ACTION_PATH | path expand
324
+ $env.UV_INSTALL_DIR = $action_path | path join 'bin'
325
+ $env.UV_PROJECT_ENVIRONMENT = $action_path | path join '.venv'
326
+ $env.UV_CACHE_DIR = $env.RUNNER_TEMP | path join 'cpp-linter-action-cache'
327
+
328
+ let args = [
329
+ --style="${{ inputs.style }}"
330
+ --extensions=${{ inputs.extensions }}
331
+ --tidy-checks="${{ inputs.tidy-checks }}"
332
+ --repo-root=${{ inputs.repo-root }}
333
+ --version=${{ inputs.version }}
334
+ --verbosity=${{ inputs.verbosity }}
335
+ --lines-changed-only=${{ inputs.lines-changed-only }}
336
+ --files-changed-only=${{ inputs.files-changed-only }}
337
+ --thread-comments=${{ inputs.thread-comments }}
338
+ --no-lgtm=${{ inputs.no-lgtm }}
339
+ --step-summary=${{ inputs.step-summary }}
340
+ --ignore="${{ inputs.ignore }}"
341
+ --ignore-tidy="${{ inputs.ignore-tidy }}"
342
+ --ignore-format="${{ inputs.ignore-format }}"
343
+ --database=${{ inputs.database }}
344
+ --file-annotations=${{ inputs.file-annotations }}
345
+ --extra-arg="${{ inputs.extra-args }}"
346
+ --tidy-review="${{ inputs.tidy-review }}"
347
+ --format-review="${{ inputs.format-review }}"
348
+ --passive-reviews="${{ inputs.passive-reviews }}"
349
+ --jobs=${{ inputs.jobs }}
350
+ ]
351
+
352
+ print $"\n(ansi purple)Running cpp-linter(ansi reset)"
353
+ ^$'($env.UV_INSTALL_DIR)/uv' run cpp-linter ...$args
0 commit comments