-
-
Notifications
You must be signed in to change notification settings - Fork 15
54 lines (50 loc) · 1.9 KB
/
black.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
# .github/workflows/black.yml
# From https://github.com/ad-m/github-push-action#example-workflow-file
name: black
on:
workflow_dispatch:
jobs:
black:
runs-on: ubuntu-latest
steps:
- name: STEP actions/setup-python@v5
uses: actions/setup-python@v5
with:
python-version: '3.9'
- name: STEP pip install black
# if: steps.cache.outputs.cache-hit != 'true'
run: |
python -m pip install --upgrade pip
pip install black
- name: STEP actions/checkout@v4
uses: actions/checkout@v4
with:
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token.
fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository.
- name: STEP black --check *.py
id: black
run: |
mapfile -t <<<"$(find . -type f -iname "*.py")"
((${#MAPFILE[@]})) || { echo ERROR: No .py files found >&2 ; exit 1 ; }
rv=0
black --config .github/linters/.python-black --check "${MAPFILE[@]}" || rv=$?
((rv==0)) && echo "::set-output name=changes::false" && exit 0
((rv==1)) && echo "::set-output name=changes::true" && exit 0
exit $rv
- name: STEP black *.py
if: steps.black.outputs.changes == 'true'
run: |
mapfile -t <<<"$(find . -type f -iname "*.py")"
black --config .github/linters/.python-black "${MAPFILE[@]}"
- name: STEP git commit -m "black" -a
if: steps.black.outputs.changes == 'true'
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git commit -m "black" -a
- name: STEP ad-m/github-push-action@master
if: steps.black.outputs.changes == 'true'
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}