Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improved black action to make pr review. #165

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 22 additions & 29 deletions .github/workflows/black-format-code.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# SPDX-FileCopyrightText: 2017-2022 Contributors to the OpenSTEF project <[email protected]> # noqa E501
# SPDX-FileCopyrightText: 2017-2024 Contributors to the OpenSTEF project <[email protected]> # noqa E501
#
# SPDX-License-Identifier: MPL-2.0

# Copied from https://github.com/psf/black/actions/runs/17913292/workflow
# Copied from https://github.com/rickstaa/action-black

# GitHub Action that uses Black to reformat the Python code in an incoming pull request.
# If all Python code in the pull request is compliant with Black then this Action
# does nothing. Otherwise, Black is run and its changes are committed to the
# incoming pull request. See https://github.com/cclauss/autoblack for a similar example.
# does nothing. Otherwise, Black is run and its changes are suggested in the
# incoming pull request. See
# https://github.com/rickstaa/action-black?tab=readme-ov-file#annotate-changes
# for a similar example.

name: Black Format Code

Expand All @@ -19,32 +21,23 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.9]
python-version: ['3.11']

permissions:
# Give the default GITHUB_TOKEN write permission to the pull request
# so that reviewdog can create annotations.
pull-requests: write

steps:
# Checkout
- name: Checkout
uses: actions/checkout@v1
# Setup
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/checkout@v4
- name: Check formatting using black
uses: rickstaa/action-black@v1
id: action_black
with:
black_args: "."
- name: Annotate diff changes using reviewdog
if: steps.action_black.outputs.is_formatted == 'true'
uses: reviewdog/action-suggester@v1
with:
python-version: ${{ matrix.python-version }}
# Install black
- name: Install Black
run: pip install black
# Run black --check
- name: Run black --check .
run: black --check .
# Run black (if needed)
- name: If needed, commit black changes to the pull request
if: failure()
run: |
black .
git config --global user.name 'black'
git config --global user.email '[email protected]'
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
git fetch
git checkout $GITHUB_HEAD_REF
git commit --signoff -am "Format Python code with Black"
git push
tool_name: blackfmt
Loading