-
Notifications
You must be signed in to change notification settings - Fork 0
71 lines (69 loc) · 2.49 KB
/
format-python.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
name: Ensure formatted code
on:
pull_request:
types: [ opened, edited, reopened, synchronize, ready_for_review ]
workflow_dispatch:
permissions:
contents: read
pull-requests: write
jobs:
format_check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install ruff
run: pip install ruff
- name: Check formatting for Python code
env:
GH_TOKEN: ${{ github.token }}
run: |
set +e
output=$(ruff format --check)
exit_code=$?
if [ $exit_code -eq 0 ]; then
echo "All Python code is properly formatted."
gh pr comment ${{ github.event.pull_request.number }} --body "All Python code is properly formatted."
else
echo "$output"
echo "<details><summary>:rotating_light: Python code is not properly formatted. Click to expand.</summary>." > output.txt
echo "" >> output.txt
echo '```' >> output.txt
echo "$output" >> output.txt
echo '```' >> output.txt
echo "" >> output.txt
echo '</details>' >> output.txt
echo "" >> output.txt
echo 'Please run `ruff format` to format the code.' >> output.txt
gh pr comment ${{ github.event.pull_request.number }} --body-file output.txt
exit 1
fi
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install ruff
run: pip install ruff
- name: Lint Python code
env:
GH_TOKEN: ${{ github.token }}
run: |
set +e
output=$(ruff check)
exit_code=$?
if [ $exit_code -eq 0 ]; then
echo "All Python code is properly formatted."
gh pr comment ${{ github.event.pull_request.number }} --body "All Python code is properly formatted."
else
echo "$output"
echo "<details><summary>:rotating_light: Linting errors found in Python code. Click to expand.</summary>" > output.txt
echo "" >> output.txt
echo '```' >> output.txt
echo "$output" >> output.txt
echo '```' >> output.txt
echo "" >> output.txt
echo '</details>' >> output.txt
echo "" >> output.txt
echo 'Please run `ruff check --fix` to format the code.' >> output.txt
gh pr comment ${{ github.event.pull_request.number }} --body-file output.txt
exit 1
fi