Skip to content

Commit

Permalink
feat(ci,release): refactor github actions into unified ci pipeline
Browse files Browse the repository at this point in the history
These revised github actions pipelines are modeled after https://github.com/copier-org/copier/blob/23f93660e7a13c521d66f2c6a1e81dd50c4d7148/.github/workflows/ci.yml. They also include changes needed to support poetry-dynamic-versioning
  • Loading branch information
kenibrewer committed Oct 27, 2023
1 parent dc4ae98 commit b34d772
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 173 deletions.
98 changes: 98 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: CI

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:
build:
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:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Needs all tags to compute dynamic version
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Generate Cache Key PY
shell: bash
run:
echo "PY=$((python -VV; pip freeze) | sha256sum | cut -d' ' -f1)" >>
$GITHUB_ENV
- name: Cache venv
uses: actions/cache@v3
with:
path: |
.cache
.venv
key:
cache|${{ runner.os }}|${{ env.PY }}|${{ hashFiles('pyproject.toml') }}|${{
hashFiles('poetry.lock') }}|${{ hashFiles('.pre-commit-config.yaml') }}
- name: Install dependencies
run: |
python -m pip install poetry poetry-dynamic-versioning
poetry install --with dev,docs --all-extras -v --no-interaction
- name: Run pytest
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

pre-commit-ci:
name: Run pre-commit checks on changed files
strategy:
fail-fast: false
runs-on: ubuntu-latest
steps:
- name: Checkout repo with all branches and tags
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python ${{ env.TARGET_PYTHON_VERSION }}
uses: actions/setup-python@v4
with:
python-version: ${{ env.TARGET_PYTHON_VERSION }}
- name: Run pre-commit checks on any files changed between base_ref and HEAD
uses: pre-commit/action@v3.0.0
with:
extra_args: --from-ref origin/${{github.base_ref}} --to-ref HEAD
66 changes: 0 additions & 66 deletions .github/workflows/codecov.yml

This file was deleted.

22 changes: 0 additions & 22 deletions .github/workflows/pre-commit-ci.yml

This file was deleted.

20 changes: 0 additions & 20 deletions .github/workflows/publish-to-pypi.yml

This file was deleted.

65 changes: 0 additions & 65 deletions .github/workflows/pytest.yml

This file was deleted.

58 changes: 58 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Publish Python 🐍 distributions 📦 to PyPI and TestPyPI
on: [release]

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
PYTHONIOENCODING: "UTF-8"
TARGET_PYTHON_VERSION: "3.10"

jobs:
build-and-publish:
name: Build and publish Python 🐍 distributions
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️ repo with history
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python 🐍 ${{ env.TARGET_PYTHON_VERSION }}
uses: actions/setup-python@v4
with:
python-version: ${{ env.TARGET_PYTHON_VERSION }}
- name: Generate cache key PY
run:
echo "PY=$((python -VV; pip freeze) | sha256sum | cut -d' ' -f1)" >>
$GITHUB_ENV
- name: Cache
uses: actions/cache@v3
with:
path: |
.cache
.venv
key:
cache|${{ runner.os }}|${{ env.PY }}|${{ hashFiles('pyproject.toml') }}|${{
hashFiles('poetry.lock') }}|${{ hashFiles('.pre-commit-config.yaml') }}
- name: Install 📦 dependencies
shell: bash
run: |
python -m pip install poetry poetry-dynamic-versioning
- 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 }}

0 comments on commit b34d772

Please sign in to comment.