Skip to content
25 changes: 19 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,28 @@ apt-get install -y libc6 wget lsb-release software-properties-common gnupg

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

If installing clang tools fails using the `apt` package manager, then
we alteratively try the following sources in order:

1. PyPI Packages [clang-tidy][clang-tidy-wheel] and/or [clang-format][clang-format-wheel]
2. Static binaries that we built ourselves; see [cpp-linter/clang-tools-pip] project for more detail.

### On macOS runners

The specified `version` of `clang-format` and `clang-tidy` is installed via Homebrew.
Failing that, we attempt to use static binaries that we built ourselves;
see [cpp-linter/clang-tools-pip] and [cpp-linter/clang-tools-static-binaries] projects for more detail.
The specified `version` of `clang-format` and `clang-tidy` is installed via
the following sources in order (which ever succeeds first):

1. Homebrew
2. PyPI Packages [clang-tidy][clang-tidy-wheel] and/or [clang-format][clang-format-wheel]
3. Static binaries that we built ourselves; see [cpp-linter/clang-tools-pip] project for more detail.

### On Windows runners

For Windows runners, we only use clang tools built as static binaries.
See [cpp-linter/clang-tools-pip] and [cpp-linter/clang-tools-static-binaries] projects for more detail.
For Windows runners, we use clang tools installed via
the following sources in order (which ever succeeds first):

1. PyPI Packages [clang-tidy][clang-tidy-wheel] and/or [clang-format][clang-format-wheel]
2. Static binaries that we built ourselves; see [cpp-linter/clang-tools-pip] project for more detail.

## License

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

<!--README-end-->
51 changes: 47 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ runs:
}

print $"\n(ansi purple)Installing uv version ($env.UV_VERSION)(ansi reset)"
let is_windows = (sys host | get 'name') == 'Windows'
let is_windows = (version | get "build_os") | str starts-with "windows"
let uv_installer_url = if $is_windows {
$"https://astral.sh/uv/($env.UV_VERSION)/install.ps1"
} else {
Expand Down Expand Up @@ -376,13 +376,56 @@ runs:
}
^$'($env.UV_INSTALL_DIR)/uv' ...$uv_args

print $"\n(ansi purple)Ensuring clang-format and clang-tidy ${{ inputs.version }} are present(ansi reset)"
let cmd = [clang-tools -i ${{ inputs.version }} -b]
let version_str = "${{ inputs.version }}"
if ($version_str | is-empty) {
print $"(ansi yellow)Using platform default clang tools \(version not specified)(ansi reset)"
exit 0
}
let version = try {
$version_str | into int
} catch {
print "Version is not an integer"
if not ($version_str | path exists) {
print "::error title=Invalid version input::Version must be a blank string, an integer, or a valid path"
exit 1
} else {
print $"(ansi yellow)Using custom clang tools installation at path: ($version_str)(ansi reset)"
exit 0
}
}

$uv_args = [run --no-sync --project $action_path --directory (pwd)]
if $verbosity {
$uv_args = $uv_args | append '-v'
}
^$'($env.UV_INSTALL_DIR)/uv' ...$uv_args ...$cmd

mut tools = []
if ("${{ inputs.tidy-checks }}" != "-*") {
# clang-tidy is being used
$tools = $tools | append "clang-tidy"
}
if ("${{ inputs.style }}" | is-not-empty) {
# clang-format is being used
$tools = $tools | append "clang-format"
}

print $"\n(ansi purple)Ensuring ($tools | str join " and ") ${{ inputs.version }} are present(ansi reset)"
for tool in $tools {
print $"Installing ($tool) ($version)"
let cmd = if (
(($version < 13) and ($tool | str ends-with "tidy"))
or (
($version <= 9)
and ($tool | str ends-with "format")
and not ((version | get "build_os") | str starts-with "linux")
)
) {
[clang-tools --tool $tool --install $version]
} else {
[clang-tools-wheel --tool $tool --version $version]
}
^$'($env.UV_INSTALL_DIR)/uv' ...$uv_args ...$cmd
}

- name: Run cpp-linter
id: cpp-linter
Expand Down
Loading