python workflow #7
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: Python | |
on: | |
push: | |
branches-ignore: [gh-pages] | |
paths: | |
- ".github/workflows/python.yml" | |
- "src/**" | |
- "python/**" | |
pull_request: | |
branches-ignore: [gh-pages] | |
paths: | |
- ".github/workflows/python.yml" | |
- "src/**" | |
- "python/**" | |
# concurrency: | |
# group: ${{ github.event.pull_request.number || github.run_id }} | |
# cancel-in-progress: true | |
jobs: | |
lint-black: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: psf/black@stable | |
with: | |
src: "./python" | |
run-tests: | |
timeout-minutes: 15 | |
needs: lint-black | |
if: "! contains(github.event.head_commit.message, '[skip ci]')" | |
name: Test ${{ matrix.c.os }} (${{ matrix.c.python-version }}) | |
runs-on: ${{ matrix.c.os }} | |
strategy: | |
# When set to true, GitHub cancels all in-progress jobs if any matrix job fails. | |
fail-fast: false | |
# The maximum number of jobs that can run simultaneously | |
max-parallel: 1 | |
matrix: | |
c: | |
- {os: ubuntu-latest, python-version: '3.9'} | |
- {os: ubuntu-latest, python-version: '3.10'} | |
- {os: ubuntu-latest, python-version: '3.11'} | |
- {os: windows-latest, python-version: '3.11'} | |
- {os: macos-latest, python-version: '3.11'} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python ${{ matrix.c.python-version }} | |
uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ matrix.c.python-version }} | |
cache: 'pip' | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
python -m pip install tox tox-gh-actions | |
- name: Run tox | |
run: cd python && tox | |
build-package: | |
timeout-minutes: 10 | |
needs: run-tests | |
if: "! contains(github.event.head_commit.message, '[skip ci]')" | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
python-version: ["3.10"] | |
os: [ubuntu-latest, windows-latest, macos-latest] | |
steps: | |
- name: Checkout sources | |
uses: actions/checkout@v4 | |
- name: Setup Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install dependencies | |
run: | | |
python3 -m pip install --upgrade pip | |
python3 -m pip install --upgrade build | |
- name: Build the packages | |
run: | | |
cd python | |
python3 -m build | |
- name: Publish artifacts | |
uses: actions/upload-artifact@v2 | |
with: | |
name: distributions | |
path: python/dist/ | |
build-doc: | |
timeout-minutes: 10 | |
needs: build-package | |
if: "! contains(github.event.head_commit.message, '[skip ci]')" | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout sources | |
uses: actions/checkout@v4 | |
- name: Setup Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.10" | |
- name: Ensure Pip and Build | |
run: | |
pip install --upgrade pip | |
pip install --upgrade build | |
- name: build the package | |
run: | | |
cd python | |
python3 -m build | |
- name: install the package | |
run: | | |
cd python | |
pip install . | |
- name: install the doc build requirements | |
run: | | |
cd python | |
pip install -r requirements_dev.txt | |
- name: Build the docs | |
run: | | |
cd python | |
make -C doc clean | |
tox -e docs | |
make -C doc html | |
- name: Upload docs as github pages artifact | |
uses: actions/upload-pages-artifact@main | |
with: | |
path: python/doc/_build/html/ | |
deploy-doc: | |
needs: build-doc | |
if: "! contains(github.event.head_commit.message, '[skip ci]')" | |
permissions: | |
pages: write # to deploy to Pages | |
id-token: write # to verify the deployment originates from an appropriate source | |
environment: | |
name: github-pages | |
url: ${{ steps.deployment.outputs.page_url }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Get the built docs | |
uses: actions/download-artifact@v3 | |
with: | |
name: github-pages | |
- name: Deploy 🚀 | |
uses: JamesIves/github-pages-deploy-action@v4 | |
with: | |
folder: . # The folder the action should deploy. | |
target-folder: python | |
coverage: | |
timeout-minutes: 15 | |
needs: build-doc | |
if: "! contains(github.event.head_commit.message, '[skip ci]')" | |
name: Coverage ${{ matrix.c.os }} (${{ matrix.c.python-version }}) | |
runs-on: ${{ matrix.c.os }} | |
strategy: | |
# When set to true, GitHub cancels all in-progress jobs if any matrix job fails. | |
fail-fast: true | |
# The maximum number of jobs that can run simultaneously | |
max-parallel: 1 | |
matrix: | |
c: | |
- {os: ubuntu-latest, python-version: '3.11'} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python ${{ matrix.c.python-version }} | |
uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ matrix.c.python-version }} | |
cache: 'pip' | |
- name: Install dependencies | |
run: | | |
cd python | |
python -m pip install --upgrade pip | |
python -m pip install tox tox-gh-actions | |
- name: Run coverage using tox | |
run: | | |
cd python | |
tox -e coverage | |
- name: Upload coverage to Codecov | |
uses: codecov/codecov-action@v3 | |
with: | |
token: ${{ secrets.CODECOV_TOKEN }} | |
fail_ci_if_error: true | |
verbose: true | |