Continuous Integration #140
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
# ci.yml | |
# | |
# Continuous Integration for Chemprop - checks build, code formatting, and runs tests for all | |
# proposed changes and on a regular schedule | |
# | |
# Note: this file contains extensive inline documentation to aid with knowledge transfer. | |
name: Continuous Integration | |
on: | |
# run on pushes/pull requests to/against main | |
push: | |
branches: [main] | |
pull_request: | |
branches: [main] | |
# run this in the morning on weekdays to catch dependency issues | |
schedule: | |
- cron: "0 8 * * 1-5" | |
# allow manual runs | |
workflow_dispatch: | |
# cancel previously running tests if new commits are made | |
# https://docs.github.com/en/actions/examples/using-concurrency-expressions-and-a-test-matrix | |
concurrency: | |
group: actions-id-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
cancel-in-progress: true | |
jobs: | |
build: | |
name: Check Build | |
runs-on: ubuntu-latest | |
steps: | |
# clone the repo, attempt to build | |
- uses: actions/checkout@v4 | |
- run: python -m pip install build | |
- run: python -m build . | |
lint: | |
name: Check Formatting | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
# clone the repo, run black and flake8 on it | |
- uses: actions/checkout@v4 | |
- run: python -m pip install black==23.* flake8 | |
- run: black --check . | |
- run: flake8 . | |
test: | |
name: Execute Tests | |
needs: lint | |
runs-on: ${{ matrix.os }} | |
defaults: | |
run: | |
# run with a login shell (so that the conda environment is activated) | |
# and echo the commands we run as we do them (for debugging purposes) | |
shell: bash -el {0} | |
strategy: | |
# if one platform/python version fails, continue testing the others | |
fail-fast: false | |
matrix: | |
# test on all platforms with both supported versions of Python | |
os: [ubuntu-latest, macos-13, windows-latest] | |
python-version: [3.11, 3.12] | |
steps: | |
- uses: actions/checkout@v4 | |
# use a version of the conda virtual environment manager to set up an | |
# isolated environment with the Python version we want | |
- uses: mamba-org/setup-micromamba@main | |
with: | |
environment-name: temp | |
condarc: | | |
channels: | |
- defaults | |
- conda-forge | |
channel_priority: flexible | |
create-args: | | |
python=${{ matrix.python-version }} | |
- name: Install dependencies | |
shell: bash -l {0} | |
run: | | |
python -m pip install nbmake | |
python -m pip install ".[dev,docs,test]" | |
- name: Install hyperopt optional dependencies (Python 3.11 only) | |
if: ${{ matrix.python-version == '3.11' }} | |
run: | | |
python -m pip install ".[hpopt]" | |
- name: Test with pytest | |
shell: bash -l {0} | |
run: | | |
# specifically disable running on GPU, otherwise Lightning will attempt to use the Apple GPU | |
# that the GitHub actions runners still have but are not allowed to actually use | |
pytest -v tests | |
- name: Test notebooks | |
shell: bash -l {0} | |
run: | | |
pytest --nbmake examples/training.ipynb | |
pytest --nbmake examples/predicting.ipynb | |
pytest --nbmake examples/convert_v1_to_v2.ipynb | |
pytest --nbmake examples/training_regression_multicomponent.ipynb | |
pytest --nbmake examples/predicting_regression_multicomponent.ipynb | |
conda-test: | |
name: Execute Tests with Conda-based Install | |
needs: lint | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
# run with a login shell (so that the conda environment is activated) | |
# and echo the commands we run as we do them (for debugging purposes) | |
shell: bash -el {0} | |
strategy: | |
# if one platform/python version fails, continue testing the others | |
fail-fast: false | |
matrix: | |
python-version: [3.11, 3.12] | |
steps: | |
- uses: actions/checkout@v4 | |
# use a version of the conda virtual environment manager to set up an | |
# isolated environment with the Python version we want | |
- uses: mamba-org/setup-micromamba@main | |
with: | |
environment-file: environment.yml | |
condarc: | | |
channels: | |
- defaults | |
- conda-forge | |
- pytorch | |
channel_priority: flexible | |
create-args: | | |
python=${{ matrix.python-version }} | |
- name: Install Testing Dependencies | |
run: conda install -c conda-forge pytest>=6.2 pytest-cov | |
- name: Install Chemprop | |
run: python -m pip install . --no-deps | |
- name: Test with pytest | |
shell: bash -l {0} | |
run: | | |
pytest -v tests | |
pypi: | |
name: Build and publish Python 🐍 distributions 📦 to PyPI | |
runs-on: ubuntu-latest | |
# only run if the tests pass | |
needs: [test, conda-test] | |
# run only on pushes to main on chemprop | |
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository == 'chemprop/chemprop'}} | |
steps: | |
- uses: actions/checkout@master | |
- name: Set up Python 3.12 | |
uses: actions/setup-python@v3 | |
with: | |
python-version: "3.11" | |
- name: Install pypa/build | |
run: >- | |
python -m | |
pip install | |
build | |
--user | |
- name: Build a binary wheel and a source tarball | |
run: >- | |
python -m | |
build | |
--sdist | |
--wheel | |
--outdir dist/ | |
. | |
- name: Publish distribution 📦 to PyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
password: ${{ secrets.PYPI_API_TOKEN }} | |
skip-existing: true | |
verbose: true | |
build-and-push-docker: | |
# shamelessly copied from: | |
# https://github.com/ReactionMechanismGenerator/RMG-Py/blob/bfaee1cad9909a17103a8e6ef9a22569c475964c/.github/workflows/CI.yml#L359C1-L386C54 | |
# which is also shamelessly copied from somewhere | |
runs-on: ubuntu-latest | |
# only run if the tests pass | |
needs: [test, conda-test] | |
# run only on pushes to main on chemprop | |
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository == 'chemprop/chemprop'}} | |
steps: | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
# repository secretes managed by the maintainers | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Build and Push | |
uses: docker/build-push-action@v4 | |
with: | |
push: true | |
tags: chemprop/chemprop:latest | |