From f5a98b8bf011c10decbb1bfc5d031ad80bb04add Mon Sep 17 00:00:00 2001 From: iarspider Date: Tue, 31 Oct 2023 18:03:00 +0100 Subject: [PATCH] Create black.yaml --- .github/workflows/black.yaml | 65 ++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 .github/workflows/black.yaml diff --git a/.github/workflows/black.yaml b/.github/workflows/black.yaml new file mode 100644 index 000000000000..4913096d8bba --- /dev/null +++ b/.github/workflows/black.yaml @@ -0,0 +1,65 @@ +name: Black Style Check + +on: + pull_request: + paths: + - '**/*.py' + +jobs: + black_check: + name: Check Python Code Style with Black + runs-on: ubuntu-latest + + steps: + - name: Check out the code + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.11 + + - name: Install Black + run: pip install black + + - name: Check Code Style with Black + id: black + run: black --check . + + - name: Comment on Pull Request (success) + if: steps.build.outcome == 'success' + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const { data: pullRequest } = await github.pulls.get({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.issue.number, + }); + + await github.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + body: 'Black has checked the code style, and no modifications are required.', + }); + + - name: Comment on Pull Request (failure) + if: steps.build.outcome != 'success' + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const { data: pullRequest } = await github.pulls.get({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.issue.number, + }); + + await github.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + body: 'Black has detected code style violations.', + });