Skip to content

Commit

Permalink
Add GitHub CI Checks
Browse files Browse the repository at this point in the history
  • Loading branch information
omad committed Nov 19, 2024
1 parent 4951659 commit ea47b64
Show file tree
Hide file tree
Showing 5 changed files with 191 additions and 5 deletions.
30 changes: 30 additions & 0 deletions .github/actions/setup-python-env/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: "Setup Python Environment"
description: "Set up Python environment for the given Python version"

inputs:
python-version:
description: "Python version to use"
required: true
default: "3.12"
uv-version:
description: "uv version to use"
required: true
default: "0.5.2"

runs:
using: "composite"
steps:
- uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}

- name: Install uv
uses: astral-sh/setup-uv@v2
with:
version: ${{ inputs.uv-version }}
enable-cache: 'true'
cache-suffix: ${{ matrix.python-version }}

- name: Install Python dependencies
run: uv sync --frozen
shell: bash
50 changes: 50 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Main

on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened, ready_for_review]

jobs:
quality:
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v4

- uses: actions/cache@v4
with:
path: ~/.cache/pre-commit
key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}

- name: Set up the environment
uses: ./.github/actions/setup-python-env

- name: Run checks
run: make check

tests-and-type-check:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12", "3.13"]
fail-fast: false
defaults:
run:
shell: bash
steps:
- name: Check out
uses: actions/checkout@v4

- name: Set up the environment
uses: ./.github/actions/setup-python-env
with:
python-version: ${{ matrix.python-version }}

- name: Run tests
run: uv run python -m pytest tests

- name: Check typing
run: uv run mypy
44 changes: 44 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
.PHONY: install
install: ## Install the virtual environment and install the pre-commit hooks
@echo "🚀 Creating virtual environment using uv"
@uv sync
@uv run pre-commit install

.PHONY: check
check: ## Run code quality tools.
@echo "🚀 Checking lock file consistency with 'pyproject.toml'"
@uv lock --locked
@echo "🚀 Linting code: Running pre-commit"
@uv run pre-commit run -a
@echo "🚀 Static type checking: Running mypy"
@uv run mypy

.PHONY: test
test: ## Test the code with pytest
@echo "🚀 Testing code: Running pytest"
@uv run python -m pytest --doctest-modules

.PHONY: build
build: clean-build ## Build wheel file
@echo "🚀 Creating wheel file"
@uvx --from build pyproject-build --installer uv

.PHONY: clean-build
clean-build: ## Clean build artifacts
@echo "🚀 Removing build artifacts"
@uv run python -c "import shutil; import os; shutil.rmtree('dist') if os.path.exists('dist') else None"

.PHONY: publish
publish: ## Publish a release to PyPI.
@echo "🚀 Publishing."
@uvx twine upload --repository-url https://upload.pypi.org/legacy/ dist/*

.PHONY: build-and-publish
build-and-publish: build publish ## Build and publish.

.PHONY: help
help:
@uv run python -c "import re; \
[[print(f'\033[36m{m[0]:<20}\033[0m {m[1]}') for m in re.findall(r'^([a-zA-Z_-]+):.*?## (.*)$$', open(makefile).read(), re.M)] for makefile in ('$(MAKEFILE_LIST)').strip().split()]"

.DEFAULT_GOAL := help
9 changes: 4 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies = [
"pandas",
"toolz",
"xarray>=0.19",
"coverage>=7.6.7",
]
classifiers = [
"License :: OSI Approved :: Apache Software License",
Expand Down Expand Up @@ -50,12 +51,9 @@ include = ["odc.loader"]
python_version = "3.10"
ignore_missing_imports = true
allow_redefinition = true
explicit_package_bases = true # work with the 'odc' namespace package
files = ["odc"]

[tool.coverage.run]
omit = [
"tests/*",
"*/test_*"
]

[tool.isort]
profile = "black"
Expand All @@ -76,6 +74,7 @@ disable = [

[dependency-groups]
dev = [
"coverage>=7.6.7",
"geopandas>=1.0.1",
"mypy>=1.13.0",
"pytest>=8.3.3",
Expand Down
63 changes: 63 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ea47b64

Please sign in to comment.