|
| 1 | +name: PR checks |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: [main] |
| 6 | + |
| 7 | +concurrency: |
| 8 | + group: pr-checks-${{ github.event.pull_request.number }} |
| 9 | + cancel-in-progress: true |
| 10 | + |
| 11 | +jobs: |
| 12 | + check-fork: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - name: Check if PR is from fork |
| 16 | + run: | |
| 17 | + if [ "${{ github.event.pull_request.head.repo.full_name }}" != "${{ github.repository }}" ]; then |
| 18 | + echo "::error::PRs must be from branches in PolicyEngine/policyengine-us-data, not forks." |
| 19 | + exit 1 |
| 20 | + fi |
| 21 | +
|
| 22 | + check-lock-freshness: |
| 23 | + runs-on: ubuntu-latest |
| 24 | + needs: check-fork |
| 25 | + steps: |
| 26 | + - uses: actions/checkout@v4 |
| 27 | + - uses: actions/setup-python@v5 |
| 28 | + with: |
| 29 | + python-version: "3.14" |
| 30 | + - uses: astral-sh/setup-uv@v5 |
| 31 | + - name: Check lock file is up-to-date |
| 32 | + run: | |
| 33 | + uv lock --locked || { |
| 34 | + echo "::error::uv.lock is outdated. Run 'uv lock' and commit." |
| 35 | + exit 1 |
| 36 | + } |
| 37 | +
|
| 38 | + lint: |
| 39 | + runs-on: ubuntu-latest |
| 40 | + needs: check-fork |
| 41 | + steps: |
| 42 | + - uses: actions/checkout@v4 |
| 43 | + - run: pip install ruff>=0.9.0 |
| 44 | + - run: ruff format --check . |
| 45 | + |
| 46 | + check-changelog: |
| 47 | + runs-on: ubuntu-latest |
| 48 | + needs: check-fork |
| 49 | + steps: |
| 50 | + - uses: actions/checkout@v4 |
| 51 | + - name: Check for changelog fragment |
| 52 | + run: | |
| 53 | + FRAGMENTS=$(find changelog.d -type f ! -name '.gitkeep' | wc -l) |
| 54 | + if [ "$FRAGMENTS" -eq 0 ]; then |
| 55 | + echo "::error::No changelog fragment in changelog.d/" |
| 56 | + exit 1 |
| 57 | + fi |
| 58 | +
|
| 59 | + unit-tests: |
| 60 | + runs-on: ubuntu-latest |
| 61 | + needs: [check-fork, lint] |
| 62 | + steps: |
| 63 | + - uses: actions/checkout@v4 |
| 64 | + - uses: actions/setup-python@v5 |
| 65 | + with: |
| 66 | + python-version: "3.14" |
| 67 | + - uses: astral-sh/setup-uv@v5 |
| 68 | + - run: uv sync --dev |
| 69 | + - name: Run unit tests with coverage |
| 70 | + env: |
| 71 | + HUGGING_FACE_TOKEN: ${{ secrets.HUGGING_FACE_TOKEN }} |
| 72 | + run: > |
| 73 | + uv run pytest tests/unit/ |
| 74 | + --cov=policyengine_us_data |
| 75 | + --cov-report=xml |
| 76 | + -v |
| 77 | + - name: Upload coverage to Codecov |
| 78 | + if: always() |
| 79 | + uses: codecov/codecov-action@v4 |
| 80 | + with: |
| 81 | + file: coverage.xml |
| 82 | + flags: unit |
| 83 | + fail_ci_if_error: false |
| 84 | + env: |
| 85 | + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} |
| 86 | + |
| 87 | + smoke-test: |
| 88 | + runs-on: ubuntu-latest |
| 89 | + needs: [check-fork, lint] |
| 90 | + steps: |
| 91 | + - uses: actions/checkout@v4 |
| 92 | + - uses: actions/setup-python@v5 |
| 93 | + with: |
| 94 | + python-version: "3.14" |
| 95 | + - run: python -m pip install . |
| 96 | + - run: python -c "import policyengine_us_data; print('OK')" |
| 97 | + - run: python -c "from policyengine_core.data import Dataset; print('OK')" |
| 98 | + |
| 99 | + docs-build: |
| 100 | + runs-on: ubuntu-latest |
| 101 | + needs: [check-fork] |
| 102 | + steps: |
| 103 | + - uses: actions/checkout@v4 |
| 104 | + - uses: actions/setup-python@v5 |
| 105 | + with: |
| 106 | + python-version: "3.14" |
| 107 | + - uses: actions/setup-node@v4 |
| 108 | + with: |
| 109 | + node-version: "24" |
| 110 | + - uses: astral-sh/setup-uv@v5 |
| 111 | + - run: uv sync --dev |
| 112 | + - name: Test documentation builds |
| 113 | + run: uv run make documentation |
| 114 | + |
| 115 | + decide-test-scope: |
| 116 | + runs-on: ubuntu-latest |
| 117 | + needs: check-fork |
| 118 | + outputs: |
| 119 | + run_integration: ${{ steps.check.outputs.run_integration }} |
| 120 | + steps: |
| 121 | + - uses: actions/checkout@v4 |
| 122 | + with: |
| 123 | + fetch-depth: 0 |
| 124 | + - name: Check changed files for integration scope |
| 125 | + id: check |
| 126 | + run: | |
| 127 | + CHANGED=$(git diff --name-only origin/main...HEAD) |
| 128 | + if echo "$CHANGED" | grep -qE '^(policyengine_us_data/|modal_app/|tests/integration/)'; then |
| 129 | + echo "run_integration=true" >> "$GITHUB_OUTPUT" |
| 130 | + else |
| 131 | + echo "run_integration=false" >> "$GITHUB_OUTPUT" |
| 132 | + fi |
| 133 | +
|
| 134 | + integration-tests: |
| 135 | + runs-on: ubuntu-latest |
| 136 | + needs: [check-fork, lint, decide-test-scope] |
| 137 | + if: needs.decide-test-scope.outputs.run_integration == 'true' |
| 138 | + env: |
| 139 | + MODAL_TOKEN_ID: ${{ secrets.MODAL_TOKEN_ID }} |
| 140 | + MODAL_TOKEN_SECRET: ${{ secrets.MODAL_TOKEN_SECRET }} |
| 141 | + HUGGING_FACE_TOKEN: ${{ secrets.HUGGING_FACE_TOKEN }} |
| 142 | + steps: |
| 143 | + - uses: actions/checkout@v4 |
| 144 | + - uses: actions/setup-python@v5 |
| 145 | + with: |
| 146 | + python-version: "3.14" |
| 147 | + - run: pip install modal |
| 148 | + - name: Build datasets and run integration tests on Modal |
| 149 | + run: | |
| 150 | + modal run modal_app/data_build.py \ |
| 151 | + --branch=${{ github.head_ref || github.ref_name }} |
0 commit comments