-
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 6ba4a7e
Showing
9 changed files
with
233 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,93 @@ | ||
name: Setup Environment and Cache | ||
description: | | ||
A reusable composite action to setup the environment for a job. | ||
This action will: | ||
- Checkout the repository | ||
- Setup Python | ||
- Cache the pre-commit installation | ||
- Cache the virtual environment | ||
- Setup poetry | ||
- Install dependencies | ||
inputs: | ||
checkout-fetch-depth: | ||
description: | | ||
The depth of commits to fetch (passed to actions/checkout). | ||
0 fetches all history for all branches and tags. | ||
required: false | ||
default: 1 | ||
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: Checkout repo | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: ${{ inputs.checkout-fetch-depth }} | ||
- 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,93 @@ | ||
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: Run pre-commit checks on changed 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 the repo, setup python, and load cache | ||
uses: ./.github/actions/setup-env | ||
with: | ||
python-version: ${{ env.TARGET_PYTHON_VERSION }} | ||
# Full history likely required for planned commitizen checks | ||
# See #345 | ||
checkout-fetch-depth: 0 | ||
cache-pre-commit: true | ||
cache-venv: false | ||
setup-poetry: false | ||
- name: Run pre-commit checks on all files | ||
uses: pre-commit/action@v3.0.0 | ||
with: | ||
extra_args: --all-files | ||
integration-test: | ||
name: Run pytest on all supported python versions and operating systems | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: | ||
- macos-latest | ||
- ubuntu-latest | ||
python-version: ["3.8", "3.9", "3.10", "3.11"] | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- name: Checkout the repo, setup python, and load cache | ||
uses: ./.github/actions/setup-env | ||
with: | ||
checkout-fetch-depth: 0 | ||
python-version: ${{ matrix.python-version }} | ||
cache-pre-commit: false | ||
cache-venv: true | ||
setup-poetry: true | ||
install-deps: true | ||
# For the target version and ubuntu, run pytest and generate/upload coverage report | ||
- name: 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 | ||
- name: 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 | ||
# For every other version and/or OS, run only pytest | ||
- name: Run pytest | ||
if: (matrix.os != 'ubuntu-latest') || (matrix.python-version != env.TARGET_PYTHON_VERSION ) | ||
run: poetry run pytest |
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,42 @@ | ||
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: Setup base environment | ||
uses: ./.github/actions/setup-env | ||
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 that tag use to set the | ||
# version of the package. | ||
checkout-fetch-depth: 1 | ||
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.