ci: add test matrix (#1234) #1
This file contains 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: OpenFisca-Core / Deploy package to PyPi & Conda | |
on: | |
push: | |
branches: [master] | |
concurrency: | |
group: ${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
setup: | |
strategy: | |
fail-fast: true | |
matrix: | |
os: [ubuntu-22.04, windows-2019] | |
numpy: [2.1.1, 1.24.2] | |
# Patch version must be specified to avoid any cache confusion, since | |
# the cache key depends on the full Python version. If left unspecified, | |
# different patch versions could be allocated between jobs, and any | |
# such difference would lead to a cache not found error. | |
python: [3.11.9, 3.9.13] | |
include: | |
- os: ubuntu-22.04 | |
activate_command: source venv/bin/activate | |
- os: windows-2019 | |
activate_command: .\venv\Scripts\activate | |
uses: ./.github/workflows/_before.yaml | |
with: | |
os: ${{ matrix.os }} | |
numpy: ${{ matrix.numpy }} | |
python: ${{ matrix.python }} | |
activate_command: ${{ matrix.activate_command }} | |
test: | |
needs: [setup] | |
strategy: | |
fail-fast: true | |
matrix: | |
os: [ubuntu-22.04, windows-2019] | |
numpy: [2.1.1, 1.24.2] | |
python: [3.11.9, 3.9.13] | |
include: | |
- os: ubuntu-22.04 | |
activate_command: source venv/bin/activate | |
- os: windows-2019 | |
activate_command: .\venv\Scripts\activate | |
uses: ./.github/workflows/_test.yaml | |
with: | |
os: ${{ matrix.os }} | |
numpy: ${{ matrix.numpy }} | |
python: ${{ matrix.python }} | |
activate_command: ${{ matrix.activate_command }} | |
lint: | |
needs: [setup] | |
strategy: | |
fail-fast: true | |
matrix: | |
numpy: [1.24.2] | |
python: [3.11.9, 3.9.13] | |
uses: ./.github/workflows/_lint.yaml | |
with: | |
os: ubuntu-22.04 | |
numpy: ${{ matrix.numpy }} | |
python: ${{ matrix.python }} | |
activate_command: source venv/bin/activate | |
# The idea behind these dependencies is we want to give feedback to | |
# contributors on the version number only after they have passed all tests, | |
# so they don't have to do it twice after changes happened to the main branch | |
# during the time they took to fix the tests. | |
check-version: | |
runs-on: ubuntu-22.04 | |
needs: [test, lint] | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
# Fetch all the tags | |
fetch-depth: 0 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: 3.9.13 | |
- name: Check version number has been properly updated | |
run: ${GITHUB_WORKSPACE}/.github/is-version-number-acceptable.sh | |
# GitHub Actions does not have a halt job option, to stop from deploying if | |
# no functional changes were found. We build a separate job to substitute the | |
# halt option. The `deploy` job is dependent on the output of the | |
# `check-for-functional-changes`job. | |
check-for-functional-changes: | |
runs-on: ubuntu-22.04 | |
# Last job to run | |
needs: [check-version] | |
outputs: | |
status: ${{ steps.stop-early.outputs.status }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: 3.9.13 | |
- id: stop-early | |
# The `check-for-functional-changes` job should always succeed regardless | |
# of the `has-functional-changes` script's exit code. Consequently, we do | |
# not use that exit code to trigger deploy, but rather a dedicated output | |
# variable `status`, to avoid a job failure if the exit code is different | |
# from 0. Conversely, if the job fails the entire workflow would be | |
# marked as `failed` which is disturbing for contributors. | |
run: if "${GITHUB_WORKSPACE}/.github/has-functional-changes.sh" ; then echo | |
"::set-output name=status::success" ; fi | |
publish-to-pypi: | |
runs-on: ubuntu-22.04 | |
needs: [check-for-functional-changes] | |
if: needs.check-for-functional-changes.outputs.status == 'success' | |
env: | |
PYPI_USERNAME: __token__ | |
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN_OPENFISCA_BOT }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: 3.9.13 | |
- name: Cache deps | |
uses: actions/cache@v4 | |
with: | |
path: venv | |
key: deps-ubuntu-22.04-np1.24.2-py3.9.13-${{ hashFiles('setup.py') }} | |
- name: Cache build | |
uses: actions/cache@v4 | |
with: | |
path: venv/**/[oO]pen[fF]isca* | |
key: build-ubuntu-22.04-np1.24.2-py3.9.13-${{ hashFiles('setup.py') }}-${{ | |
github.sha }} | |
- name: Cache release | |
uses: actions/cache@v4 | |
with: | |
path: dist | |
key: release-ubuntu-22.04-np1.24.2-py3.9.13-${{ hashFiles('setup.py') }}-${{ | |
github.sha }} | |
- name: Upload package to PyPi | |
run: | | |
source venv/bin/activate | |
make publish | |
- name: Update doc | |
run: | | |
curl -L \ | |
-X POST \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "Authorization: Bearer ${{ secrets.OPENFISCADOC_BOT_ACCESS_TOKEN }}" \ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
https://api.github.com/repos/openfisca/openfisca-doc/actions/workflows/deploy.yaml/dispatches \ | |
-d '{"ref":"main"}' | |
publish-to-conda: | |
runs-on: ubuntu-22.04 | |
needs: [publish-to-pypi] | |
strategy: | |
fail-fast: false | |
steps: | |
- uses: conda-incubator/setup-miniconda@v2 | |
with: | |
auto-update-conda: true | |
python-version: 3.10.6 | |
channels: conda-forge | |
activate-environment: true | |
- uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 | |
- name: Update meta.yaml | |
run: | | |
python3 -m pip install requests argparse | |
# Sleep to allow PyPi to update its API | |
sleep 60 | |
python3 .github/get_pypi_info.py -p OpenFisca-Core | |
- name: Conda Config | |
run: | | |
conda install conda-build anaconda-client | |
conda info | |
conda config --set anaconda_upload yes | |
- name: Conda build | |
run: conda build -c conda-forge --token ${{ secrets.ANACONDA_TOKEN }} --user | |
openfisca .conda | |
test-on-windows: | |
runs-on: windows-2019 | |
needs: [publish-to-conda] | |
steps: | |
- uses: conda-incubator/setup-miniconda@v2 | |
with: | |
auto-update-conda: true | |
# See GHA Windows | |
# https://raw.githubusercontent.com/actions/python-versions/main/versions-manifest.json | |
python-version: 3.10.6 | |
channels: conda-forge | |
activate-environment: true | |
- uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 | |
- name: Install with conda | |
run: conda install -c openfisca openfisca-core | |
- name: Test openfisca | |
run: openfisca --help |