From 3b1e893d345ca08e8e28e3dcdf2f66f0cddc5f1f Mon Sep 17 00:00:00 2001 From: Raj <116505616+raj-open@users.noreply.github.com> Date: Sun, 26 Jan 2025 08:54:46 +0100 Subject: [PATCH] Linting-Workflow ---> v0.8.0 | Make wf only fail on syntax errors instead of unformatted code (#6041) * linting-workflow > v0.8.0: make QA only throw warning instead of error on unprettified code with no syntax errors Without a Linting policy, the workflow should only fail if code base contains syntax errors. * linting-workflow > v0.8.0: better logging * linting-workflow > v0.8.0: changed instruction to notice-type --------- Co-authored-by: raj-open --- .github/workflows/ci-black-formatting.yaml | 73 ++++++++++++++++++++++ .github/workflows/ci-black-formatting.yml | 12 ---- 2 files changed, 73 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/ci-black-formatting.yaml delete mode 100644 .github/workflows/ci-black-formatting.yml diff --git a/.github/workflows/ci-black-formatting.yaml b/.github/workflows/ci-black-formatting.yaml new file mode 100644 index 0000000000..b1d3295c1b --- /dev/null +++ b/.github/workflows/ci-black-formatting.yaml @@ -0,0 +1,73 @@ +name: ci-black-formatting + +on: + push: + pull_request: + +env: + PYTHON_VERSION: "3.12" + +jobs: + lint-formatting: + runs-on: ubuntu-latest + steps: + - name: Action - checkout repository + uses: actions/checkout@v4.2.2 + + - name: Action - install python + uses: actions/setup-python@v5.3.0 + with: + python-version: "${{ env.PYTHON_VERSION }}" + + - name: Step 1 - install dependencies + shell: bash + run: | + python3 -m pip install --upgrade pip + python3 -m pip install 'black>=24.10.0' + + # NOTE: This would suffice, however it is less informative in terms of the 3 possible outcomes + # - name: QA Step - check linting + # shell: bash + # id: linting + # run: | + # python3 -m black . + + # QA STEP + - name: QA Step - check linting + shell: bash + id: linting + run: | + python3 -m black --check . \ + && exit 0 \ + || (echo "exit_code=$?" >> "$GITHUB_OUTPUT" && exit 1); + continue-on-error: true + + # OUTCOME 1 of QA STEP + - name: QA Step - no linting errors + if: steps.linting.outcome == 'success' + shell: bash + run: |- + echo "::notice::QA step linting succeeded" + exit 0; + + # OUTCOME 2i of QA STEP + - name: QA Step - unprettified code with no syntax errors + if: steps.linting.outputs.exit_code == 1 + shell: bash + run: |- + echo "::group::QA step succeeded with warnings" + echo "::warning::one or more files contains unformatted code but no syntax errors"; + echo "::notice::please run the linter before pushing!"; + echo "::endgroup::" + exit 0; + + # OUTCOME 2ii of QA STEP + - name: QA Step - code contains syntax errors + if: steps.linting.outputs.exit_code == 123 + shell: bash + run: |- + echo "::group::QA step failed" + echo "::error::one or more files contains syntax errors"; + echo "::notice::please run the linter and fix syntax errors before pushing!"; + echo "::endgroup::" + exit 1; diff --git a/.github/workflows/ci-black-formatting.yml b/.github/workflows/ci-black-formatting.yml deleted file mode 100644 index fb293e36c8..0000000000 --- a/.github/workflows/ci-black-formatting.yml +++ /dev/null @@ -1,12 +0,0 @@ -name: ci-black-formatting - -on: - push: - pull_request: - -jobs: - lint-formatting: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: psf/black@stable