Skip to content

Test and Publish

Test and Publish #14

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"]
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 tests
run: |
pytest
# ------------------------------------------------------------
# Build the distribution and publish (on release tag).
# ------------------------------------------------------------
publish:
runs-on: ubuntu-latest
needs: [test]
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/PRIM' && github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}