From e53f6abc1eaba64b29944c59195abfea91cf40b0 Mon Sep 17 00:00:00 2001 From: Priyank Patel <147739348+priyank766@users.noreply.github.com> Date: Thu, 5 Mar 2026 16:59:33 +0530 Subject: [PATCH] ci: add black auto-format workflow (#2827) (#2883) * ci: add black auto-format workflow (#2827) Signed-off-by: priyank * ci: use pre-commit to run black and isort (#2827) * ci: fix install dependencies to include dev extras --------- Signed-off-by: priyank --- .github/workflows/black-format.yml | 60 ++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 .github/workflows/black-format.yml diff --git a/.github/workflows/black-format.yml b/.github/workflows/black-format.yml new file mode 100644 index 00000000..77ccbfc2 --- /dev/null +++ b/.github/workflows/black-format.yml @@ -0,0 +1,60 @@ +name: black auto-format + +on: + pull_request: + branches: [ master ] + paths-ignore: + - 'web/**' + - 'doc/**' + - '**.md' + workflow_dispatch: # allow manual trigger + +permissions: + contents: write + +jobs: + black-format: + # only run on dependabot PRs or manual trigger + if: github.actor == 'dependabot[bot]' || github.event_name == 'workflow_dispatch' + runs-on: ubuntu-22.04 + steps: + - name: Checkout repository + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + with: + ref: ${{ github.head_ref }} + # need a token with write access to push the commit + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up Python 3.13 + uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0 + with: + python-version: "3.13" + + - name: Install dependencies + run: | + pip install -r requirements.txt + pip install -e .[dev,scripts] + + - name: Run isort + run: pre-commit run isort --all-files + + - name: Run black + run: pre-commit run black --all-files + + - name: Check for changes + id: changes + run: | + if git diff --quiet; then + echo "has_changes=false" >> "$GITHUB_OUTPUT" + else + echo "has_changes=true" >> "$GITHUB_OUTPUT" + fi + + - name: Commit and push formatting changes + if: steps.changes.outputs.has_changes == 'true' + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git add -A + git commit -m "style: auto-format with black and isort" + git push