grantjenks / blue

The slightly less uncompromising Python code formatter.
https://blue.readthedocs.io/
Other
393 stars 21 forks source link

How to properly use Blue in GitHub Actions? #85

Open eddyyxxyy opened 2 years ago

tpwo commented 2 years ago

I just migrated from black, and I'm using the same way as before -- pre-commit. It's a great solution to run multiple tools in one process, and it provides a ready-to-use plugin for GitHub Actions.

To enable it, you have to create a config file .pre-commit-config.yaml in your repo root; the simplest with just blue looks like that:

repos:
-   repo: https://github.com/grantjenks/blue
    rev: v0.9.1
    hooks:
    -   id: blue

My .github/workflows/pre-commit.yaml looks like this. pre-commit/action@v2.0.2 does the magic here:

name: pre-commit

on:
  pull_request:
  push:
    branches:
      - main
      - test-me-*
    tags:
      - '*'

jobs:
  pre-commit:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-python@v2
    - uses: pre-commit/action@v2.0.2

And remember that you can very easily run pre-commit locally, hence the name -- it can run all checks AKA hooks before each commit