Skip to content

Commit 048ce58

Browse files
committed
rewrote most steps at this point
I love nushell!
1 parent 5faf5ac commit 048ce58

File tree

1 file changed

+101
-56
lines changed

1 file changed

+101
-56
lines changed

action.yml

Lines changed: 101 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,13 @@ inputs:
217217
required: false
218218
default: 0
219219
cache-enable:
220-
description: enable caching of cpp-linter dependencies
220+
description: |-
221+
Controls the caching of cpp-linter dependencies.
222+
The installed `clang-format` and `clang-tidy` tools are not cached.
223+
224+
By default, this is enabled.
225+
Any cached assets are kept within the path to this action's source
226+
(not in the runner's workspace or temp directory).
221227
required: false
222228
default: true
223229
outputs:
@@ -233,21 +239,6 @@ outputs:
233239
runs:
234240
using: "composite"
235241
steps:
236-
- name: Install Linux clang dependencies
237-
if: runner.os == 'Linux'
238-
shell: bash
239-
run: |
240-
sudo apt-get update
241-
# First try installing from default Ubuntu repositories before trying LLVM script
242-
if ! sudo apt-get install -y clang-format-${{ inputs.version }} clang-tidy-${{ inputs.version }}; then
243-
# This LLVM script will add the relevant LLVM PPA: https://apt.llvm.org/
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
247-
sudo apt-get install -y clang-format-${{ inputs.version }} clang-tidy-${{ inputs.version }}
248-
fi
249-
fi
250-
251242
- name: Setup nu shell
252243
# I'm done writing everything twice (in bash and powershell)
253244
# With nu shell, we use the same shell/script for all platforms
@@ -279,14 +270,68 @@ runs:
279270
path: ${{ runner.temp }}/cpp-linter-action-cache
280271
key: cpp-linter-action_${{ runner.os }}_${{ steps.compute-cache-key.outputs.key }}
281272

273+
- name: Install Linux clang dependencies
274+
if: runner.os == 'Linux'
275+
shell: nu {0}
276+
run: |
277+
let action_path = $env.GITHUB_ACTION_PATH | path expand
278+
let apt_install_args = [
279+
install -y clang-format-${{ inputs.version }} clang-tidy-${{ inputs.version }}
280+
]
281+
let has_sudo = not ((which 'sudo') | is-empty)
282+
283+
# First try installing from default Ubuntu repositories before trying LLVM script
284+
let are_tools_present = (
285+
if $has_sudo {
286+
^sudo apt-get update
287+
^sudo apt-get ...$apt_install_args
288+
} else {
289+
^apt-get update
290+
^apt-get ...$apt_install_args
291+
}
292+
) | complete | $in.exit_code == 0
293+
if (not $are_tools_present) {
294+
# This LLVM script will add the relevant LLVM PPA: https://apt.llvm.org/
295+
(
296+
http get --raw --redirect-mode follow https://apt.llvm.org/llvm.sh
297+
| save $"($action_path)/llvm_install.sh"
298+
)
299+
^chmod +x $"($action_path)/llvm_install.sh"
300+
301+
let llvm_installer_result = (
302+
if $has_sudo {
303+
^sudo $"($action_path)/llvm_install.sh" ${{ inputs.version }}
304+
} else {
305+
^bash $"($action_path)/llvm_install.sh" ${{ inputs.version }}
306+
}
307+
) | complete
308+
print $llvm_installer_result
309+
310+
if ($llvm_installer_result.exit_code == 0) {
311+
let result = (
312+
if $has_sudo {
313+
^sudo apt-get ...$apt_install_args
314+
} else {
315+
^apt-get ...$apt_install_args
316+
}
317+
) | complete
318+
print $result
319+
}
320+
}
321+
282322
- name: Install MacOS clang dependencies
283323
if: runner.os == 'macOS'
284-
shell: bash
285-
continue-on-error: true
286-
run: |
287-
brew install llvm@${{ inputs.version }}
288-
ln -s "$(brew --prefix llvm@${{ inputs.version }})/bin/clang-format" "/usr/local/bin/clang-format-${{ inputs.version }}"
289-
ln -s "$(brew --prefix llvm@${{ inputs.version }})/bin/clang-tidy" "/usr/local/bin/clang-tidy-${{ inputs.version }}"
324+
shell: nu {0}
325+
run: |-
326+
let brew_install_arg = 'llvm@${{ inputs.version }}'
327+
let result = (^brew install $brew_install_arg) | complete
328+
if ($result.exit_code == 0) {
329+
let brew_prefix = ^brew --prefix $brew_install_arg
330+
^ln -s $"($brew_prefix)/bin/clang-format" "/usr/local/bin/clang-format-${{ inputs.version }}"
331+
^ln -s $"($brew_prefix)/bin/clang-tidy" "/usr/local/bin/clang-tidy-${{ inputs.version }}"
332+
} else {
333+
print $result
334+
}
290335
291336
- name: Setup cpp-linter dependencies
292337
shell: nu {0}
@@ -299,29 +344,29 @@ runs:
299344
300345
$env.UV_CACHE_DIR = $env.RUNNER_TEMP | path join 'cpp-linter-action-cache'
301346
if (not ($env.UV_CACHE_DIR | path exists)) {
302-
mkdir $env.UV_CACHE_DIR
347+
mkdir $env.UV_CACHE_DIR
303348
}
304349
305350
print $"\n(ansi purple)Installing uv version ($env.UV_VERSION)(ansi reset)"
306351
let is_windows = (sys host | get 'name') == 'Windows'
307352
let uv_installer_url = if $is_windows {
308-
$"https://astral.sh/uv/($env.UV_VERSION)/install.ps1"
353+
$"https://astral.sh/uv/($env.UV_VERSION)/install.ps1"
309354
} else {
310-
$"https://astral.sh/uv/($env.UV_VERSION)/install.sh"
355+
$"https://astral.sh/uv/($env.UV_VERSION)/install.sh"
311356
}
312357
let installer = http get --raw --redirect-mode follow $uv_installer_url
313358
if $is_windows {
314-
^powershell -ExecutionPolicy ByPass $installer
359+
^powershell -ExecutionPolicy ByPass $installer
315360
} else {
316-
$installer | ^sh
361+
$installer | ^sh
317362
}
318363
319364
let gh_action_debug = $env | get --optional 'ACTIONS_STEP_DEBUG'
320365
let action_verbosity = '${{ inputs.verbosity }}' == 'debug'
321366
let verbosity = (
322-
$action_verbosity
323-
or ($gh_action_debug == true)
324-
or ($gh_action_debug == 'true')
367+
$action_verbosity
368+
or ($gh_action_debug == true)
369+
or ($gh_action_debug == 'true')
325370
)
326371
327372
print $"\n(ansi purple)Installing workflow dependencies(ansi reset)"
@@ -335,7 +380,7 @@ runs:
335380
let cmd = [clang-tools -i ${{ inputs.version }} -b]
336381
$uv_args = [run --no-sync --project $action_path --directory (pwd)]
337382
if $verbosity {
338-
$uv_args = $uv_args | append '-v'
383+
$uv_args = $uv_args | append '-v'
339384
}
340385
^$'($env.UV_INSTALL_DIR)/uv' ...$uv_args ...$cmd
341386
@@ -348,39 +393,39 @@ runs:
348393
$env.UV_CACHE_DIR = $env.RUNNER_TEMP | path join 'cpp-linter-action-cache'
349394
350395
let args = [
351-
--style="${{ inputs.style }}"
352-
--extensions=${{ inputs.extensions }}
353-
--tidy-checks="${{ inputs.tidy-checks }}"
354-
--repo-root=${{ inputs.repo-root }}
355-
--version=${{ inputs.version }}
356-
--verbosity=${{ inputs.verbosity }}
357-
--lines-changed-only=${{ inputs.lines-changed-only }}
358-
--files-changed-only=${{ inputs.files-changed-only }}
359-
--thread-comments=${{ inputs.thread-comments }}
360-
--no-lgtm=${{ inputs.no-lgtm }}
361-
--step-summary=${{ inputs.step-summary }}
362-
--ignore="${{ inputs.ignore }}"
363-
--ignore-tidy="${{ inputs.ignore-tidy }}"
364-
--ignore-format="${{ inputs.ignore-format }}"
365-
--database=${{ inputs.database }}
366-
--file-annotations=${{ inputs.file-annotations }}
367-
--extra-arg="${{ inputs.extra-args }}"
368-
--tidy-review="${{ inputs.tidy-review }}"
369-
--format-review="${{ inputs.format-review }}"
370-
--passive-reviews="${{ inputs.passive-reviews }}"
371-
--jobs=${{ inputs.jobs }}
396+
--style="${{ inputs.style }}"
397+
--extensions=${{ inputs.extensions }}
398+
--tidy-checks="${{ inputs.tidy-checks }}"
399+
--repo-root=${{ inputs.repo-root }}
400+
--version=${{ inputs.version }}
401+
--verbosity=${{ inputs.verbosity }}
402+
--lines-changed-only=${{ inputs.lines-changed-only }}
403+
--files-changed-only=${{ inputs.files-changed-only }}
404+
--thread-comments=${{ inputs.thread-comments }}
405+
--no-lgtm=${{ inputs.no-lgtm }}
406+
--step-summary=${{ inputs.step-summary }}
407+
--ignore="${{ inputs.ignore }}"
408+
--ignore-tidy="${{ inputs.ignore-tidy }}"
409+
--ignore-format="${{ inputs.ignore-format }}"
410+
--database=${{ inputs.database }}
411+
--file-annotations=${{ inputs.file-annotations }}
412+
--extra-arg="${{ inputs.extra-args }}"
413+
--tidy-review="${{ inputs.tidy-review }}"
414+
--format-review="${{ inputs.format-review }}"
415+
--passive-reviews="${{ inputs.passive-reviews }}"
416+
--jobs=${{ inputs.jobs }}
372417
]
373418
mut uv_args = [run --no-sync --project $action_path --directory (pwd)]
374419
375420
let gh_action_debug = $env | get --optional 'ACTIONS_STEP_DEBUG'
376421
let action_verbosity = '${{ inputs.verbosity }}' == 'debug'
377422
let verbosity = (
378-
$action_verbosity
379-
or ($gh_action_debug == true)
380-
or ($gh_action_debug == 'true')
423+
$action_verbosity
424+
or ($gh_action_debug == true)
425+
or ($gh_action_debug == 'true')
381426
)
382427
if $verbosity {
383-
$uv_args = $uv_args | append '-v'
428+
$uv_args = $uv_args | append '-v'
384429
}
385430
386431
print $"\n(ansi purple)Running cpp-linter(ansi reset)"

0 commit comments

Comments
 (0)