docs: rewrite theory.md as Advanced Features guide #28
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: Release | |
| on: | |
| push: | |
| branches: [main] | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| concurrency: | |
| group: release-${{ github.ref_name }} | |
| cancel-in-progress: false | |
| permissions: | |
| contents: write | |
| outputs: | |
| released: ${{ steps.semantic-release.outputs.released || 'false' }} | |
| tag: ${{ steps.semantic-release.outputs.tag }} | |
| steps: | |
| - name: Checkout release branch | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.ref_name }} | |
| - name: Force branch to workflow sha | |
| run: git reset --hard ${{ github.sha }} | |
| - name: Run semantic release | |
| id: semantic-release | |
| uses: python-semantic-release/python-semantic-release@v10.5.3 | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| git_committer_name: github-actions | |
| git_committer_email: actions@users.noreply.github.com | |
| build: false | |
| build-wheels: | |
| needs: release | |
| if: needs.release.outputs.released == 'true' | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - os: ubuntu-latest | |
| target: x86_64 | |
| - os: ubuntu-latest | |
| target: aarch64 | |
| - os: macos-14 | |
| target: aarch64 | |
| - os: macos-15-intel | |
| target: x86_64 | |
| - os: windows-latest | |
| target: x64 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ needs.release.outputs.tag }} | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| - name: Build wheels | |
| uses: PyO3/maturin-action@v1 | |
| with: | |
| target: ${{ matrix.target }} | |
| args: --release --out dist -i 3.10 3.11 3.12 3.13 | |
| manylinux: auto | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: wheels-${{ matrix.os }}-${{ matrix.target }} | |
| path: dist/*.whl | |
| build-sdist: | |
| needs: release | |
| if: needs.release.outputs.released == 'true' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ needs.release.outputs.tag }} | |
| - name: Build sdist | |
| uses: PyO3/maturin-action@v1 | |
| with: | |
| command: sdist | |
| args: --out dist | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: sdist | |
| path: dist/*.tar.gz | |
| smoke-test-wheels: | |
| needs: build-wheels | |
| if: needs.release.outputs.released == 'true' | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - os: ubuntu-latest | |
| target: x86_64 | |
| - os: macos-14 | |
| target: aarch64 | |
| - os: macos-15-intel | |
| target: x86_64 | |
| - os: windows-latest | |
| target: x64 | |
| steps: | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| name: wheels-${{ matrix.os }}-${{ matrix.target }} | |
| path: dist | |
| - name: Install built wheel | |
| shell: python | |
| run: | | |
| import glob | |
| import subprocess | |
| import sys | |
| interpreter_tag = f"cp{sys.version_info.major}{sys.version_info.minor}" | |
| wheels = glob.glob(f"dist/*{interpreter_tag}*.whl") | |
| assert wheels, f"No wheel matching interpreter tag {interpreter_tag}" | |
| subprocess.check_call([sys.executable, "-m", "pip", "install", wheels[0]]) | |
| - name: Smoke test wheel | |
| shell: python | |
| run: | | |
| import numpy as np | |
| import pandas as pd | |
| from causal_impact import CausalImpact, ModelOptions | |
| dates = pd.date_range("2020-01-01", periods=24, freq="D") | |
| x = np.linspace(0.0, 1.0, 24) | |
| y = 5.0 + 0.2 * np.arange(24) + 1.5 * x | |
| y[18:] += 2.0 | |
| data = pd.DataFrame({"y": y, "x1": x}, index=dates) | |
| ci = CausalImpact( | |
| data, | |
| ["2020-01-01", "2020-01-18"], | |
| ["2020-01-19", "2020-01-24"], | |
| model_args=ModelOptions(niter=100, nwarmup=50, seed=42), | |
| ) | |
| assert ci.summary() | |
| assert len(ci.inferences.columns) >= 11 | |
| upload-release-assets: | |
| needs: [release, build-sdist, smoke-test-wheels] | |
| if: needs.release.outputs.released == 'true' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ needs.release.outputs.tag }} | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| path: dist | |
| merge-multiple: true | |
| - name: Upload release assets to GitHub release | |
| uses: python-semantic-release/publish-action@v10.5.3 | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| tag: ${{ needs.release.outputs.tag }} | |
| publish: | |
| needs: [release, build-sdist, smoke-test-wheels] | |
| if: needs.release.outputs.released == 'true' | |
| runs-on: ubuntu-latest | |
| environment: pypi | |
| permissions: | |
| contents: read | |
| id-token: write | |
| steps: | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| path: dist | |
| merge-multiple: true | |
| - uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| packages-dir: dist/ |