Merge pull request #27 from lizc-au/chore/add-quality-check-helper #29
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
| name: CI & Policy Checks | |
| on: | |
| push: | |
| branches: [ main ] | |
| pull_request: | |
| branches: [ main ] | |
| jobs: | |
| verify-and-test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@v4 | |
| # ================================================================= | |
| # 1. PR POLICY & SECURITY CHECKS | |
| # ================================================================= | |
| - name: 'Policy Step 1: Check for restricted file changes' | |
| if: github.event_name == 'pull_request' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const repoOwner = context.repo.owner; | |
| const repoName = context.repo.repo; | |
| const prNumber = context.payload.pull_request.number; | |
| const { data: files } = await github.rest.pulls.listFiles({ | |
| owner: repoOwner, | |
| repo: repoName, | |
| pull_number: prNumber | |
| }); | |
| const containsCoreFile = files.some(file => file.filename === 'tests/test_zoo_core.py' || file.filename === 'test_zoo_core.py'); | |
| if (containsCoreFile) { | |
| await github.rest.issues.createComment({ | |
| owner: repoOwner, | |
| repo: repoName, | |
| issue_number: prNumber, | |
| body: `[!] **Notice for @${context.payload.pull_request.user.login}:**\n\nThis PR touches \`test_zoo_core.py\`. Please ensure these edits are discussed in an open issue first so we can review them together!` | |
| }); | |
| } | |
| - name: 'Policy Step 2: Check if PR author is assigned' | |
| if: github.event_name == 'pull_request' && success() | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const prAuthor = context.payload.pull_request.user.login; | |
| const repoOwner = context.repo.owner; | |
| const repoName = context.repo.repo; | |
| const prNumber = context.payload.pull_request.number; | |
| const { data: issues } = await github.rest.issues.listForRepo({ | |
| owner: repoOwner, | |
| repo: repoName, | |
| assignee: prAuthor, | |
| state: 'open' | |
| }); | |
| if (issues.length === 0) { | |
| await github.rest.issues.createComment({ | |
| owner: repoOwner, | |
| repo: repoName, | |
| issue_number: prNumber, | |
| body: `[+] **Hi @${prAuthor}, thank you for your contribution!**\n\nWe noticed you aren't assigned to an open issue yet. You're welcome to submit PRs directly, but if this relates to an existing roadmap item, drop a comment on the issue so we can link them up!` | |
| }); | |
| } | |
| - name: 'Policy Step 3: Verify accompanying tests are included' | |
| if: github.event_name == 'pull_request' && success() | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const prAuthor = context.payload.pull_request.user.login; | |
| const repoOwner = context.repo.owner; | |
| const repoName = context.repo.repo; | |
| const prNumber = context.payload.pull_request.number; | |
| const { data: files } = await github.rest.pulls.listFiles({ | |
| owner: repoOwner, | |
| repo: repoName, | |
| pull_number: prNumber | |
| }); | |
| const hasSourceCodeChanges = files.some(file => file.filename.endsWith('.py') && !file.filename.startsWith('tests/')); | |
| const hasTestChanges = files.some(file => file.filename.startsWith('tests/')); | |
| if (hasSourceCodeChanges && !hasTestChanges) { | |
| await github.rest.issues.createComment({ | |
| owner: repoOwner, | |
| repo: repoName, | |
| issue_number: prNumber, | |
| body: `[i] **Tip for @${prAuthor}:** We noticed Python source code changes without accompanying files in \`tests/\`. Feel free to add tests as you finalize your branch!` | |
| }); | |
| } | |
| # ================================================================= | |
| # 2. PYTHON ENVIRONMENT & DEPENDENCIES | |
| # ================================================================= | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.12' | |
| - name: Install Dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| python -m pip install --group dev | |
| # ================================================================= | |
| # 3. LINTING, TYPE CHECKS & TESTS | |
| # ================================================================= | |
| - name: Run Ruff Linter | |
| run: ruff check . | |
| - name: Run Ruff Format Check | |
| run: ruff format --check . | |
| - name: Run Type Checks | |
| run: mypy . | |
| - name: Run Test Suite | |
| run: pytest |