black-command #36
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
name: black-command | |
on: | |
repository_dispatch: | |
types: [black-command] | |
jobs: | |
black: | |
runs-on: ubuntu-latest | |
steps: | |
# Checkout the pull request branch | |
- uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.ACTIONS_BOT_TOKEN }} | |
repository: ${{ github.event.client_payload.pull_request.head.repo.full_name }} | |
ref: ${{ github.event.client_payload.pull_request.head.ref }} | |
# Setup Python environment | |
- uses: actions/setup-python@v5 | |
# Install black | |
- name: Install black | |
run: pip install black | |
# Execute black in check mode | |
- name: Black | |
id: black | |
run: | | |
format=$(black --check --quiet . || echo "true") | |
echo "format=$format" >> $GITHUB_OUTPUT | |
# Execute black and commit the change to the PR branch | |
- name: Commit to the PR branch | |
if: steps.black.outputs.format == 'true' | |
run: | | |
black . | |
git config --global user.name 'actions-bot' | |
git config --global user.email '[email protected]' | |
git commit -am "[black-command] fixes" | |
git push | |
- name: Add reaction | |
uses: peter-evans/create-or-update-comment@v4 | |
with: | |
token: ${{ secrets.ACTIONS_BOT_TOKEN }} | |
repository: ${{ github.event.client_payload.github.payload.repository.full_name }} | |
comment-id: ${{ github.event.client_payload.github.payload.comment.id }} | |
reactions: hooray |