├── .github └── workflows │ └── main.yml ├── .pre-commit-config.yaml ├── LICENSE ├── README.md └── action.yml /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | on: 2 | pull_request: 3 | push: 4 | branches: [main, test-me-*] 5 | 6 | jobs: 7 | main: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v4 11 | - name: self test action 12 | uses: ./ 13 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | repos: 2 | - repo: https://github.com/pre-commit/pre-commit-hooks 3 | rev: v5.0.0 4 | hooks: 5 | - id: trailing-whitespace 6 | - id: end-of-file-fixer 7 | - id: check-yaml 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2019 Anthony Sottile 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | this action is in maintenance-only mode and will not be accepting new features. 2 | 3 | generally you want to use [pre-commit.ci] which is faster and has more features. 4 | 5 | [pre-commit.ci]: https://pre-commit.ci 6 | 7 | ___ 8 | 9 | [![pre-commit.ci status](https://results.pre-commit.ci/badge/github/pre-commit/action/main.svg)](https://results.pre-commit.ci/latest/github/pre-commit/action/main) 10 | [![Build Status](https://github.com/pre-commit/action/actions/workflows/main.yml/badge.svg)](https://github.com/pre-commit/action/actions) 11 | 12 | pre-commit/action 13 | ================= 14 | 15 | A GitHub action to run [pre-commit](https://pre-commit.com) 16 | using [pre-commit-uv](https://github.com/tox-dev/pre-commit-uv). 17 | 18 | ### using this action 19 | 20 | To use this action, make a file `.github/workflows/pre-commit.yml`. Here's a 21 | template to get started: 22 | 23 | ```yaml 24 | name: pre-commit 25 | 26 | on: 27 | pull_request: 28 | push: 29 | branches: [main] 30 | 31 | jobs: 32 | pre-commit: 33 | runs-on: ubuntu-latest 34 | steps: 35 | - uses: actions/checkout@v4 36 | - uses: tox-dev/action-pre-commit-uv@v1 37 | ``` 38 | 39 | This does a few things: 40 | 41 | - clones the code 42 | - installs uv 43 | - sets up the `pre-commit` cache 44 | 45 | ### using this action with custom invocations 46 | 47 | By default, this action runs all the hooks against all the files. `extra_args` 48 | lets users specify a single hook id and/or options to pass to `pre-commit run`. 49 | 50 | Here's a sample step configuration that only runs the `flake8` hook against all 51 | the files (use the template above except for the `pre-commit` action): 52 | 53 | ```yaml 54 | - uses: tox-dev/action-pre-commit-uv@v1 55 | with: 56 | extra_args: flake8 --all-files 57 | ``` 58 | 59 | ### using this action in private repositories 60 | 61 | prior to v3.0.0, this action had custom behaviour which pushed changes back to 62 | the pull request when supplied with a `token`. 63 | 64 | this behaviour was removed: 65 | - it required a PAT (didn't work with short-lived `GITHUB_TOKEN`) 66 | - properly hiding this `input` from the installation and execution of hooks 67 | is intractable in github actions (it is readily available as `$INPUT_TOKEN`) 68 | - this meant potentially unvetted code could access the token via the 69 | environment 70 | 71 | you can _likely_ achieve the same thing with an external action such as 72 | [git-auto-commit-action] though you may want to take precautions to clear `git` 73 | hooks or other ways that arbitrary code execution can occur when running 74 | `git commit` / `git push` (for example [core.fsmonitor]). 75 | 76 | while unrelated to this action, [pre-commit.ci] avoids these problems by 77 | installing and executing isolated from the short-lived repository-scoped 78 | [installation access token]. 79 | 80 | [git-auto-commit-action]: https://github.com/stefanzweifel/git-auto-commit-action 81 | [core.fsmonitor]: https://github.blog/2022-04-12-git-security-vulnerability-announced/ 82 | [pre-commit.ci]: https://pre-commit.ci 83 | [installation access token]: https://docs.github.com/en/rest/apps/apps#create-an-installation-access-token-for-an-app 84 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: pre-commit 2 | description: run pre-commit 3 | inputs: 4 | extra_args: 5 | description: options to pass to pre-commit run 6 | required: false 7 | default: '--all-files' 8 | runs: 9 | using: composite 10 | steps: 11 | - name: Install the latest version of uv 12 | uses: astral-sh/setup-uv@v5 13 | with: 14 | enable-cache: true 15 | cache-dependency-glob: '.pre-commit-config.yaml' 16 | - run: uv run --isolated --no-sync true && echo "pythonLocation=$(uv python find)" >>$GITHUB_ENV 17 | shell: bash 18 | - uses: actions/cache@v4 19 | with: 20 | path: ~/.cache/pre-commit 21 | key: pre-commit-3|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }} 22 | - run: uv run --no-sync --with pre-commit-uv pre-commit run --show-diff-on-failure --color=always ${{ inputs.extra_args }} 23 | shell: bash 24 | --------------------------------------------------------------------------------