feat: enhance CI with parallel jobs and PR comments #20
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: write | |
| 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" | |
| cache: 'pip' | |
| - 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 }} | |
| cache: 'pip' | |
| - 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" | |
| cache: 'pip' | |
| - 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: Deploy Images to Assets Branch | |
| run: | | |
| git config --global user.name "github-actions[bot]" | |
| git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
| # Stash generated images temporarily | |
| mkdir -p temp_images | |
| cp .github/images/*.png temp_images/ | |
| # Fetch all branches to ensure we can switch to assets if it exists | |
| git fetch origin | |
| # Checkout assets branch or create orphan if it doesn't exist | |
| if git show-ref --verify --quiet refs/remotes/origin/assets; then | |
| git checkout assets | |
| else | |
| git checkout --orphan assets | |
| git rm -rf . | |
| fi | |
| # Create directory for this run | |
| mkdir -p ${{ github.run_id }} | |
| cp temp_images/*.png ${{ github.run_id }}/ | |
| git add ${{ github.run_id }}/ | |
| git commit -m "Add graphs for run ${{ github.run_id }}" | |
| git push origin assets | |
| continue-on-error: true | |
| - 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: | |
| - uses: actions/checkout@v4 | |
| - 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: Generate Comment Body | |
| run: python .github/scripts/comment_pr.py | |
| env: | |
| GITHUB_REPOSITORY: ${{ github.repository }} | |
| GITHUB_RUN_ID: ${{ github.run_id }} | |
| - name: Post PR Comment | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| const body = fs.readFileSync('pr_comment_body.md', 'utf8'); | |
| github.rest.issues.createComment({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: body | |
| }) |