|
1 | 1 | name: Automatically format with Black and submit PR
|
2 | 2 |
|
3 | 3 | on:
|
4 |
| - push: |
5 |
| - branches: |
6 |
| - - master |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
7 | 7 |
|
8 |
| - workflow_dispatch: |
| 8 | + workflow_dispatch: |
9 | 9 |
|
10 | 10 | jobs:
|
11 | 11 | format:
|
12 |
| - runs-on: ubuntu-20.04 |
| 12 | + runs-on: ubuntu-24.04 |
13 | 13 | steps:
|
14 |
| - - name: Checks-out repository |
15 |
| - uses: actions/checkout@v4 |
16 |
| - - name: Set up Python 3.12 |
17 |
| - uses: actions/setup-python@v5 |
18 |
| - with: |
19 |
| - python-version: "3.12" |
20 |
| - - name: Install black |
21 |
| - run: | |
22 |
| - python -m pip install --upgrade pip |
23 |
| - python -m pip install black |
24 |
| - - name: Reformat with black |
25 |
| - run: | |
26 |
| - shopt -s globstar |
27 |
| - black cf_remote/*.py cf_remote/**/*.py tests/*.py tests/**/*.py > black_output.txt 2>&1 |
28 |
| - - name: Check if there are changes |
29 |
| - run: | |
30 |
| - git diff --exit-code || touch git_diff_exists |
31 |
| - if [ -f git_diff_exists ]; then echo "Changes need to be commited"; else echo "No changes to commit"; fi |
32 |
| - - name: Create commit message |
33 |
| - if: hashFiles('git_diff_exists') != '' |
34 |
| - run: | |
35 |
| - echo "Reformatted python code using Black formatter" >> commit_message.txt |
36 |
| - echo "" >> commit_message.txt |
37 |
| - echo "Output from black:" >> commit_message.txt |
38 |
| - echo "" >> commit_message.txt |
39 |
| - echo '```' >> commit_message.txt |
40 |
| - cat black_output.txt >> commit_message.txt |
41 |
| - echo '```' >> commit_message.txt |
42 |
| - - name: Commit changes |
43 |
| - if: hashFiles('git_diff_exists') != '' |
44 |
| - run: | |
45 |
| - git config user.name 'GitHub' |
46 |
| - git config user.email '<[email protected]>' |
47 |
| - shopt -s globstar |
48 |
| - git add cf_remote/*.py cf_remote/**/*.py tests/*.py tests/**/*.py |
49 |
| - git commit -F commit_message.txt |
50 |
| - - id: commit-message-from-file |
51 |
| - name: Parse commit message from file into variable |
52 |
| - if: hashFiles('git_diff_exists') != '' |
53 |
| - run: | |
54 |
| - body=$(cat commit_message.txt) |
55 |
| - body="${body//$'\n'/'%0A'}" |
56 |
| - echo ::set-output name=body::$body |
57 |
| - - name: Create Pull Request |
58 |
| - if: hashFiles('git_diff_exists') != '' |
59 |
| - uses: cfengine/create-pull-request@v6 |
60 |
| - with: |
61 |
| - title: Reformatted python code using Black formatter |
62 |
| - body: ${{ steps.commit-message-from-file.outputs.body }} |
63 |
| - reviewers: | |
64 |
| - olehermanse |
65 |
| - larsewi |
66 |
| - vpodzime |
67 |
| - branch: formatting-action |
| 14 | + - name: Checks-out repository |
| 15 | + uses: actions/checkout@v4 |
| 16 | + - name: Set up Python 3.12 |
| 17 | + uses: actions/setup-python@v5 |
| 18 | + with: |
| 19 | + python-version: "3.12" |
| 20 | + - name: Install black |
| 21 | + run: | |
| 22 | + python -m pip install --upgrade pip |
| 23 | + python -m pip install black |
| 24 | + - name: Reformat with black |
| 25 | + run: | |
| 26 | + shopt -s globstar |
| 27 | + black cf_remote/*.py cf_remote/**/*.py tests/*.py tests/**/*.py > black_output.txt 2>&1 |
| 28 | + - name: Check if there are changes |
| 29 | + run: | |
| 30 | + git diff --exit-code || touch git_diff_exists |
| 31 | + if [ -f git_diff_exists ]; then echo "Changes need to be commited"; else echo "No changes to commit"; fi |
| 32 | + - name: Create commit message |
| 33 | + if: hashFiles('git_diff_exists') != '' |
| 34 | + run: | |
| 35 | + echo "Reformatted python code using Black formatter" >> commit_message.txt |
| 36 | + echo "" >> commit_message.txt |
| 37 | + echo "Output from black:" >> commit_message.txt |
| 38 | + echo "" >> commit_message.txt |
| 39 | + echo '```' >> commit_message.txt |
| 40 | + cat black_output.txt >> commit_message.txt |
| 41 | + echo '```' >> commit_message.txt |
| 42 | + - name: Commit changes |
| 43 | + if: hashFiles('git_diff_exists') != '' |
| 44 | + run: | |
| 45 | + git config user.name 'GitHub' |
| 46 | + git config user.email '<[email protected]>' |
| 47 | + shopt -s globstar |
| 48 | + git add cf_remote/*.py cf_remote/**/*.py tests/*.py tests/**/*.py |
| 49 | + git commit -F commit_message.txt |
| 50 | + - id: commit-message-from-file |
| 51 | + name: Parse commit message from file into variable |
| 52 | + if: hashFiles('git_diff_exists') != '' |
| 53 | + run: | |
| 54 | + body=$(cat commit_message.txt) |
| 55 | + body="${body//$'\n'/'%0A'}" |
| 56 | + echo ::set-output name=body::$body |
| 57 | + - name: Create Pull Request |
| 58 | + if: hashFiles('git_diff_exists') != '' |
| 59 | + uses: cfengine/create-pull-request@v6 |
| 60 | + with: |
| 61 | + title: Reformatted python code using Black formatter |
| 62 | + body: ${{ steps.commit-message-from-file.outputs.body }} |
| 63 | + reviewers: | |
| 64 | + olehermanse |
| 65 | + larsewi |
| 66 | + vpodzime |
| 67 | + branch: formatting-action |
0 commit comments