Skip to content

Commit ac82521

Browse files
authored
feat: migrate to uv and use nu shell (#306)
* migrate to uv v0.8.9 resolves #305 * use nu shell (cross-platform compatible) * enable caching by default closes #234 *update RTD config * pin to external actions' via commit hash * use colored logs as progress markers
1 parent 0f6d1b8 commit ac82521

File tree

9 files changed

+1210
-116
lines changed

9 files changed

+1210
-116
lines changed

.github/dependabot.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ updates:
1313
actions:
1414
patterns:
1515
- "*"
16-
- package-ecosystem: pip
16+
- package-ecosystem: uv
1717
directory: /
1818
schedule:
1919
interval: "daily"
2020
groups:
2121
pip:
2222
patterns:
23-
- "*"
23+
- '*'

.pre-commit-config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ repos:
88
- id: check-yaml
99
# special mkdocs config to include inline icons fails (see `pymdownx.emoji` in mkdocs.yml)
1010
args: ['--unsafe'] # use `--unsafe` to workaround yaml loading
11-
- id: requirements-txt-fixer

.readthedocs.yaml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ version: 2
66

77
# Set the version of Python and other tools you might need
88
build:
9-
os: ubuntu-22.04
9+
os: ubuntu-24.04
1010
tools:
11-
python: "3.12"
11+
python: latest
12+
jobs:
13+
install:
14+
- python -m pip install -U pip
15+
- pip install --group 'docs'
1216

1317
mkdocs:
1418
configuration: mkdocs.yml
15-
16-
# Optionally declare the Python requirements required to build your docs
17-
python:
18-
install:
19-
- requirements: docs/requirements.txt

action.yml

Lines changed: 104 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -216,27 +216,23 @@ inputs:
216216
use the number of all available CPU cores.
217217
required: false
218218
default: 0
219+
cache-enable:
220+
description: enable caching of cpp-linter dependencies
221+
required: false
222+
default: true
219223
outputs:
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.
222-
value: ${{ steps.cpp-linter-unix.outputs.checks-failed || steps.cpp-linter-windows.outputs.checks-failed }}
226+
value: ${{ steps.cpp-linter.outputs.checks-failed }}
223227
clang-tidy-checks-failed:
224228
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 }}
226230
clang-format-checks-failed:
227231
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 }}
229233
runs:
230234
using: "composite"
231235
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-
240236
- name: Install Linux clang dependencies
241237
if: runner.os == 'Linux'
242238
shell: bash
@@ -245,13 +241,44 @@ runs:
245241
# First try installing from default Ubuntu repositories before trying LLVM script
246242
if ! sudo apt-get install -y clang-format-${{ inputs.version }} clang-tidy-${{ inputs.version }}; then
247243
# 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
251247
sudo apt-get install -y clang-format-${{ inputs.version }} clang-tidy-${{ inputs.version }}
252248
fi
253249
fi
254250
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+
255282
- name: Install MacOS clang dependencies
256283
if: runner.os == 'macOS'
257284
shell: bash
@@ -261,82 +288,66 @@ runs:
261288
ln -s "$(brew --prefix llvm@${{ inputs.version }})/bin/clang-format" "/usr/local/bin/clang-format-${{ inputs.version }}"
262289
ln -s "$(brew --prefix llvm@${{ inputs.version }})/bin/clang-tidy" "/usr/local/bin/clang-tidy-${{ inputs.version }}"
263290
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

docs/action.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ inputs:
4949
required-permission: 'pull-requests: write #pull-request-reviews'
5050
jobs:
5151
minimum-version: '2.11.0'
52+
cache-enable:
53+
minimum-version: '2.16.0'
5254
outputs:
5355
checks-failed:
5456
minimum-version: '1.2.0'

docs/requirements.txt

Lines changed: 0 additions & 6 deletions
This file was deleted.

pyproject.toml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[project]
2+
name = "cpp-linter-action"
3+
version = "0.0.0+private_virtual"
4+
requires-python = ">=3.9"
5+
dependencies = []
6+
7+
[dependency-groups]
8+
action = [
9+
"clang-tools==0.15.1",
10+
"cpp-linter==1.10.7",
11+
]
12+
dev = [
13+
"mypy>=1.17.1",
14+
"pre-commit>=4.3.0",
15+
"ruff>=0.12.8",
16+
]
17+
docs = [
18+
"markdown-gfm-admonition>=0.1.1",
19+
"mkdocs>=1.6.1",
20+
"mkdocs-gen-files>=0.5.0",
21+
"mkdocs-include-markdown-plugin>=7.1.6",
22+
"mkdocs-material>=9.6.16",
23+
"pyyaml>=6.0.2",
24+
]

requirements.txt

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)