Numerical Equivalence #84
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: Numerical Equivalence | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| schedule: | |
| - cron: "0 2 * * 1" | |
| jobs: | |
| # R live comparison: blocking when R is available | |
| equivalence-with-r: | |
| runs-on: ubuntu-latest | |
| if: github.event_name != 'schedule' | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: r-lib/actions/setup-r@v2 | |
| with: | |
| r-version: "4.5" | |
| use-public-rspm: true | |
| - name: Cache R packages | |
| uses: actions/cache@v4 | |
| with: | |
| path: ${{ env.R_LIBS_USER }} | |
| key: r-pkgs-${{ runner.os }}-r4.5-causalimpact-jsonlite-v1 | |
| - name: Install R packages | |
| id: r-install | |
| continue-on-error: true | |
| run: | | |
| Rscript -e "install.packages(c('CausalImpact','jsonlite'))" | |
| - uses: dtolnay/rust-toolchain@stable | |
| - uses: Swatinem/rust-cache@v2 | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| - name: Install Python dependencies | |
| run: pip install uv && uv sync --all-extras | |
| - name: Generate fresh R fixtures | |
| if: steps.r-install.outcome == 'success' | |
| run: Rscript scripts/generate_r_reference.R | |
| - name: Run equivalence tests | |
| if: steps.r-install.outcome == 'success' | |
| run: .venv/bin/pytest tests/test_numerical_equivalence.py -v --tb=short | |
| env: | |
| CI: "true" | |
| # Weekly: regenerate fixtures from R and auto-commit | |
| regenerate-fixtures: | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'schedule' | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - uses: r-lib/actions/setup-r@v2 | |
| with: | |
| r-version: "4.5" | |
| use-public-rspm: true | |
| - name: Cache R packages | |
| uses: actions/cache@v4 | |
| with: | |
| path: ${{ env.R_LIBS_USER }} | |
| key: r-pkgs-${{ runner.os }}-r4.5-causalimpact-jsonlite-v1 | |
| - name: Install R packages | |
| run: | | |
| Rscript -e "install.packages(c('CausalImpact','jsonlite'))" | |
| - uses: dtolnay/rust-toolchain@stable | |
| - uses: Swatinem/rust-cache@v2 | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| - name: Install Python dependencies | |
| run: pip install uv && uv sync --all-extras | |
| - name: Regenerate R fixtures | |
| run: Rscript scripts/generate_r_reference.R | |
| - name: Run equivalence tests | |
| run: .venv/bin/pytest tests/test_numerical_equivalence.py -v --tb=short | |
| env: | |
| CI: "true" | |
| - name: Commit updated fixtures if changed | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add tests/fixtures/r_reference_*.json | |
| if git diff --staged --quiet; then | |
| echo "No fixture changes, skipping commit" | |
| else | |
| git commit -m "chore: regenerate R fixtures (weekly update)" | |
| git push | |
| fi |