-
Notifications
You must be signed in to change notification settings - Fork 20
45 lines (37 loc) · 1.21 KB
/
python-format.yml
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
name: Check Black Formatting
on:
pull_request:
types: [opened, synchronize, reopened]
permissions:
contents: read
pull-requests: write
jobs:
black-formatting:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r dev_requirements.txt
pre-commit install
- name: Run formatting check
run: pre-commit run --all-files
- name: Add PR review comment if formatting is incorrect
if: failure()
uses: actions/github-script@v4
with:
script: |
const { pull_request } = context.payload;
const comment = "Your code does not meet the Black formatting standards.\nPlease run `python3 -m pip install -r dev_requirements.txt && pre-commit install && pre-commit run --all-files` to format your code.";
await github.issues.createComment({
issue_number: pull_request.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});