Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 72 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ jobs:

strategy:
matrix:
os: [ubuntu, macos, windows]
python: ["3.10", "3.11", "3.12"]
include:
- os: ubuntu
python: "3.8"
- os: ubuntu
python: "3.9"
# TODO: implement windows
# os: [ubuntu, macos, windows]
os: [windows]
# TODO: put back 3.11, 3.12
# python: ["3.10", "3.11", "3.12"]
python: ["3.10"]
# TODO: put back 3.8, 3.9
# include:
# - os: ubuntu
# python: "3.8"
# - os: ubuntu
# python: "3.9"

steps:
- uses: actions/checkout@v4
Expand All @@ -39,14 +44,46 @@ jobs:
pandoc-version: "2.9.2"
- name: Install tox
run: python -m pip install -U pip tox
- name: Install pdm
run: |
pdm install --dev
pdm config python.use_venv false
- name: Set up dependencies with invoke
run: |
python -m pip install invoke
python -m invoke setup
echo "== PYTHON after setup =="
python --version
python -c "import pytest"
- name: Info
run: |
echo "===== PYTHON ====="
python --version
echo "===== PANDOC ====="
pandoc --version | head -2
- name: Run tests
run: tox -e py${{ matrix.python }}
- name: Run tests with coverage
run: |
python -m pytest --cov=pelican
ls -l .coverage.*
env:
# control the filename to avoid issues with uploading
# see also https://github.com/actions/upload-artifact/issues/478#issuecomment-2096976037
COVERAGE_FILE: .coverage.${{ matrix.os }}.${{ matrix.python }}.${{ github.event_name }}
- name: Upload coverage data
uses: "actions/upload-artifact@v4"
with:
name: coverage-data
path: ".coverage.${{ matrix.os }}.${{ matrix.python }}.${{ github.event_name }}"
if-no-files-found: error

# see https://github.com/actions/upload-artifact/blob/main/merge/README.md#combining-all-artifacts-in-a-workflow-run
merge:
runs-on: ubuntu-latest
# needs the upload-artifact action to have been run
needs: test
steps:
- name: Merge Artifacts
uses: actions/upload-artifact/merge@v4

lint:
name: Lint
Expand All @@ -66,6 +103,32 @@ jobs:
- name: Run pre-commit checks on all files
uses: pre-commit/action@v3.0.1

coverage:
runs-on: "ubuntu-latest"
needs: merge
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
cache: "pip"
cache-dependency-path: "**/requirements/*"

- name: "Install Coverage.py"
run: "python -m pip install --upgrade coverage[toml]"

- name: "Download coverage data"
uses: actions/download-artifact@v4
with:
name: coverage-data

- name: "Combine & check coverage"
run: |
set -xe
python -m coverage combine
python -m coverage report --fail-under=74

build:
name: Test build
runs-on: ubuntu-latest
Expand Down
34 changes: 25 additions & 9 deletions tasks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import sys
from pathlib import Path
from shutil import which

Expand All @@ -15,9 +16,21 @@
VENV = str(VENV_PATH.expanduser())
VENV_BIN = Path(VENV) / Path(BIN_DIR)

PYTHON = which("python")

TOOLS = ["pdm", "pre-commit", "psutil"]
PDM = which("pdm") or VENV_BIN / "pdm"
PRECOMMIT = which("pre-commit") or VENV_BIN / "pre-commit"


def _get_pdm_path():
return which("pdm") or VENV_BIN / "pdm"


def _get_precommit_path():
return which("pre-commit") or VENV_BIN / "pre-commit"


def _get_coverage_path():
return which("coverage")


@task
Expand All @@ -41,14 +54,14 @@ def docserve(c):
@task
def tests(c):
"""Run the test suite"""
c.run(f"{VENV_BIN}/pytest", pty=PTY)
c.run(f"{PYTHON} -m pytest", pty=PTY)


@task
def coverage(c):
"""Generate code coverage of running the test suite."""
c.run(f"{VENV_BIN}/pytest --cov=pelican", pty=PTY)
c.run(f"{VENV_BIN}/coverage html", pty=PTY)
c.run(f"{PYTHON} -m pytest --cov=pelican", pty=PTY)
c.run(f"{PYTHON} -m coverage html", pty=PTY)


@task
Expand Down Expand Up @@ -87,20 +100,23 @@ def tools(c):
"""Install tools in the virtual environment if not already on PATH"""
for tool in TOOLS:
if not which(tool):
c.run(f"{VENV_BIN}/python -m pip install {tool}", pty=PTY)
c.run(f"{PYTHON} -m pip install {tool}", pty=PTY)


@task
def precommit(c):
"""Install pre-commit hooks to .git/hooks/pre-commit"""
c.run(f"{PRECOMMIT} install", pty=PTY)
precommt = _get_precommit_path()
c.run(f"{precommt} install", pty=PTY)


@task
def setup(c):
c.run(f"{VENV_BIN}/python -m pip install -U pip", pty=PTY)
c.run(f"{PYTHON} -m pip install -U pip", pty=PTY)
tools(c)
c.run(f"{PDM} install", pty=PTY)
pdm = _get_pdm_path()
print(f"***** running {pdm} install", file=sys.stderr) # noqa: T201
c.run(f"{pdm} install -v", pty=PTY, echo=True)
precommit(c)


Expand Down