Coverage #5
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: Coverage | |
| on: | |
| schedule: | |
| - cron: "0 0 * * 0" | |
| workflow_dispatch: {} | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.head_ref || github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| check-skip: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| actions: write | |
| contents: read | |
| steps: | |
| - id: skip_check | |
| uses: fkirc/skip-duplicate-actions@v5 | |
| with: | |
| skip_after_successful_duplicate: "true" | |
| do_not_skip: '["workflow_dispatch"]' | |
| outputs: | |
| should_skip: ${{ steps.skip_check.outputs.should_skip }} | |
| coverage: | |
| needs: check-skip | |
| if: needs.check-skip.outputs.should_skip != 'true' | |
| runs-on: ubuntu-22.04 | |
| defaults: | |
| run: | |
| shell: bash | |
| permissions: | |
| contents: write # push to `internal-main-badges` | |
| steps: | |
| ############ Setup ############ | |
| - name: Repo checkout | |
| uses: actions/checkout@v7 | |
| - name: Rust toolchain | |
| uses: actions-rust-lang/setup-rust-toolchain@v1 | |
| with: | |
| toolchain: 1.98.1 # LLVM 21 | |
| components: llvm-tools-preview | |
| cache-workspaces: | | |
| jix | |
| jix-macros | |
| jix-py | |
| - uses: taiki-e/install-action@cargo-llvm-cov | |
| - uses: actions/setup-python@v7 | |
| with: | |
| python-version: 3.13 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v7 | |
| with: | |
| python-version: 3.13 | |
| activate-environment: true | |
| - name: Install Python dependencies | |
| run: | | |
| python -m ensurepip | |
| uv pip install -r scripts/dev_requirements.txt | |
| - name: Install Protoc | |
| uses: arduino/setup-protoc@v3 | |
| - name: Install jix-py runtime dependencies | |
| run: | | |
| python -c ' | |
| import pathlib, subprocess, tomllib | |
| deps = tomllib.loads(pathlib.Path("jix-py/pyproject.toml").read_text())["project"]["dependencies"] | |
| subprocess.check_call(["uv", "pip", "install", *deps]) | |
| ' | |
| ############ Coverage ############ | |
| - name: Run coverage | |
| run: python scripts/coverage_report.py --out coverage-out | |
| - name: Upload reports | |
| if: always() | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| name: coverage-reports | |
| path: | | |
| coverage-out | |
| !coverage-out/*/coverage.json | |
| !coverage-out/python/llvm_profile | |
| retention-days: 30 | |
| ############ Badge ############ | |
| - name: Build badge | |
| id: badge | |
| run: | | |
| mkdir -p "${{ runner.temp }}/badge" | |
| python -c ' | |
| import json, os, pathlib | |
| percent = json.loads(pathlib.Path("coverage-out/summary.json").read_text())["total"]["percent"] | |
| cutoffs = [(90, "brightgreen"), (80, "green"), (70, "yellowgreen"), (60, "yellow"), (50, "orange")] | |
| color = next((c for threshold, c in cutoffs if percent >= threshold), "red") | |
| badge = {"schemaVersion": 1, "label": "coverage", "message": f"{percent:.1f}%", "color": color} | |
| pathlib.Path(os.environ["BADGE_DIR"], "coverage.json").write_text(json.dumps(badge) + "\n") | |
| pathlib.Path(os.environ["GITHUB_OUTPUT"]).open("a").write(f"percent={percent:.1f}\n") | |
| print(badge) | |
| ' | |
| env: | |
| BADGE_DIR: ${{ runner.temp }}/badge | |
| - name: Publish badge | |
| working-directory: ${{ runner.temp }}/badge | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| git init -q -b internal-main-badges | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git add coverage.json | |
| git commit -q -m "Coverage ${{ steps.badge.outputs.percent }}% (${{ github.sha }})" | |
| git push -qf "https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" internal-main-badges |