CI: extend tests to Python 3.12 as well #221
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: Continuous integration | |
on: | |
push: | |
pull_request: | |
jobs: | |
build: | |
# To prevent this job from running, have "[skip ci]" or "[ci skip]" in the commit message | |
if: contains(toJson(github.event.commits), '[ci skip]') == false && contains(toJson(github.event.commits), '[skip ci]') == false | |
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 | |
with: | |
submodules: true | |
- name: Set up Python ${{ matrix.python-version }} on ${{ matrix.os }} | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- uses: actions/cache@v4 | |
if: startsWith(runner.os, 'Linux') | |
with: | |
path: ~/.cache/pip | |
key: ${{ runner.os }}-pip-${{ hashFiles('**/*requirements.txt') }} | |
- uses: actions/cache@v4 | |
if: startsWith(runner.os, 'macOS') | |
with: | |
path: ~/Library/Caches/pip | |
key: ${{ runner.os }}-pip-${{ hashFiles('**/*requirements.txt') }} | |
- uses: actions/cache@v4 | |
if: startsWith(runner.os, 'Windows') | |
with: | |
path: ~\AppData\Local\pip\Cache | |
key: ${{ runner.os }}-py${{ matrix.python-version }}-pip-${{ hashFiles('**/*requirements.txt') }} | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install numpy wheel | |
pip install -r requirements.txt | |
pip install -r dev-requirements.txt | |
# Note the use of the -Wa flag to show DeprecationWarnings | |
# We test the package as-installed. | |
- name: Unit tests | |
env: | |
MATERIALS_PROJECT_API_KEY: ${{ secrets.MATERIALS_PROJECT_API_KEY }} | |
run: | | |
pip install . | |
cd ~ | |
python -Wa -m pytest --pyargs crystals --full-trace | |
- name: Build documentation | |
run: | | |
python setup.py build_sphinx | |
- name: Doctests | |
run: | | |
python -m sphinx -b doctest docs build | |
python -m doctest README.md | |
- name: Build artifacts | |
run: | | |
python setup.py sdist bdist_wheel | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ runner.os }}-py${{ matrix.python-version }}-artifact | |
path: dist/* | |
retention-days: 7 | |
release: | |
needs: [build] | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/download-artifact@v4 | |
with: | |
path: artifacts/ | |
- name: Create release description | |
run: | | |
python release-description.py CHANGELOG.rst > description.md | |
cat description.md | |
- name: Move artifacts | |
run: | | |
ls --recursive artifacts/ | |
mkdir dist | |
mv --backup=numbered artifacts/*/** dist | |
rm -f dist/*~ | |
# Linux wheels cannot be uploaded to pypi | |
# https://peps.python.org/pep-0513/#rationale | |
rm -f dist/*linux**.whl | |
echo "To be uploaded:" | |
ls dist | |
- name: Create release | |
if: startsWith(github.ref, 'refs/tags/v') | |
uses: softprops/action-gh-release@v2 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
body_path: description.md | |
files: | | |
dist/* | |
- name: Upload to PyPI | |
if: startsWith(github.ref, 'refs/tags/v') | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
user: __token__ | |
password: ${{ secrets.PYPI_API_TOKEN }} |