-
Notifications
You must be signed in to change notification settings - Fork 12.8k
fix test #2917
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+199
−38
Closed
fix test #2917
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
998c696
fix test
lighting9999 976f545
Update python.yml
lighting9999 e023943
Update python.yml
lighting9999 50dc8fc
update Add Doctests python.yml
lighting9999 ee38ee2
rollback error
lighting9999 043a872
Update python.yml
lighting9999 20257a3
更新 python.yml
lighting9999 9ae0870
fix python.yml
lighting9999 3adb190
更新 python.yml
lighting9999 ab14d10
更新 python.yml
lighting9999 6706dca
更新 python.yml
lighting9999 a103971
fix python.yml
lighting9999 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,44 +1,218 @@ | ||
| name: Python Checks | ||
| name: Mandatory PR Code Quality Checks | ||
|
|
||
| # Force trigger for ALL PR events + retain push (for post-merge validation) | ||
| on: | ||
| pull_request: | ||
| types: [opened, synchronize, reopened] | ||
| push: | ||
| branches: | ||
| - main | ||
| branches: [ main, master ] # Only for merged PR validation | ||
| pull_request: | ||
| branches: [ main, master ] | ||
| types: [ opened, synchronize, reopened, edited ] # Trigger on ANY PR change | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | ||
| cancel-in-progress: true | ||
| env: | ||
| PYTHON_VERSION: '3.13.7' | ||
|
|
||
| jobs: | ||
| Test: | ||
| # 1. Mandatory PR Step: Ruff Auto-Format (pushes back to PR source branch) | ||
| pr-ruff-auto-format: | ||
| name: "📝 PR: Ruff Auto-Format" | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write # Critical for pushing format fixes to PR | ||
| pull-requests: write # Required to update PR status | ||
| outputs: | ||
| changes_made: ${{ steps.format-check.outputs.changes_made }} | ||
| steps: | ||
| - name: Checkout repository | ||
| - name: Checkout PR SOURCE BRANCH (MANDATORY FOR PR) | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| token: ${{ secrets.PR_ACCESS_PAT || secrets.GITHUB_TOKEN }} # Use PAT for forked PRs | ||
| fetch-depth: 0 | ||
| ref: ${{ github.head_ref }} # MUST target PR source (not main) | ||
| path: . | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v5 | ||
| uses: actions/setup-python@v4 | ||
| with: | ||
| python-version: '3.13.7' | ||
| python-version: ${{ env.PYTHON_VERSION }} | ||
| cache: 'pip' | ||
|
|
||
| - name: Install ruff | ||
| run: pip install ruff | ||
| env: | ||
| PIP_DISABLE_PIP_VERSION_CHECK: 1 | ||
|
|
||
| - name: Install all dependencies and tools | ||
| - name: Run format & detect changes | ||
| id: format-check | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install ruff bandit mypy pytest codespell requests-mock colorama | ||
| ruff format . | ||
| if git diff --quiet --exit-code; then | ||
| echo "changes_made=false" >> $GITHUB_OUTPUT | ||
| else | ||
| echo "changes_made=true" >> $GITHUB_OUTPUT | ||
| git diff --name-only >> pr_format_changes.txt # Log changes for PR review | ||
| fi | ||
|
|
||
| - name: Run Codespell check | ||
| run: codespell --skip "*.json,*.txt,*.pdf" || true | ||
| - name: Push fixes to PR source branch | ||
| if: steps.format-check.outputs.changes_made == 'true' | ||
| run: | | ||
| git config --local user.name "GitHub Actions (PR Bot)" | ||
| git config --local user.email "pr-bot@github.com" | ||
| git add . | ||
| git commit -m "[PR AUTO-FIX] Code formatting via ruff" | ||
| git push # Updates PR automatically—no manual push needed | ||
|
|
||
| - name: Comment format changes on PR (MANDATORY VISIBILITY) | ||
| if: steps.format-check.outputs.changes_made == 'true' && github.event_name == 'pull_request' | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const changes = require('fs').readFileSync('pr_format_changes.txt', 'utf8'); | ||
| github.rest.issues.createComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: context.issue.number, | ||
| body: `🔄 Auto-formatting changes applied to these files:\n\`\`\`\n${changes}\n\`\`\`` | ||
| }); | ||
|
|
||
| - name: Run Bandit security scan | ||
| run: bandit -r . --skip B101,B105 || true | ||
| # 2. Mandatory PR Step: Setup tools (ONLY runs for PRs) | ||
| pr-setup-tools: | ||
| name: "⚙️ PR: Setup Check Tools" | ||
| needs: pr-ruff-auto-format | ||
| if: github.event_name == 'pull_request' # MANDATORY: Only execute for PRs | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout PR source branch | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| ref: ${{ github.head_ref }} | ||
| path: . | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v4 | ||
| with: | ||
| python-version: ${{ env.PYTHON_VERSION }} | ||
| cache: 'pip' | ||
|
|
||
| - name: Run Pytest tests | ||
| run: pytest || true | ||
| - name: Install PR check tools | ||
| run: pip install codespell bandit mypy ruff pytest | ||
| env: | ||
| PIP_DISABLE_PIP_VERSION_CHECK: 1 | ||
|
|
||
| - name: Run Ruff checks with ignored rules | ||
| run: ruff check . --ignore B904,B905,EM101,EXE001,G004,ISC001,PLC0415,PLC1901,PLW060,PLW1641,PLW2901,PT011,PT018,PT028,S101,S311,SIM905,SLF001 | ||
| # 3. Mandatory PR Checks (all sync to PR "Checks" tab) | ||
| pr-spell-check: | ||
| name: "🔍 PR: Spell Check (Non-Blocking)" | ||
| needs: pr-setup-tools | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout PR source branch | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| ref: ${{ github.head_ref }} | ||
| path: . | ||
| - name: Run codespell | ||
| run: codespell --skip="*.json,*.lock,*.csv" --ignore-words-list="xxx,yyy,zzz" --quiet-level=2 || true | ||
|
|
||
| - name: Run Mypy type checks | ||
| run: mypy . --ignore-missing-imports || true | ||
| pr-security-check: | ||
| name: "🔒 PR: Security Check (Non-Blocking)" | ||
| needs: pr-setup-tools | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout PR source branch | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| ref: ${{ github.head_ref }} | ||
| path: . | ||
| - name: Run bandit | ||
| run: bandit -r . -f human -o pr_bandit_results.txt -f json -o pr_bandit_results.json || true | ||
| pr-security-check: | ||
| name: "🔒 PR: Security Check (Non-Blocking)" | ||
| needs: pr-setup-tools | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout PR source branch | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| ref: ${{ github.head_ref }} | ||
| path: . | ||
| - name: Run bandit | ||
| run: bandit -r . -f human -o pr_bandit_results.txt -f json -o pr_bandit_results.json || true | ||
|
|
||
| pr-type-check: | ||
| name: "🎯 PR: Type Check (Non-Blocking)" | ||
| needs: pr-setup-tools | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout PR source branch | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| ref: ${{ github.head_ref }} | ||
| path: . | ||
| - name: Run mypy | ||
| run: mypy --ignore-missing-imports --show-error-codes . || true | ||
|
|
||
| pr-lint-check: | ||
| name: "🧹 PR: Lint Check (BLOCKING)" | ||
| needs: pr-setup-tools | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout PR source branch | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| ref: ${{ github.head_ref }} | ||
| path: . | ||
| - name: Run ruff check | ||
| run: ruff check --output-format=concise . # Fails PR if lint errors exist | ||
|
|
||
| pr-unit-tests: | ||
| name: "🧪 PR: Unit Tests (BLOCKING)" | ||
| needs: pr-setup-tools | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout PR source branch | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| ref: ${{ github.head_ref }} | ||
| path: . | ||
| - name: Run pytest | ||
| run: pytest # Fails PR if test failures exist | ||
|
|
||
| # 4. Mandatory PR Security: CodeQL (syncs to PR "Security" tab) | ||
| pr-codeql: | ||
| name: "🛡️ PR: CodeQL Analysis" | ||
| needs: pr-setup-tools | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| actions: read | ||
| contents: read | ||
| security-events: write # Mandatory for PR security alerts | ||
| steps: | ||
| - name: Checkout PR source branch | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| ref: ${{ github.head_ref }} | ||
| path: . | ||
| - name: Initialize CodeQL | ||
| uses: github/codeql-action/init@v2 | ||
| with: | ||
| languages: python | ||
| - name: Autobuild | ||
| uses: github/codeql-action/autobuild@v2 | ||
| - name: Analyze | ||
| uses: github/codeql-action/analyze@v2 | ||
|
|
||
| # 5. Mandatory PR Step: Block invalid merges | ||
| pr-merge-gate: | ||
| name: "🚫 PR: Merge Gate (MANDATORY)" | ||
| needs: [pr-spell-check, pr-security-check, pr-type-check, pr-lint-check, pr-unit-tests, pr-codeql] | ||
| if: github.event_name == 'pull_request' | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Check PR validity | ||
| run: | | ||
| # Block merge if ANY blocking check fails | ||
| if [[ "${{ contains(needs.pr-lint-check.result, 'failure') || contains(needs.pr-unit-tests.result, 'failure') || contains(needs.pr-codeql.result, 'failure') }}" == "true" ]]; then | ||
| echo "❌ PR CANNOT be merged: Blocking checks (lint/tests/CodeQL) failed." | ||
| exit 1 | ||
| else | ||
| echo "✅ PR is merge-ready: All blocking checks passed." | ||
| fi | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great🤩