|
| 1 | +[](https://github.com/pre-commit/action/actions) |
| 2 | + |
| 3 | +pre-commit/action |
| 4 | +================= |
| 5 | + |
| 6 | +a GitHub action to run [pre-commit](https://pre-commit.com) |
| 7 | + |
| 8 | +### using this action |
| 9 | + |
| 10 | +To use this action, make a file `.github/workflows/pre-commit.yml`. Here's a |
| 11 | +template to get started: |
| 12 | + |
| 13 | +```yaml |
| 14 | +on: |
| 15 | + pull_request: |
| 16 | + push: |
| 17 | + branches: [master] |
| 18 | + |
| 19 | +jobs: |
| 20 | + pre-commit: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + steps: |
| 23 | + - uses: actions/checkout@v1 |
| 24 | + - uses: actions/setup-python@v1 |
| 25 | + - name: set PY |
| 26 | + run: echo "::set-env name=PY::$(python --version --version | sha256sum | cut -d' ' -f1)" |
| 27 | + - uses: actions/cache@v1 |
| 28 | + with: |
| 29 | + path: ~/.cache/pre-commit |
| 30 | + key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }} |
| 31 | + - uses: pre-commit/[email protected] |
| 32 | +``` |
| 33 | +
|
| 34 | +This does a few things: |
| 35 | +
|
| 36 | +- clones the code |
| 37 | +- installs python |
| 38 | +- sets up the `pre-commit` cache |
| 39 | + |
| 40 | +Hopefully in the future when `actions` matures the yaml can be simplified. |
| 41 | + |
| 42 | +### using this action in private repositories |
| 43 | + |
| 44 | +this action also provides an additional behaviour when used in private |
| 45 | +repositories. when configured with a github token, the action will push back |
| 46 | +fixes to the pull request branch. |
| 47 | + |
| 48 | +here's an example configuration for that (use the template above except for the |
| 49 | +`pre-commit` action): |
| 50 | + |
| 51 | +```yaml |
| 52 | + - uses: pre-commit/[email protected] |
| 53 | + with: |
| 54 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 55 | +``` |
| 56 | + |
| 57 | +note that `secrets.GITHUB_TOKEN` is automatically provisioned and will not |
| 58 | +require any special configuration. |
| 59 | + |
| 60 | +while you could _technically_ configure this for a public repository (using a |
| 61 | +personal access token), I can't think of a way to do this safely without |
| 62 | +exposing a privileged token to pull requests -- if you have any ideas, please |
| 63 | +leave an issue! |
0 commit comments