From 28c2a11c512ff33b2192dd90da74c9e18e00340d Mon Sep 17 00:00:00 2001 From: bartpleiter Date: Wed, 11 Dec 2024 12:47:57 +0100 Subject: [PATCH] feat: improved black action to make pr review. Signed-off-by: bartpleiter --- .github/workflows/black-format-code.yml | 51 +++++++++++-------------- 1 file changed, 22 insertions(+), 29 deletions(-) diff --git a/.github/workflows/black-format-code.yml b/.github/workflows/black-format-code.yml index 74c00078..8a5c4273 100644 --- a/.github/workflows/black-format-code.yml +++ b/.github/workflows/black-format-code.yml @@ -1,13 +1,15 @@ -# SPDX-FileCopyrightText: 2017-2022 Contributors to the OpenSTEF project # noqa E501 +# SPDX-FileCopyrightText: 2017-2024 Contributors to the OpenSTEF project # 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 @@ -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 'action@github.com' - 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 \ No newline at end of file + tool_name: blackfmt \ No newline at end of file