generated from worldbank/template
-
Notifications
You must be signed in to change notification settings - Fork 5
60 lines (51 loc) · 1.79 KB
/
code_formating.yaml
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
name: black-action
on: [push, pull_request]
jobs:
format_code:
name: runner / black
runs-on: ubuntu-latest
steps:
# Step 1: Checkout the repository using GITHUB_TOKEN
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
# Step 2: Set up Python environment
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10' # Align with your project Python version
# Step 3: Install Poetry
- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
echo "$HOME/.local/bin" >> $GITHUB_PATH
# Step 4: Install project dependencies
- name: Install dependencies
run: |
poetry install --no-interaction --no-root
# Step 5: Install Black as a development dependency
- name: Add Black Formatter
run: |
poetry add --dev black
# Step 6: Run Black to format the code
- name: Run Black Formatter
run: |
poetry run black .
# Step 7: Check if Black made any changes
- name: Check for formatting changes
id: check_black
run: |
git diff --exit-code
continue-on-error: true
# Step 8: Create Pull Request if formatting changes are detected
- name: Create Pull Request
if: steps.check_black.outcome == 'failure'
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
title: "Format Python code with Black"
commit-message: ":art: Format Python code with Black"
body: |
The Black formatter has made changes to ensure consistent code formatting.
base: ${{ github.head_ref }}
branch: actions/black