Skip to content

Commit 29df6b3

Browse files
tiangolopre-commit
and
pre-commit
authored
👷 Add pre-commit GitHub Action workflow (fastapi#4895)
Co-authored-by: pre-commit <github-actions@github.com>
1 parent 16f1d07 commit 29df6b3

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

.github/workflows/autoformat.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Auto Format
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize]
6+
7+
jobs:
8+
autoformat:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
with:
13+
ref: ${{ github.head_ref }}
14+
- name: Set up Python
15+
uses: actions/setup-python@v2
16+
with:
17+
python-version: '3.10'
18+
- uses: actions/cache@v2
19+
id: cache
20+
with:
21+
path: ${{ env.pythonLocation }}
22+
key: ${{ runner.os }}-python-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-v01
23+
- name: Install Flit
24+
if: steps.cache.outputs.cache-hit != 'true'
25+
run: pip install flit
26+
- name: Install Dependencies
27+
if: steps.cache.outputs.cache-hit != 'true'
28+
run: flit install --symlink
29+
- uses: actions/cache@v2
30+
id: pre-commit-hooks-cache
31+
with:
32+
path: ~/.cache/pre-commit
33+
key: ${{ runner.os }}-pre-commit-hooks-${{ hashFiles('.pre-commit-config.yaml') }}-v01
34+
- name: Run pre-commit
35+
run: pre-commit run --all-files
36+
- name: Commit pre-commit changes
37+
if: failure()
38+
run: |
39+
git config --global user.name "pre-commit"
40+
git config --global user.email github-actions@github.com
41+
git add --update
42+
git commit -m "🎨 Format code with pre-commit"
43+
git push

0 commit comments

Comments
 (0)