Skip to content

Test and Publish

Test and Publish #151

name: Test and Publish
on:
push:
pull_request:
workflow_dispatch:
schedule: # Run tests once a week to detect regressions
- cron: '0 0 * * 1'
jobs:
# ------------------------------------------------------------
# Run unit tests, linter, and other static checks.
# ------------------------------------------------------------
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "pypy-3.10"]
steps:
- name: Checkout source
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
allow-prereleases: true
- name: Install dependencies
run: |
pip install .[test]
- name: Run flake8
run: |
flake8
- name: Run tests
run: |
pytest
# ------------------------------------------------------------
# Run all examples (targeting minimum Python version).
# ------------------------------------------------------------
examples:
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v4
- name: Get minimum Python version
run: |
PYTHON_VERSION=$(cat pyproject.toml | grep "requires-python" | grep -Eo "[0-9]+\.[0-9]+")
echo "PYTHON_VERSION=${PYTHON_VERSION}" >> $GITHUB_ENV
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: "pip"
- name: Install dependencies
run: |
sudo apt update
sudo DEBIAN_FRONTEND=noninteractive apt-get -y install mpi mpich libmpich-dev libopenmpi-dev
pip install .[full]
- name: Run examples
run: |
find examples/ -name '*.py' -not -name '*mpi*' | \
xargs -I {} sh -c "echo '{}:' && python '{}' && echo ''"
- name: Run MPI examples
run: |
lamboot
find examples/ -name '*.py' -name '*mpi*' | \
xargs -I {} sh -c "echo '{}:' && mpirun -np 2 --oversubscribe python '{}' && echo ''"
lamhalt
# ------------------------------------------------------------
# Build the distribution and publish (on release tag).
# ------------------------------------------------------------
publish:
runs-on: ubuntu-latest
needs: [test, examples]
steps:
- name: Checkout source
uses: actions/checkout@v4
- name: Get minimum Python version
run: |
PYTHON_VERSION=$(cat pyproject.toml | grep "requires-python" | grep -Eo "[0-9]+\.[0-9]+")
echo "PYTHON_VERSION=${PYTHON_VERSION}" >> $GITHUB_ENV
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: "pip"
- name: Install build dependencies
run: |
pip install --upgrade pip
pip install --upgrade build wheel setuptools
- name: Validate links
uses: gaurav-nelson/github-action-markdown-link-check@v1
with:
file-path: README.md
- name: Build distributions
run: python -m build
- name: Publish package
if: github.repository == 'Project-Platypus/Platypus' && github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}