From 764b2f8a8feaea7bd5b3fd9f8873d55264c08f27 Mon Sep 17 00:00:00 2001 From: jlin880 Date: Fri, 28 Feb 2025 15:28:37 -0800 Subject: [PATCH 01/10] use sre workflow --- .github/workflows/lint.yml | 83 +++++++++++++++++++++++++ .github/workflows/pr-format-checker.yml | 21 +++++++ 2 files changed, 104 insertions(+) create mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/pr-format-checker.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..0d59fea --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,83 @@ +name: Black (python) + +on: [pull_request] + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: Checkout branch + uses: actions/checkout@v4 + with: + fetch-depth: 2 + + - name: Get changed files + id: changed-files + uses: tj-actions/changed-files@40853de9f8ce2d6cfdc73c1b96f14e22ba44aec4 # v45.0.0 + with: + files: "**/*.py" + + - name: Setup Python env + uses: actions/setup-python@v5 + with: + python-version: '3.10' + cache: 'pip' + + - name: Install linters + run: pip install black pylint + + - name: Create and install dependencies in virtual environment + if: env.file_changed == 'true' + run: | + python3 -m venv venv + ./venv/bin/python -m pip install --upgrade pip + ./venv/bin/python -m pip install "black~=23.0" "pylint~=2.17" + + - name: Check formatting and lint changed Python files + if: env.file_changed == 'true' + env: + PYTHON3: ./venv/bin/python + run: | + set +euo pipefail + format_exit_status=0 + lint_exit_status=0 + files=$(echo "${{ steps.changed-files.outputs.all_changed_files }}" | xargs) + + $PYTHON3 -m black --check $files + format_exit_status=$? + if [ $format_exit_status -ne 0 ]; then + echo "Python formatting issue detected by Black." + BLACK_OUTPUT=$($PYTHON3 -m black --diff $files 2>&1) + fi + echo "Black exit status: $format_exit_status" + + $PYTHON3 -m pylint $files + lint_exit_status=$? + if [ $lint_exit_status -ne 0 ]; then + echo "Python linting issue detected by pylint." + PYLINT_OUTPUT=$($PYTHON3 -m pylint $files 2>&1) + fi + echo "Pylint exit status: $lint_exit_status" + + SUMMARY="" + echo $lint_exit_status + echo $format_exit_status + echo "black and pylint output for changed files: $files" >> "$GITHUB_STEP_SUMMARY" + if [ -n "$BLACK_OUTPUT" ]; then + SUMMARY="${SUMMARY}\n### Black Output\n\`\`\`\n$BLACK_OUTPUT\n\`\`\`\n" + fi + if [ -n "$PYLINT_OUTPUT" ]; then + SUMMARY="${SUMMARY}\n### Pylint Output\n\`\`\`\n$PYLINT_OUTPUT\n\`\`\`\n" + fi + + if [ $format_exit_status -ne 0 ] || [ $lint_exit_status -ne 0 ]; then + echo "❌ Black or pylint found issues in the code. Please fix them before committing." >> "$GITHUB_STEP_SUMMARY" + if [ -n "$SUMMARY" ]; then + echo -e "$SUMMARY" >> "$GITHUB_STEP_SUMMARY" + fi + else + echo "✅ No formatting or lint issues detected." >> "$GITHUB_STEP_SUMMARY" + fi + + # TODO: Fail the CI pipeline if there are any issues + exit 1 diff --git a/.github/workflows/pr-format-checker.yml b/.github/workflows/pr-format-checker.yml new file mode 100644 index 0000000..de500a1 --- /dev/null +++ b/.github/workflows/pr-format-checker.yml @@ -0,0 +1,21 @@ +name: PR Format Checker + +on: + pull_request: + types: [opened, edited, synchronize, reopened, labeled, unlabeled] + +permissions: + contents: read + checks: read + statuses: read + +jobs: + aviatrix-check: + uses: AvxSre/sre-workflows/.github/workflows/aviatrix.yml@main + with: + jira-check: true + jira-regex: '^[A-Z]+-[0-9]+[[:space:]:].*' + jira-max-length: 120 + jira-check-commits: false + merge-all-checks: true + semgrep-check: true \ No newline at end of file From 062a6c050dbc927e6784589353552b049e132dcd Mon Sep 17 00:00:00 2001 From: jlin880 Date: Fri, 28 Feb 2025 15:32:01 -0800 Subject: [PATCH 02/10] use sre workflow --- .github/workflows/lint.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 0d59fea..057ece6 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -17,6 +17,17 @@ jobs: with: files: "**/*.py" + - name: Check if any files changed + id: check-changed-files + run: | + if [ -z "${{ steps.changed-files.outputs.all_changed_files }}" ]; then + echo "✅ No Python File Change in this PR, skipping CI Check." >> "$GITHUB_STEP_SUMMARY" + exit 0 + else + echo "Python files changed. Continuing." + echo "file_changed=true" >> $GITHUB_ENV + fi + - name: Setup Python env uses: actions/setup-python@v5 with: From a4d5bc731e51489dc9c50502c0c8e0bfc27400fb Mon Sep 17 00:00:00 2001 From: jlin880 Date: Fri, 28 Feb 2025 15:33:07 -0800 Subject: [PATCH 03/10] add pylint as mandatory check --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 057ece6..a78cbd2 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,4 +1,4 @@ -name: Black (python) +name: Black and Pylint (python) on: [pull_request] From 93bd4314cd32247ded23044883c358e4cf7bd913 Mon Sep 17 00:00:00 2001 From: jlin880 Date: Fri, 28 Feb 2025 15:34:38 -0800 Subject: [PATCH 04/10] remove unused imports --- pytest_testrail/plugin.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pytest_testrail/plugin.py b/pytest_testrail/plugin.py index 55d36e9..aafa82a 100644 --- a/pytest_testrail/plugin.py +++ b/pytest_testrail/plugin.py @@ -6,7 +6,6 @@ import os import pytest import re -import sys import warnings import logging from datetime import datetime From 67b60a878c4aaacec298b2b4b88ea0bf6f6ee9b7 Mon Sep 17 00:00:00 2001 From: jlin880 Date: Fri, 28 Feb 2025 15:36:02 -0800 Subject: [PATCH 05/10] don't make this workflow as mandatory check --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index a78cbd2..c4da2be 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -91,4 +91,4 @@ jobs: fi # TODO: Fail the CI pipeline if there are any issues - exit 1 + exit 0 From 7dcd01036ecb590ec805204eccf3c36c38e03cf7 Mon Sep 17 00:00:00 2001 From: jlin880 Date: Fri, 28 Feb 2025 15:45:12 -0800 Subject: [PATCH 06/10] extend black check to black + pylint --- .github/workflows/black.yml | 32 -------------------------------- 1 file changed, 32 deletions(-) delete mode 100644 .github/workflows/black.yml diff --git a/.github/workflows/black.yml b/.github/workflows/black.yml deleted file mode 100644 index e810429..0000000 --- a/.github/workflows/black.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: Black (python) - -on: [push, pull_request] - -jobs: - lint: - runs-on: ubuntu-latest - steps: - - name: Checkout branch - uses: actions/checkout@v3 - with: - fetch-depth: 2 - - - name: Get changed files - id: changed-files - uses: tj-actions/changed-files@40853de9f8ce2d6cfdc73c1b96f14e22ba44aec4 # v45.0.0 - with: - files: "**/*.py" - - - name: Setup Python env - uses: actions/setup-python@v5 - with: - python-version: '3.10' - cache: 'pip' - - - name: Install linters - run: pip install black pylint - - - name: Black changed files - if: steps.changed-files.outputs.any_changed == 'true' - run: | - black --check ${{ steps.changed-files.outputs.all_changed_files }} From bb093248833b5ca0b059e47c3596211fade75102 Mon Sep 17 00:00:00 2001 From: jlin880 Date: Wed, 5 Mar 2025 11:40:26 -0800 Subject: [PATCH 07/10] Trigger Build From 89963efc41a10e6da3ec08cbee5a8884e57c6f18 Mon Sep 17 00:00:00 2001 From: rstuhlmuller <157405186+avx-rodmans@users.noreply.github.com> Date: Wed, 5 Mar 2025 12:43:38 -0800 Subject: [PATCH 08/10] ci: update --- .github/workflows/pr-format-checker.yml | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/.github/workflows/pr-format-checker.yml b/.github/workflows/pr-format-checker.yml index de500a1..7e5fb59 100644 --- a/.github/workflows/pr-format-checker.yml +++ b/.github/workflows/pr-format-checker.yml @@ -11,11 +11,20 @@ permissions: jobs: aviatrix-check: - uses: AvxSre/sre-workflows/.github/workflows/aviatrix.yml@main - with: - jira-check: true - jira-regex: '^[A-Z]+-[0-9]+[[:space:]:].*' - jira-max-length: 120 - jira-check-commits: false - merge-all-checks: true - semgrep-check: true \ No newline at end of file + runs-on: ubuntu-latest + # Restrict permissions of the GITHUB_TOKEN. + # Docs: https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs + permissions: + checks: read + statuses: read + steps: + - name: Run Merge Gatekeeper + # NOTE: v1 is updated to reflect the latest v1.x.y. Please use any tag/branch that suits your needs: + # https://github.com/upsidr/merge-gatekeeper/tags + # https://github.com/upsidr/merge-gatekeeper/branches + uses: upsidr/merge-gatekeeper@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + ignored: "aviatrix-check / merge-all-checks,aviatrix-checks / merge-all-checks" + timeout: 3600 + interval: 10 \ No newline at end of file From 7c188a0a6fd6003895d2c34d62ba0ee5f9000d81 Mon Sep 17 00:00:00 2001 From: rstuhlmuller <157405186+avx-rodmans@users.noreply.github.com> Date: Wed, 5 Mar 2025 12:44:48 -0800 Subject: [PATCH 09/10] ci: fix --- .github/workflows/pr-format-checker.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/pr-format-checker.yml b/.github/workflows/pr-format-checker.yml index 7e5fb59..a36ef8a 100644 --- a/.github/workflows/pr-format-checker.yml +++ b/.github/workflows/pr-format-checker.yml @@ -12,11 +12,6 @@ permissions: jobs: aviatrix-check: runs-on: ubuntu-latest - # Restrict permissions of the GITHUB_TOKEN. - # Docs: https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs - permissions: - checks: read - statuses: read steps: - name: Run Merge Gatekeeper # NOTE: v1 is updated to reflect the latest v1.x.y. Please use any tag/branch that suits your needs: From 743adeb48a3c5cc525d285c2440089c789658e3a Mon Sep 17 00:00:00 2001 From: rstuhlmuller <157405186+avx-rodmans@users.noreply.github.com> Date: Wed, 5 Mar 2025 12:47:14 -0800 Subject: [PATCH 10/10] ci: fix --- .github/workflows/pr-format-checker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-format-checker.yml b/.github/workflows/pr-format-checker.yml index a36ef8a..ea26ccd 100644 --- a/.github/workflows/pr-format-checker.yml +++ b/.github/workflows/pr-format-checker.yml @@ -20,6 +20,6 @@ jobs: uses: upsidr/merge-gatekeeper@v1 with: token: ${{ secrets.GITHUB_TOKEN }} - ignored: "aviatrix-check / merge-all-checks,aviatrix-checks / merge-all-checks" + ignored: "aviatrix-check" timeout: 3600 interval: 10 \ No newline at end of file