Skip to content

Commit 77c390c

Browse files
authored
feat: Switch clang tools from static binaries to wheels (#368)
1 parent 7672123 commit 77c390c

File tree

2 files changed

+77
-21
lines changed

2 files changed

+77
-21
lines changed

README.md

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,16 +185,28 @@ apt-get install -y libc6 wget lsb-release software-properties-common gnupg
185185

186186
Otherwise, [nushell] and/or the LLVM-provided bash script will fail to run.
187187

188+
If installing clang tools fails using the `apt` package manager, then
189+
we alternatively try the following sources in order:
190+
191+
1. PyPI Packages [clang-tidy][clang-tidy-wheel] and/or [clang-format][clang-format-wheel]
192+
2. Static binaries that we built ourselves; see [cpp-linter/clang-tools-pip] project for more detail.
193+
188194
### On macOS runners
189195

190-
The specified `version` of `clang-format` and `clang-tidy` is installed via Homebrew.
191-
Failing that, we attempt to use static binaries that we built ourselves;
192-
see [cpp-linter/clang-tools-pip] and [cpp-linter/clang-tools-static-binaries] projects for more detail.
196+
The specified `version` of `clang-format` and `clang-tidy` is installed via
197+
the following sources in order (whichever succeeds first):
198+
199+
1. Homebrew
200+
2. PyPI Packages [clang-tidy][clang-tidy-wheel] and/or [clang-format][clang-format-wheel]
201+
3. Static binaries that we built ourselves; see [cpp-linter/clang-tools-pip] project for more detail.
193202

194203
### On Windows runners
195204

196-
For Windows runners, we only use clang tools built as static binaries.
197-
See [cpp-linter/clang-tools-pip] and [cpp-linter/clang-tools-static-binaries] projects for more detail.
205+
For Windows runners, we use clang tools installed via
206+
the following sources in order (whichever succeeds first):
207+
208+
1. PyPI Packages [clang-tidy][clang-tidy-wheel] and/or [clang-format][clang-format-wheel]
209+
2. Static binaries that we built ourselves; see [cpp-linter/clang-tools-pip] project for more detail.
198210

199211
## License
200212

@@ -203,7 +215,8 @@ The scripts and documentation in this project are released under the [MIT Licens
203215
[nushell]: https://www.nushell.sh/
204216
[uv]: https://docs.astral.sh/uv/
205217
[cpp-linter/clang-tools-pip]: https://github.com/cpp-linter/clang-tools-pip
206-
[cpp-linter/clang-tools-static-binaries]: https://github.com/cpp-linter/clang-tools-static-binaries
207218
[gh-container-syntax]: https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax#jobsjob_idcontainer
219+
[clang-tidy-wheel]: https://pypi.org/project/clang-tidy
220+
[clang-format-wheel]: https://pypi.org/project/clang-format
208221

209222
<!--README-end-->

action.yml

Lines changed: 58 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ inputs:
4444
- Set this option to a blank string (`''`) to use the platform's default installed version.
4545
- This value can also be a path to where the clang tools are installed (if using a custom install location).
4646
required: false
47-
default: 20
47+
default: '20'
4848
verbosity:
4949
description: |
5050
This controls the action's verbosity in the workflow's logs.
@@ -67,7 +67,7 @@ inputs:
6767
This feature requires special permissions to perform successfully.
6868
See our [documented permissions](permissions.md)
6969
required: false
70-
default: false
70+
default: 'false'
7171
files-changed-only:
7272
description: |
7373
Set this option to false to analyze any source files in the repo.
@@ -77,7 +77,7 @@ inputs:
7777
This feature requires special permissions to perform successfully.
7878
See our [documented permissions](permissions.md)
7979
required: false
80-
default: true
80+
default: 'true'
8181
ignore:
8282
description: |
8383
Set this option with string of path(s) to ignore.
@@ -135,7 +135,7 @@ inputs:
135135
See [`thread-comments`](#thread-comments), [`tidy-review`](#tidy-review),
136136
and [`format-review`](#format-review) options for further details.
137137
required: false
138-
default: true
138+
default: 'true'
139139
step-summary:
140140
description: |
141141
Set this option to true to append content as part of workflow's job summary.
@@ -149,12 +149,12 @@ inputs:
149149
> [!NOTE]
150150
> The [`no-lgtm`](#no-lgtm) option is _not_ applied to step summaries.
151151
required: false
152-
default: false
152+
default: 'false'
153153
file-annotations:
154154
description: |
155155
Set this option to false to disable the use of file annotations as feedback.
156156
required: false
157-
default: true
157+
default: 'true'
158158
database:
159159
description: The directory containing compilation database (like compile_commands.json) file.
160160
required: false
@@ -189,7 +189,7 @@ inputs:
189189
> [!NOTE]
190190
> The [`no-lgtm`](#no-lgtm) option is applicable to Pull Request reviews.
191191
required: false
192-
default: false
192+
default: 'false'
193193
format-review:
194194
description: |
195195
Set this option to `true` to enable Pull Request reviews from clang-format.
@@ -203,19 +203,19 @@ inputs:
203203
> [!NOTE]
204204
> The [`no-lgtm`](#no-lgtm) option is applicable to Pull Request reviews.
205205
required: false
206-
default: false
206+
default: 'false'
207207
passive-reviews:
208208
description: |
209209
Set this option to `true` to prevent Pull Request reviews from approving or requesting changes.
210-
default: false
210+
default: 'false'
211211
required: false
212212
jobs:
213213
description: |
214214
The number of jobs to run in parallel.
215215
If less than or equal to 0, the number of jobs is set to
216216
use the number of all available CPU cores.
217217
required: false
218-
default: 0
218+
default: '0'
219219
cache-enable:
220220
description: |-
221221
Controls the caching of cpp-linter dependencies.
@@ -225,7 +225,7 @@ inputs:
225225
Any cached assets are kept within the path to this action's source
226226
(not in the runner's workspace or temp directory).
227227
required: false
228-
default: true
228+
default: 'true'
229229
outputs:
230230
checks-failed:
231231
description: An integer that can be used as a boolean value to indicate if any checks failed by clang-tidy and clang-format.
@@ -348,7 +348,7 @@ runs:
348348
}
349349
350350
print $"\n(ansi purple)Installing uv version ($env.UV_VERSION)(ansi reset)"
351-
let is_windows = (sys host | get 'name') == 'Windows'
351+
let is_windows = (version | get "build_os") | str starts-with "windows"
352352
let uv_installer_url = if $is_windows {
353353
$"https://astral.sh/uv/($env.UV_VERSION)/install.ps1"
354354
} else {
@@ -376,13 +376,56 @@ runs:
376376
}
377377
^$'($env.UV_INSTALL_DIR)/uv' ...$uv_args
378378
379-
print $"\n(ansi purple)Ensuring clang-format and clang-tidy ${{ inputs.version }} are present(ansi reset)"
380-
let cmd = [clang-tools -i ${{ inputs.version }} -b]
379+
let version_str = '${{ inputs.version }}'
380+
if ($version_str | is-empty) {
381+
print $"(ansi yellow)Using platform default clang tools \(version not specified)(ansi reset)"
382+
exit 0
383+
}
384+
let version = try {
385+
$version_str | into int
386+
} catch {
387+
print "Version is not an integer"
388+
if not ($version_str | path exists) {
389+
print "::error title=Invalid version input::Version must be a blank string, an integer, or a valid path"
390+
exit 1
391+
} else {
392+
print $"(ansi yellow)Using custom clang tools installation at path: ($version_str)(ansi reset)"
393+
exit 0
394+
}
395+
}
396+
381397
$uv_args = [run --no-sync --project $action_path --directory (pwd)]
382398
if $verbosity {
383399
$uv_args = $uv_args | append '-v'
384400
}
385-
^$'($env.UV_INSTALL_DIR)/uv' ...$uv_args ...$cmd
401+
402+
mut tools = []
403+
if ("${{ inputs.tidy-checks }}" != "-*") {
404+
# clang-tidy is being used
405+
$tools = $tools | append "clang-tidy"
406+
}
407+
if ("${{ inputs.style }}" | is-not-empty) {
408+
# clang-format is being used
409+
$tools = $tools | append "clang-format"
410+
}
411+
412+
print $"\n(ansi purple)Ensuring ($tools | str join ' and ') ($version_str) are present(ansi reset)"
413+
for tool in $tools {
414+
print $"Installing ($tool) ($version)"
415+
let cmd = if (
416+
(($version < 13) and ($tool | str ends-with "tidy"))
417+
or (
418+
($version <= 9)
419+
and ($tool | str ends-with "format")
420+
and not ((version | get "build_os") | str starts-with "linux")
421+
)
422+
) {
423+
[clang-tools --tool $tool --install $version]
424+
} else {
425+
[clang-tools-wheel --tool $tool --version $version]
426+
}
427+
^$'($env.UV_INSTALL_DIR)/uv' ...$uv_args ...$cmd
428+
}
386429
387430
- name: Run cpp-linter
388431
id: cpp-linter

0 commit comments

Comments
 (0)