-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #121 from UoA-CARES/chore/add-auto-formatting
Add autoformatting workflow
- Loading branch information
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
name: Auto Formatter | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- "*" | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
|
||
format: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
with: | ||
ref: ${{ github.head_ref }} | ||
fetch-depth: 0 | ||
token: ${{ secrets.BOT_ACCESS_TOKEN }} | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: "3.11" | ||
|
||
- name: Install Black | ||
run: pip install black | ||
|
||
- name: Run Black Formatter | ||
run: black . | ||
|
||
- name: Check for changes | ||
id: check_changes | ||
run: | | ||
if [ -n "$(git diff)" ]; then | ||
echo "::set-output name=changed::true" | ||
else | ||
echo "::set-output name=changed::false" | ||
fi | ||
continue-on-error: true | ||
|
||
# Optionally, customize the user name and commit message, and can add an email as well such as Github Actions' email | ||
- name: Set up Git and Commit Changes | ||
run: | | ||
if [ "${{ steps.check_changes.outputs.changed }}" == "true" ]; then | ||
git config --local user.name "Formatter [BOT]" | ||
git add . | ||
git commit -m "Auto-format code 🧹🌟🤖" | ||
git push | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters