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 }} diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..c4da2be --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,94 @@ +name: Black and Pylint (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: 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: + 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 0 diff --git a/.github/workflows/pr-format-checker.yml b/.github/workflows/pr-format-checker.yml new file mode 100644 index 0000000..ea26ccd --- /dev/null +++ b/.github/workflows/pr-format-checker.yml @@ -0,0 +1,25 @@ +name: PR Format Checker + +on: + pull_request: + types: [opened, edited, synchronize, reopened, labeled, unlabeled] + +permissions: + contents: read + checks: read + statuses: read + +jobs: + aviatrix-check: + runs-on: ubuntu-latest + 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" + timeout: 3600 + interval: 10 \ No newline at end of file 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