Skip to content

Commit

Permalink
Updates to GitHub Actions/Workflows (#151)
Browse files Browse the repository at this point in the history
- Updates to GH Actions and pre-commit hooks
- Enable caching of pip reqs
- Enable code coverage generation and reporting
- Removed unused workflow files
- Update README to add badges
- Re-enable pip-compile hook; regenerate requirements.txt
- Remove requirements_dev.txt; not used
  • Loading branch information
tchamberlin authored Dec 5, 2023
1 parent 5793e0b commit ab608b3
Show file tree
Hide file tree
Showing 18 changed files with 665 additions and 228 deletions.
31 changes: 0 additions & 31 deletions .github/workflows/build.yml

This file was deleted.

86 changes: 86 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: CI
on:
push:
branches:
- "main"
- "release*"
- "*-devel"
- "*_devel"
- "*-ci"
- "*_ci"
pull_request: # Run on all pull requests
workflow_dispatch: # needed for "Run" button to show up in action
env:
FORCE_COLOR: "1" # Make tools pretty.
PIP_DISABLE_PIP_VERSION_CHECK: "1"
PIP_NO_PYTHON_VERSION_WARNING: "1"

jobs:
tests:
runs-on: ${{ matrix.os }}

strategy:
# Ensure that if even if a build in the matrix fails, the others continue
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ["3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
# Enable caching of pip packages between workflow jobs. This can speed things up dramatically, _if_
# jobs are executed fairly close together in time
# See: https://github.com/actions/setup-python/blob/main/docs/advanced-usage.md#caching-packages
cache: 'pip'
cache-dependency-path: 'requirements.txt'
- name: Install dependencies
run: |
# Install requirements, as compiled by pip-compile
pip install -r requirements.txt
# Install dysh itself, in editable mode (which is required to avoid breaking the caching mechanism above)
pip install -e .
- name: Test with pytest
run: |
# Write coverage data files, namespaced using matrix info
coverage run --data-file=".coverage.${{ matrix.os }}.${{ matrix.python-version }}" -m pytest
- name: Upload coverage data
# Upload only ubuntu results, since we are only running the coverage step on ubuntu
if: matrix.os == 'ubuntu-latest'
uses: actions/upload-artifact@v3
with:
name: coverage-data
path: ".coverage.ubuntu-latest*"
coverage:
needs: tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: 3.9
cache: pip
- run: pip install --upgrade coverage[toml]
- uses: actions/download-artifact@v3
with:
name: coverage-data
- name: Combine coverage
run: |
coverage combine
coverage html --skip-covered --skip-empty
# Report and write to summary.
coverage report | sed 's/^/ /' >> $GITHUB_STEP_SUMMARY
# Report again and fail if under 100%.
# coverage report --fail-under=100
- name: Upload HTML report
uses: actions/upload-artifact@v3
with:
name: html-report
path: htmlcov
40 changes: 0 additions & 40 deletions .github/workflows/hatch-and-pytest.yml

This file was deleted.

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

This file was deleted.

38 changes: 0 additions & 38 deletions .github/workflows/pyinstaller.yml

This file was deleted.

15 changes: 6 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,22 @@ jobs:
environment: release
permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
# See: https://github.com/pypa/gh-action-pypi-publish#trusted-publishing
id-token: write
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: ["3.x"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
python-version: '3.9' # Should always be the minimum supported Python version
cache: 'pip'
cache-dependency-path': 'requirements.txt'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -e .
- name: Build with hatch
run: |
hatch build -c
hatch build --clean
- name: upload release to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
16 changes: 0 additions & 16 deletions .github/workflows/workflow.yml

This file was deleted.

15 changes: 6 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,39 +1,36 @@
---
# See https://pre-commit.com for more information
default_language_version:
python: python3.10
python: python3.9

# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: 'https://github.com/pre-commit/pre-commit-hooks'
rev: v4.4.0
rev: v4.5.0
hooks:
- id: trailing-whitespace
exclude: '(notebooks|attic|benchmark|testdata)/.*'
- id: end-of-file-fixer
exclude: LICENSE
- id: check-yaml
- id: check-toml
- id: check-added-large-files
args:
- '--maxkb=1024'
- id: debug-statements
- id: detect-private-key
- id: mixed-line-ending
args:
- '--fix=lf'
- id: check-docstring-first
- id: check-case-conflict # Check for files with names that would conflict on a case-insensitive filesystem
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
exclude: '(notebooks|attic|benchmark|testdata)/.*'
- repo: 'https://github.com/psf/black'
rev: 23.1.0
rev: 23.11.0
hooks:
- id: black
exclude: '(notebooks|attic|benchmark|testdata)/.*'
# - repo: https://github.com/jazzband/pip-tools
# rev: 6.12.3
# hooks:
# - id: pip-compile
# args:
# - '--resolver=backtracking'
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
[![Documentation Status](https://readthedocs.org/projects/dysh/badge/?version=latest)](https://dysh.readthedocs.io/en/latest/?badge=latest)
[![pre-commit.ci Status](https://results.pre-commit.ci/badge/github/GreenBankObservatory/dysh/main.svg)](https://results.pre-commit.ci/latest/github/GreenBankObservatory/dysh/main)
[![CI Workflow Build Status](https://github.com/GreenBankObservatory/dysh/actions/workflows/ci.yml/badge.svg)](https://github.com/GreenBankObservatory/dysh/actions/workflows/ci.yml)

# dysh

Expand Down
19 changes: 18 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ dependencies = [

[project.optional-dependencies]
dev = [
"coverage[toml]",
"ipdb",
"numpydoc",
"pytest",
Expand Down Expand Up @@ -81,7 +82,7 @@ docs-build = "sphinx-build {root}/docs/source {root}/docs/build -b html {args}"
# run via: $ hatch run test:<script>
[tool.hatch.envs.test.scripts]
matrix = "pytest {args}"
cov = "pytest --cov-report=term-missing --cov-config=pyproject.toml --cov=src/dysh --cov=tests {args}"
cov = "pytest --cov-report=xml --cov-config=pyproject.toml --cov=src/dysh --cov=tests {args}"

# Run tests across all supported version of Python
[[tool.hatch.envs.test.matrix]]
Expand All @@ -105,10 +106,16 @@ exclude = [
packages = ["src/dysh"]

[tool.coverage.run]

branch = true
source = [
"src/"
]
parallel = true
omit = [
"src/dysh/__about__.py",
"*/tests/*",
"test_*.py"
]

[tool.coverage.report]
Expand Down Expand Up @@ -154,6 +161,7 @@ ignore = [
"E741", # ambiguous-variable-name
]
line-length = 120
src = ["src", "benchmark", "notebooks"]

[tool.ruff.per-file-ignores]
# Ignore in all `__init__.py` files
Expand All @@ -169,6 +177,15 @@ filterwarnings = [
"ignore::DeprecationWarning"
]

[tool.pip-tools]
src_files = ["pyproject.toml"]
extra = ["nb", "dev"]
resolver = "backtracking"
output_file= "requirements.txt"
no_strip_extras = true
quiet = true
no_emit_trusted_host = true

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
Loading

0 comments on commit ab608b3

Please sign in to comment.