-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ci): refactor actions and add linting
- refactor: revise testing into unified integration pipeline - refactor: create re-usable setup-env action - feat: add pipeline support for poetry dynamic versioning - feat: add actionlint to pre-commit hooks.
- Loading branch information
1 parent
8483796
commit 7b7b533
Showing
9 changed files
with
238 additions
and
174 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
name: Setup Environment and Cache | ||
description: | | ||
A reusable composite action to setup the environment for a job. | ||
This action will: | ||
- Setup Python | ||
- Cache the pre-commit installation | ||
- Cache the virtual environment | ||
- Setup poetry | ||
- Install dependencies | ||
inputs: | ||
python-version: | ||
description: The version of Python to use (passed to actions/setup-python) | ||
required: true | ||
cache-pre-commit: | ||
description: Whether to cache the pre-commit installation | ||
required: false | ||
default: true | ||
cache-venv: | ||
description: Whether to cache the virtual environment | ||
required: false | ||
default: true | ||
setup-poetry: | ||
description: Whether to setup poetry | ||
required: false | ||
default: true | ||
install-deps: | ||
description: Whether to install dependencies | ||
required: false | ||
default: true | ||
runs: | ||
using: "composite" | ||
env: | ||
PRE_COMMIT_HOME: ${{ github.workspace }}/.cache/pre-commit | ||
POETRY_VIRTUALENVS_IN_PROJECT: "true" | ||
steps: | ||
- name: Set up Python ${{ inputs.python-version }} | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ inputs.python-version }} | ||
- name: Generate Cache Key PY | ||
# The cache key PY is a hash of the Python version and the | ||
# output of `pip freeze` (the installed packages). | ||
# This ensures that the cache is invalidated when the Python | ||
# version or the default packages change. Both of the remaining | ||
# cache keys depend on PY. | ||
shell: bash | ||
run: echo "PY=$((python -VV; pip freeze) | sha256sum | cut -d' ' -f1)" >> | ||
$GITHUB_ENV | ||
- name: Cache pre-commit installation | ||
# The cache key for the pre-commit installation is a hash of the | ||
# operating system, PY (see above), and the pre-commit config. | ||
# This allows for caching the pre-commit hook installation across | ||
# jobs and workflows. | ||
if: ${{ inputs.cache-pre-commit == 'true' }} | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
.cache | ||
pre-commit | ||
key: cache|${{ runner.os }}|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }} | ||
- name: Cache venv | ||
# The cache key for the virtual environment is a hash of the | ||
# operating system, PY (see above), the pyproject.toml and | ||
# the poetry.lock file. This allows for caching the virtual | ||
# environment with all the dependencies. | ||
if: ${{ inputs.cache-venv == 'true' }} | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
.cache | ||
.venv | ||
key: | ||
cache|${{ runner.os }}|${{ env.PY }}|${{ hashFiles('pyproject.toml') }}|${{ | ||
hashFiles('poetry.lock') }} | ||
- name: Setup poetry and poetry-dynamic-versioning | ||
if: ${{ inputs.setup-poetry == 'true' }} | ||
run: | | ||
python -m pip install poetry poetry-dynamic-versioning | ||
- name: Install dependencies with poetry | ||
if: ${{ inputs.install-deps == 'true' }} | ||
run: | | ||
poetry install --with dev,docs --all-extras -v --no-interaction |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
name: Integration Workflow | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: [main] | ||
tags: ["*"] | ||
workflow_dispatch: | ||
inputs: | ||
pytest_addopts: | ||
description: Extra options for pytest; use -vv for full details; see | ||
https://docs.pytest.org/en/latest/example/simple.html#how-to-change-command-line-options-defaults | ||
required: false | ||
default: "" | ||
|
||
env: | ||
LANG: "en_US.utf-8" | ||
LC_ALL: "en_US.utf-8" | ||
PIP_CACHE_DIR: ${{ github.workspace }}/.cache/pip | ||
POETRY_CACHE_DIR: ${{ github.workspace }}/.cache/pypoetry | ||
POETRY_VIRTUALENVS_IN_PROJECT: "true" | ||
PRE_COMMIT_HOME: ${{ github.workspace }}/.cache/pre-commit | ||
PYTEST_ADDOPTS: ${{ github.event.inputs.pytest_addopts }} | ||
PYTHONIOENCODING: "UTF-8" | ||
TARGET_PYTHON_VERSION: "3.9" | ||
|
||
jobs: | ||
quality-test: | ||
# This job is used to run pre-commit checks to ensure that all files are | ||
# are formatted correctly. | ||
name: Pre-commit checks | ||
# Runs pre-commit checks on all files | ||
# This job doesn't fail fast to ensure that feedback on function is still provided | ||
strategy: | ||
fail-fast: false | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@v4 | ||
with: | ||
# Full history likely required for planned commitizen checks | ||
# See #345 | ||
fetch-depth: 0 | ||
- name: Setup python, and check pre-commit cache | ||
uses: ./.github/actions/setup-env | ||
with: | ||
python-version: ${{ env.TARGET_PYTHON_VERSION }} | ||
cache-pre-commit: true | ||
cache-venv: false | ||
setup-poetry: false | ||
- name: Run pre-commit checks on all files | ||
uses: pre-commit/[email protected] | ||
with: | ||
extra_args: --all-files | ||
integration-test: | ||
name: Pytest (Python ${{ matrix.python-version }} on ${{ matrix.os }}) | ||
# Runs pytest on all tested versions of python and OSes | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: | ||
- macos-latest | ||
- ubuntu-latest | ||
python-version: ["3.8", "3.9", "3.10", "3.11"] | ||
runs-on: ${{ matrix.os }} | ||
env: | ||
OS: ${{ matrix.os }} | ||
# This is needed to avoid a warning from SQLAlchemy | ||
# https://sqlalche.me/e/b8d9 | ||
# We can remove this once we upgrade to SQLAlchemy >= 2.0 | ||
SQLALCHEMY_SILENCE_UBER_WARNING: "1" | ||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@v4 | ||
- name: Setup python, and load cache | ||
uses: ./.github/actions/setup-env | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
cache-pre-commit: false | ||
cache-venv: true | ||
setup-poetry: true | ||
install-deps: true | ||
- name: Run pytest and generate coverage report | ||
# For the target version and ubuntu, run pytest and generate coverage report | ||
if: (matrix.os == 'ubuntu-latest') && (matrix.python-version == env.TARGET_PYTHON_VERSION) | ||
run: poetry run pytest --cov=./ --cov-report=xml ${{ github.event.inputs.pytest_addopts }} | ||
- name: Upload coverage to Codecov | ||
# For the target version and ubuntu, upload coverage to Codecov | ||
continue-on-error: true | ||
if: (matrix.os == 'ubuntu-latest') && (matrix.python-version == env.TARGET_PYTHON_VERSION ) | ||
uses: codecov/codecov-action@v3 | ||
env: | ||
OS: ${{ matrix.os }} | ||
PYTHON: ${{ matrix.python-version }} | ||
with: | ||
file: ./coverage.xml | ||
files: ./coverage1.xml,./coverage2.xml | ||
directory: ./coverage/reports/ | ||
env_vars: OS,PYTHON | ||
fail_ci_if_error: true | ||
flags: unittests | ||
name: pycytominer | ||
- name: Run pytest | ||
# For every other version and/or OS, run pytest without coverage | ||
if: (matrix.os != 'ubuntu-latest') || (matrix.python-version != env.TARGET_PYTHON_VERSION ) | ||
run: poetry run pytest ${{ github.event.inputs.pytest_addopts }} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
name: Publish Python 🐍 distributions 📦 to PyPI and TestPyPI | ||
on: [release] | ||
|
||
env: | ||
LANG: "en_US.utf-8" | ||
LC_ALL: "en_US.utf-8" | ||
PYTHONIOENCODING: "UTF-8" | ||
TARGET_PYTHON_VERSION: "3.9" | ||
|
||
jobs: | ||
build-and-publish: | ||
name: Build and publish Python 🐍 distributions | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@v4 | ||
with: | ||
# We do not need to fetch all the history of the repository | ||
# as commit being released is guaranteed to have a tag. | ||
# poetry-dynamic-versioning will use that tag use to set the | ||
# build version of the package. | ||
fetch-depth: 1 | ||
- name: Setup base environment | ||
uses: ./.github/actions/setup-env | ||
with: | ||
python-version: ${{ env.TARGET_PYTHON_VERSION }} | ||
cache-pre-commit: false | ||
cache-venv: false | ||
setup-poetry: true | ||
install-deps: false | ||
- name: Build 📦 distributions | ||
run: | | ||
poetry build | ||
- name: Publish any distribution 📦 to Test PyPI | ||
uses: pypa/gh-action-pypi-publish@release/v1 | ||
with: | ||
user: __token__ | ||
repository-url: https://test.pypi.org/legacy/ | ||
password: ${{ secrets.TEST_PYPI_API_TOKEN }} | ||
- name: Publish tagged distribution 📦 to PyPI | ||
uses: pypa/gh-action-pypi-publish@release/v1 | ||
if: startsWith(github.ref, 'refs/tags') | ||
with: | ||
user: __token__ | ||
password: ${{ secrets.PYPI_API_TOKEN }} |
Oops, something went wrong.