-
Notifications
You must be signed in to change notification settings - Fork 9
65 lines (62 loc) · 2.29 KB
/
black-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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
name: Automatically format with Black and submit PR
on:
push:
branches:
- master
workflow_dispatch:
jobs:
format:
runs-on: ubuntu-20.04
steps:
- name: Checks-out repository
uses: actions/checkout@v2
- name: Set up Python 3.6
uses: actions/setup-python@v2
with:
python-version: "3.6"
- name: Install black
run: |
python -m pip install --upgrade pip
python -m pip install black
- name: Reformat with black
run: |
black cfbs/*.py tests/*.py > black_output.txt 2>&1
- name: Check if there are changes
run: |
git diff --exit-code || touch git_diff_exists
if [ -f git_diff_exists ]; then echo "Changes need to be commited"; else echo "No changes to commit"; fi
- name: Create commit message
if: hashFiles('git_diff_exists') != ''
run: |
echo "Reformatted python code using Black formatter" >> commit_message.txt
echo "" >> commit_message.txt
echo "Output from black:" >> commit_message.txt
echo "" >> commit_message.txt
echo '```' >> commit_message.txt
cat black_output.txt >> commit_message.txt
echo '```' >> commit_message.txt
- name: Commit changes
if: hashFiles('git_diff_exists') != ''
run: |
git config user.name 'GitHub'
git config user.email '<[email protected]>'
git add cfbs/*.py tests/*.py
git commit -F commit_message.txt
- id: commit-message-from-file
name: Parse commit message from file into variable
if: hashFiles('git_diff_exists') != ''
run: |
body=$(cat commit_message.txt)
body="${body//$'\n'/'%0A'}"
echo ::set-output name=body::$body
- name: Create Pull Request
if: hashFiles('git_diff_exists') != ''
uses: cfengine/create-pull-request@v3
with:
title: Reformatted python code using Black formatter
body: ${{ steps.commit-message-from-file.outputs.body }}
reviewers: |
olehermanse
larsewi
vpodzime
branch: formatting-action