Skip to content

Commit 43268c2

Browse files
authored
Auto-format code with black + Pin black requirement (#673)
* Add `autoblack` GitHub action * Fix command * Add `black` to `requirements.txt`
1 parent 21d9b86 commit 43268c2

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

.github/workflows/autoblack.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# GitHub Action that uses Black to reformat all Python code and submits a PR
2+
# in regular intervals. Inspired by: https://github.com/cclauss/autoblack
3+
4+
name: autoblack
5+
on:
6+
workflow_dispatch: # allow manual trigger
7+
schedule:
8+
- cron: '0 8 * * 5' # every Friday at 8am UTC
9+
10+
jobs:
11+
autoblack:
12+
if: github.repository_owner == 'explosion'
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v2
16+
with:
17+
ref: ${{ github.head_ref }}
18+
- uses: actions/setup-python@v2
19+
- run: pip install black
20+
- name: Auto-format code if needed
21+
run: black thinc
22+
# We can't run black --check here because that returns a non-zero excit
23+
# code and makes GitHub think the action failed
24+
- name: Check for modified files
25+
id: git-check
26+
run: echo ::set-output name=modified::$(if git diff-index --quiet HEAD --; then echo "false"; else echo "true"; fi)
27+
- name: Create Pull Request
28+
if: steps.git-check.outputs.modified == 'true'
29+
uses: peter-evans/create-pull-request@v3
30+
with:
31+
title: Auto-format code with black
32+
labels: meta
33+
commit-message: Auto-format code with black
34+
committer: GitHub <[email protected]>
35+
author: explosion-bot <[email protected]>
36+
body: _This PR is auto-generated._
37+
branch: autoblack
38+
delete-branch: true
39+
draft: false
40+
- name: Check outputs
41+
if: steps.git-check.outputs.modified == 'true'
42+
run: |
43+
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
44+
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@ nbconvert>=5.6.1,<6.2.0
3333
nbformat>=5.0.4,<5.2.0
3434
# Test to_disk/from_disk against pathlib.Path subclasses
3535
pathy>=0.3.5
36+
black>=22.0,<23.0

0 commit comments

Comments
 (0)