Simplify GH actions #422
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: CI/CD | |
on: | |
push: | |
branches: [master, develop] | |
pull_request: | |
branches: [master, develop] | |
workflow_dispatch: | |
jobs: | |
test_and_build: | |
runs-on: ${{ matrix.os }} | |
strategy: | |
fail-fast: false | |
matrix: | |
os: [ubuntu-latest, macos-latest, windows-latest] | |
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12'] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Cache pip packages | |
uses: actions/cache@v3 | |
with: | |
path: ~/.cache/pip | |
key: ${{ runner.os }}-pip-${{ hashFiles('pyproject.toml') }} | |
restore-keys: | | |
${{ runner.os }}-pip- | |
- name: Install dependencies | |
run: | | |
pip install --upgrade pip | |
pip install -e .[dev,test,lint] | |
pip install cibuildwheel==2.15.0 | |
- name: Run tests and linting | |
run: | | |
black KDEpy -l 120 --check | |
flake8 --show-source --ignore=F811,W293,W391,W292,W291,W504,W503,E231 --max-line-length=120 --exclude="*examples.py,testing.py,*kde.py" KDEpy | |
pytest KDEpy --doctest-modules --capture=sys | |
- name: Build wheels | |
env: | |
CIBW_BUILD: cp${{ matrix.python-version == '3.8' && '38' || matrix.python-version == '3.9' && '39' || matrix.python-version == '3.10' && '310' || matrix.python-version == '3.11' && '311' || matrix.python-version == '3.12' && '312' }}* | |
CIBW_ARCHS_MACOS: x86_64 arm64 | |
CIBW_SKIP: pp* *-musllinux_* *-manylinux_i686 | |
run: | | |
python -m cibuildwheel --output-dir wheelhouse | |
- name: Build source distribution | |
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.11' | |
run: | | |
pip install build | |
python -m build --sdist --outdir dist | |
- name: Store artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: python-package-distributions | |
path: | | |
wheelhouse/*.whl | |
dist/*.tar.gz | |
build_docs: | |
runs-on: ubuntu-latest | |
if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop') | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.11' | |
- name: Cache pip packages | |
uses: actions/cache@v3 | |
with: | |
path: ~/.cache/pip | |
key: ${{ runner.os }}-pip-docs-${{ hashFiles('pyproject.toml') }} | |
restore-keys: | | |
${{ runner.os }}-pip-docs- | |
- name: Install dependencies | |
run: | | |
pip install --upgrade pip | |
pip install -e .[dev] | |
sudo apt install pandoc -y | |
- name: Build docs | |
run: sphinx-build docs/source _build/html -W | |
- name: Store documentation | |
uses: actions/upload-artifact@v3 | |
with: | |
name: documentation | |
path: _build/html | |
publish: | |
needs: [test_and_build, build_docs] | |
runs-on: ubuntu-latest | |
if: github.event_name == 'push' && github.ref == 'refs/heads/master' | |
steps: | |
- uses: actions/download-artifact@v3 | |
with: | |
name: python-package-distributions | |
path: dist/ | |
- name: Publish to PyPI | |
uses: pypa/gh-action-pypi-publish@e53eb8b103ffcb59469888563dc324e3c8ba6f06 | |
with: | |
skip-existing: true | |
user: __token__ | |
password: ${{ secrets.PYPI_API_TOKEN }} |