Repository navigation
Expand file tree
/
Copy pathaction.yml
More file actions
50 lines (50 loc) · 2.03 KB
/
Copy pathaction.yml
File metadata and controls
50 lines (50 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
name: pre-commit-uv
description: run pre-commit
inputs:
extra_args:
description: options to pass to pre-commit run
required: false
default: '--all-files'
uv-install:
description: whether to install uv (true=always, false=never, auto=only if not already available)
required: false
default: 'auto'
runs:
using: composite
steps:
- name: 🔍 Check if uv is already installed
if: inputs.uv-install == 'auto'
id: check-uv
run: command -v uv && echo "installed=true" >> "$GITHUB_OUTPUT" || echo "installed=false" >> "$GITHUB_OUTPUT"
shell: bash
- name: 🐍 Install the latest version of uv
if: inputs.uv-install == 'true' || (inputs.uv-install == 'auto' && steps.check-uv.outputs.installed != 'true')
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
with:
version: latest-known
enable-cache: true
cache-dependency-glob: '.pre-commit-config.yaml'
- name: ⚙️ Record the Python location
run: uv run --isolated --no-sync true && echo "pythonLocation=$(uv python find)" >>$GITHUB_ENV
shell: bash
- name: 💾 Cache pre-commit environments
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ~/.cache/pre-commit
key: pre-commit-3|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}
- name: 🧹 Run hooks with project dependencies
if: hashFiles('pyproject.toml') != ''
run: |
uv run --no-sync --with pre-commit-uv env -u UV_PYTHON pre-commit run \
--show-diff-on-failure --color=always ${INPUTS_EXTRA_ARGS}
shell: bash
env:
INPUTS_EXTRA_ARGS: ${{ inputs.extra_args }}
- name: 🧹 Run hooks without a project
if: hashFiles('pyproject.toml') == ''
run: |
uvx --from pre-commit --with pre-commit-uv env -u UV_PYTHON pre-commit run \
--show-diff-on-failure --color=always ${INPUTS_EXTRA_ARGS}
shell: bash
env:
INPUTS_EXTRA_ARGS: ${{ inputs.extra_args }}