From ae88af9485e25e66a92a8849563bc314be226a25 Mon Sep 17 00:00:00 2001 From: Lila Date: Sun, 27 Oct 2024 09:47:18 +0000 Subject: [PATCH] First iteration --- .github/workflows/black-lint.yml | 13 ----------- .github/workflows/black-suggest.yml | 19 --------------- .github/workflows/black.yml | 36 +++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 32 deletions(-) delete mode 100644 .github/workflows/black-lint.yml delete mode 100644 .github/workflows/black-suggest.yml create mode 100644 .github/workflows/black.yml diff --git a/.github/workflows/black-lint.yml b/.github/workflows/black-lint.yml deleted file mode 100644 index e0b5e1379..000000000 --- a/.github/workflows/black-lint.yml +++ /dev/null @@ -1,13 +0,0 @@ -# https://black.readthedocs.io/en/stable/integrations/github_actions.html - -name: Black Lint - -on: [push, pull_request] - -jobs: - black-lint: - permissions: {} # Remove all permissions - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: psf/black@23.12.1 diff --git a/.github/workflows/black-suggest.yml b/.github/workflows/black-suggest.yml deleted file mode 100644 index e9201b786..000000000 --- a/.github/workflows/black-suggest.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: black Suggest -on: [pull_request] -jobs: - formatting-check: - runs-on: ubuntu-24.04 - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 - with: - python-version: '3.12' - cache: 'pip' # caching pip dependencies - - run: - pip install black==23.12.1 - - name: Run black style check. - run: | - black . - - uses: parkerbxyz/suggest-changes@v1 - with: - comment: 'Please commit the suggested changes from black.' diff --git a/.github/workflows/black.yml b/.github/workflows/black.yml new file mode 100644 index 000000000..9a1f91a97 --- /dev/null +++ b/.github/workflows/black.yml @@ -0,0 +1,36 @@ +name: Black lint and suggest changes + +on: [pull_request, push] + +jobs: + black-lint-and-suggest: + permissions: # needed in forks? https://github.com/parkerbxyz/suggest-changes/issues/33 + contents: read + pull-requests: write + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: '3.12' + cache: 'pip' # caching pip dependencies + - run: pip install black==23.12.1 + + - name: Run black + run: black . # if this fails nothing else will run, this is correct behavior + + - name: Suggest changes via comment + if: github.event_name == 'pull_request' # Only run for PRs + uses: parkerbxyz/suggest-changes@v1 + with: + comment: 'Please commit the suggested changes from black.' + + - name: Fail if changes were made + run: | + if git diff --quiet; then + echo "Black formatting applied no changes." + exit 0 + else + echo "Black formatting applied changes. Please format with black." + exit 1 + fi \ No newline at end of file