CI-CD #39
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: | |
create: | |
tags: | |
- '^v[0-9]+.[0-9]+.[0-9]+(?:.dev[0-9])?$' | |
workflow_dispatch: | |
inputs: | |
py-act: | |
description: 'Python 3.X for GH Actions' | |
required: false | |
default: '3.8' | |
pip_opts: | |
description: Install options (pip) | |
required: false | |
default: '--upgrade --upgrade-strategy eager' | |
env: | |
ACTIONS_SETUP_PY3: ${{ github.event.inputs.py-act || '3.8' }} | |
PIP_INSTALL_OPTS: ${{ github.event.inputs.pip_opts || '--upgrade --upgrade-strategy eager' }} | |
PY_COLORS: 1 | |
GHCR: ghcr.io | |
DOCKER_IMAGE: sbrg/pymodulon | |
jobs: | |
test: | |
runs-on: ${{ matrix.os }} | |
name: Test code (Python ${{ matrix.py }} - ${{ matrix.os }}) | |
strategy: | |
max-parallel: 3 | |
fail-fast: true | |
matrix: | |
os: [ubuntu-latest] | |
py: [3.6, 3.7, 3.8] | |
steps: | |
- | |
name: Checkout repository | |
id: checkout | |
uses: actions/checkout@v2 | |
- | |
name: Set up Python ${{ matrix.py }} | |
id: setup | |
uses: actions/setup-python@v2 | |
with: | |
python-version: ${{ matrix.py }} | |
- | |
name: Set Python ${{ matrix.py }} cache | |
id: cache | |
uses: actions/cache@v2 | |
with: | |
path: ${{ env.pythonLocation }} | |
key: ${{ runner.os }}-pydeps-${{ env.pythonLocation }}-${{ hashFiles('setup.cfg') }}-${{ hashFiles('pyproject.toml') }} | |
- | |
name : Install dependencies | |
id: install-deps | |
run: | | |
python -m pip install ${{ env.PIP_INSTALL_OPTS }} pip setuptools tox tox-gh-actions coverage[toml] | |
sudo apt-get install ncbi-blast+ | |
- | |
name: Run tests via tox | |
id: run-tox | |
run: | | |
python -m tox | |
- | |
name: Generate an XML report of coverage results | |
id: cov-report-xml | |
run: | | |
python -m coverage xml | |
- | |
name: Upload coverage report to Codecov.io | |
id: codecov-upload | |
uses: codecov/codecov-action@v1 | |
with: | |
name: "py${{ matrix.py }}-${{ matrix.os }}" | |
token: ${{ secrets.CODECOV_TOKEN }} | |
fail_ci_if_error: true | |
docs: | |
runs-on: ubuntu-latest | |
name: Check documentation | |
steps: | |
- | |
name: Checkout | |
id: checkout | |
uses: actions/checkout@v2 | |
- | |
name: Set up Python ${{ env.ACTIONS_SETUP_PY3 }} | |
id: setup | |
uses: actions/setup-python@v2 | |
with: | |
python-version: ${{ env.ACTIONS_SETUP_PY3 }} | |
- | |
name: Set Python ${{ env.ACTIONS_SETUP_PY3 }} cache | |
id: cache | |
uses: actions/cache@v2 | |
with: | |
path: | | |
${{ env.pythonLocation }} | |
key: ${{ runner.os }}-pydeps-${{ env.pythonLocation }}-${{ hashFiles('setup.cfg') }}-${{ hashFiles('pyproject.toml') }} | |
- | |
name : Install dependencies | |
id: install-deps | |
run: | | |
python -m pip install ${{ env.PIP_INSTALL_OPTS }} pip setuptools tox | |
- | |
name: Set up pandoc | |
id: pandoc | |
uses: r-lib/actions/setup-pandoc@v1 | |
- | |
name: Run additional checks via tox | |
id: run-tox | |
run: | | |
python -m tox -e "docs, pypi-description" | |
publish-pypi: | |
needs: [test, docs] | |
runs-on: ubuntu-latest | |
name: Publish package to Python Packaging Index (PyPi) | |
if: startsWith(github.ref, 'refs/tags/v') | |
steps: | |
- | |
name: Checkout | |
id: checkout | |
uses: actions/checkout@v2 | |
- | |
name: Set up Python | |
id: setup | |
uses: actions/setup-python@v2 | |
with: | |
python-version: ${{ env.ACTIONS_SETUP_PY3 }} | |
- | |
name: Set Python ${{ env.ACTIONS_SETUP_PY3 }} cache | |
id: cache | |
uses: actions/cache@v2 | |
with: | |
path: ${{ env.pythonLocation }} | |
key: ${{ runner.os }}-pydeps-${{ env.pythonLocation }}-${{ hashFiles('setup.cfg') }}-${{ hashFiles('pyproject.toml') }} | |
- | |
name : Install dependencies | |
id: install-deps | |
run: | | |
python -m pip install ${{ env.PIP_INSTALL_OPTS }} pip setuptools wheel build | |
- | |
name: Build package | |
id: build | |
run: | | |
python -m build -s -w . | |
- | |
name: Publish package to Test PyPI | |
id: test-publish | |
uses: pypa/gh-action-pypi-publish@master | |
with: | |
user: __token__ | |
password: ${{ secrets.SBRG_MACHINE_PYPI_TEST_TOKEN }} | |
repository_url: https://test.pypi.org/legacy/ | |
skip_existing: true | |
- | |
name: Publish package to PyPI | |
id: publish | |
uses: pypa/gh-action-pypi-publish@master | |
with: | |
user: __token__ | |
password: ${{ secrets.SBRG_MACHINE_PYPI_TOKEN }} | |
push-to-registries: | |
needs: [publish-pypi] | |
name: Build and push Docker images to registries | |
runs-on: ubuntu-latest | |
if: startsWith(github.ref, 'refs/tags/v') | |
steps: | |
- | |
name: Checkout | |
id: checkout | |
uses: actions/checkout@v2 | |
- | |
name: Docker meta | |
id: docker-meta | |
uses: crazy-max/ghaction-docker-meta@v1 | |
with: | |
images: | | |
${{ env.DOCKER_IMAGE }} | |
${{ env.GHCR }}/${{ env.DOCKER_IMAGE }} | |
tag-sha: true | |
tag-match: '^v[0-9]+.[0-9]+.[0-9]+(?:.dev[0-9])?$' | |
# e.g., v{MAJOR}.{MINOR}.{PATCH}(.dev{}) | |
- | |
name: Set up Docker Buildx | |
id: docker-buildx-setupx | |
uses: docker/setup-buildx-action@v1 | |
- | |
name: Login to DockerHub | |
id: docker-login | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.SBRG_MACHINE_DOCKERHUB_USERNAME }} | |
password: ${{ secrets.SBRG_MACHINE_DOCKERHUB_TOKEN }} | |
- | |
name: Login to GitHub Container Registry | |
id: ghcr-login | |
uses: docker/login-action@v1 | |
with: | |
registry: ${{ env.GHCR }} | |
username: ${{ secrets.SBRG_MACHINE_GHCR_USERNAME }} | |
password: ${{ secrets.SBRG_MACHINE_GHCR_TOKEN }} | |
- | |
name: Build and push image to registry | |
id: docker-build-push | |
uses: docker/build-push-action@v2 | |
with: | |
file: Dockerfile | |
push: true | |
tags: ${{ steps.docker-meta.outputs.tags }} |