Skip to content

Commit

Permalink
CI QOL update, including Publish package to PyPI on tag (#279)
Browse files Browse the repository at this point in the history
* Add CI step for publishing on release (#278) · Issues

* Add pytest options and code coverage dependencies

* Reorganise stages into build/deploy
Add timeout
Add code coverage step
Only deploy docs when tagged

* Exclude Adoni5, alexomics and matt from faqtory action

* Add parallel mode to coverage, to give files unique names

* Fix docs html upload artifact path

* Add fail under and skip empty to coverage reporting
  • Loading branch information
Adoni5 committed Oct 10, 2023
1 parent f128f4b commit d7cf756
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 37 deletions.
138 changes: 102 additions & 36 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ name: CI

on:
push:
branches: [refactor, main]
tags: ["*"]
schedule:
- cron: '0 0 * * SUN'
- cron: '0 8 * * MON'
pull_request:
branches:
- refactor
- main
types:
- closed
branches: [refactor, main]
workflow_dispatch:

env:
Expand All @@ -19,17 +17,20 @@ jobs:
pre_commit:
name: "🅿️ pre-commit"
runs-on: "ubuntu-latest"
timeout-minutes: 5
steps:
- uses: "actions/checkout@v4"
- uses: "actions/setup-python@v4"
with:
python-version: ${{env.PYTHON_LATEST}}
cache: pip
- uses: "pre-commit/action@v3.0.0"

tests:
name: "Test Python ${{ matrix.python-version }}"
runs-on: "ubuntu-latest"
needs: "pre_commit"
timeout-minutes: 5
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
Expand All @@ -38,56 +39,121 @@ jobs:
- uses: actions/setup-python@v4
with:
python-version: "${{ matrix.python-version }}"
cache: pip
- name: "Run tests"
run: |
set -xe
python -VV
python -m site
python -m pip install -U pip setuptools wheel
python -m pip install -e ".[dev]"
python -m pytest -sv --doctest-modules
python -m pip install -e ".[tests]"
coverage run -pm pytest
- name: Upload coverage data
uses: actions/upload-artifact@v3
with:
name: coverage-data
path: .coverage*
if-no-files-found: ignore

coverage:
name: Combine coverage
runs-on: ubuntu-latest
needs: tests

deploy-docs:
runs-on: ubuntu-22.04
needs: "pre_commit"
permissions:
contents: write
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_LATEST }}
cache: pip

- name: Setup Python
uses: actions/setup-python@v3
- name: Download coverage data
uses: actions/download-artifact@v3
with:
python-version: '3.8'
name: coverage-data

- name: Upgrade pip
- name: Combine coverage
run: |
# install pip=>20.1 to use "pip cache dir"
python3 -m pip install --upgrade pip
python -m pip install coverage[toml]
python -m coverage combine
python -m coverage report --skip-empty --fail-under=72 --format=markdown >> $GITHUB_STEP_SUMMARY
build-package:
name: Build python package
runs-on: ubuntu-latest
needs: tests
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_LATEST }}
cache: pip
- name: Build package
run: |
python -m pip install --upgrade pip
python -m pip install build
python -m build
- name: Upload built package
uses: actions/upload-artifact@v3
with:
name: built-package
path: dist/
if-no-files-found: error

- name: Get pip cache dir
id: pip-cache
run: echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
build-docs:
name: Build HTML docs
runs-on: ubuntu-latest
needs: "pre_commit"
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_LATEST }}
cache: pip

- name: Cache dependencies
uses: actions/cache@v3
- name: Build docs
run: |
python -m pip install .[docs]
cd docs
make html
- name: Upload built HTML
uses: actions/upload-artifact@v3
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }}
restore-keys: |
${{ runner.os }}-pip-
name: html-docs
path: docs/_build/html/
if-no-files-found: error


- name: Install dependencies
run: python3 -m pip install .[docs]
deploy:
name: Deploy docs and package
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags')
needs:
- build-docs
- build-package
environment:
name: PyPI
url: https://pypi.org/p/readfish
permissions:
id-token: write
contents: write

steps:
- name: Download HTML docs
uses: actions/download-artifact@v3
with:
name: html-docs
path: _build/html
- name: Download python package
uses: actions/download-artifact@v3
with:
name: built-package

- run: cd docs && make html
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

- name: Deploy
- name: Deploy docs to gh-pages branch
uses: peaceiris/actions-gh-pages@v3
if: github.event.pull_request.merged == true
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs/_build/html/
publish_dir: _build/html/
2 changes: 2 additions & 0 deletions .github/workflows/faqtory.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
types: [opened]
jobs:
add-comment:
# https://docs.github.com/en/actions/learn-github-actions/expressions#example-matching-an-array-of-strings
if: ${{ !contains(fromJSON('["alexomics", "Adoni5", "mattloose"]'), github.actor) }}
runs-on: ubuntu-latest
permissions:
issues: write
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ readfish = "readfish._cli_base:main"
[project.optional-dependencies]
# Development dependencies
docs = ["sphinx-copybutton", "furo", "myst-parser", "faqtory"]
tests = ["pytest"]
tests = ["pytest", "coverage[toml]"]
tests-mappy = ["readfish[tests,mappy,guppy]"]
dev = ["readfish[all,docs,tests]"]
# Running dependencies, this is a little bit clunky but works for now
Expand Down Expand Up @@ -82,3 +82,4 @@ testpaths = [
markers = [
"alignment: marks tests which rely on loading or using Mappy or Mappy-rs aligners, used to test with both. (deselect with '-m \"not slow\", select with '-k alignment')",
]
addopts = ["-ra", "--doctest-modules"]

0 comments on commit d7cf756

Please sign in to comment.