feat: enhance CI with parallel jobs and PR comments #16
Workflow file for this run
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: Python CI | |
| on: | |
| push: | |
| branches: [ "master", "main" ] | |
| pull_request: | |
| branches: [ "master", "main" ] | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| issues: write | |
| jobs: | |
| quality: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python 3.13 | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.13" | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| pip install -r requirements-dev.txt | |
| pip install -e . | |
| - name: Lint with Ruff | |
| run: ruff check . | |
| - name: Type check with Mypy | |
| run: mypy src | |
| - name: Security check with Bandit | |
| run: bandit -r src | |
| tests: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| pip install -r requirements-dev.txt | |
| pip install -e . | |
| - name: Run tests | |
| run: | | |
| pytest --junitxml=test-results-${{ matrix.python-version }}.xml | |
| - name: Upload Test Results | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: test-results-${{ matrix.python-version }} | |
| path: test-results-${{ matrix.python-version }}.xml | |
| if: always() | |
| graphs: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python 3.13 | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.13" | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| pip install -e . | |
| - name: Generate graphs | |
| run: python generate_graphs.py | |
| - name: Upload Graphs | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: generated-graphs | |
| path: .github/images/*.png | |
| pr-comment: | |
| needs: [quality, tests, graphs] | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'pull_request' | |
| steps: | |
| - name: Download Test Results | |
| uses: actions/download-artifact@v4 | |
| with: | |
| pattern: test-results-* | |
| path: test-results | |
| - name: Download Graphs | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: generated-graphs | |
| path: generated-graphs | |
| - name: Post PR Comment | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| const path = require('path'); | |
| const testDir = 'test-results'; | |
| let testSummary = '### Test Results\\n\\n| Python Version | Status |\\n|---|---|\\n'; | |
| let allPassed = true; | |
| try { | |
| const files = fs.readdirSync(testDir); | |
| for (const dir of files) { | |
| const version = dir.replace('test-results-', ''); | |
| testSummary += `| ${version} | ✅ Passed |\\n`; | |
| } | |
| } catch (e) { | |
| testSummary += `Error reading test results: ${e.message}\\n`; | |
| } | |
| let graphSummary = '### Generated Graphs\\n\\nGraphs generated by `generate_graphs.py` have been uploaded as artifacts.'; | |
| try { | |
| const graphFiles = fs.readdirSync('generated-graphs'); | |
| graphSummary += '\\n\\n**Generated Files:**\\n'; | |
| graphFiles.forEach(file => { | |
| graphSummary += `- ${file}\\n`; | |
| }); | |
| } catch (e) { | |
| graphSummary += `\\nError reading graphs: ${e.message}`; | |
| } | |
| const body = `## CI Summary 🚀\\n\\n${testSummary}\\n\\n${graphSummary}\\n\\n[View Artifacts](${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId})`; | |
| github.rest.issues.createComment({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: body | |
| }) |