Skip to content

Commit

Permalink
Update CI:
Browse files Browse the repository at this point in the history
- Add precommit check for code linting/formatting
- Upload code coverage reports to codecov
- Run tests with python 3.9, 3.10, 3.11
Move schema and general methods to Model class so they can used for different models
Move schema and general methods to Model class so they can used for different models
  • Loading branch information
jo-basevi committed May 21, 2024
1 parent 1ec6639 commit 403cc26
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 32 deletions.
36 changes: 17 additions & 19 deletions .github/workflows/CD.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: CI
name: CD

on:
pull_request:
branches:
- 'main'
push:
tags:
- '*'

jobs:
pypi-build:
Expand All @@ -18,7 +18,6 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: 3.11
cache: 'pip'

- name: Install build dependencies
run: python3 -m pip install --upgrade build
Expand All @@ -29,23 +28,22 @@ jobs:
- name: Upload distribution artifact
uses: actions/upload-artifact@v4
with:
name: release
path: dist

tests:
name: Tests
pypi-publish:
# Split build and publish to restrict trusted publishing to just this workflow
needs: ['pypi-build']
name: Publish to PyPI.org
runs-on: ubuntu-latest
permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Python 3.11
uses: actions/setup-python@v5
- uses: actions/download-artifact@v4
with:
python-version: 3.11
cache: pip

- name: Install model_config_tests
run: pip install -e '.[test]'
name: release
path: dist

- name: Run tests
run: pytest -s tests
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@2f6f737ca5f74c637829c0f5c3acd0e29ea5e8bf # v1.8.11
25 changes: 21 additions & 4 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ on:
- 'main'

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd #v3.0.1

pypi-build:
name: Build package for PyPI
if: github.repository == 'access-nri/model-config-tests'
Expand Down Expand Up @@ -34,18 +41,28 @@ jobs:
tests:
name: Tests
runs-on: ubuntu-latest

strategy:
matrix:
python-version: [ "3.9", "3.10", "3.11" ]

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Python 3.11
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: 3.11
python-version: ${{ matrix.python-version }}
cache: pip

- name: Install model_config_tests
run: pip install -e '.[test]'
run: python3 -m pip install -e '.[test]'

- name: Run tests
run: pytest -s tests
run: python3 -m pytest -s

- name: Upload code coverage
uses: codecov/codecov-action@v4
with:
files: ./coverage.xml
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
.ipynb_checkpoints
.vscode
.idea
/tests/tmp/
/tests/tmp/
coverage.xml
12 changes: 12 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.4
hooks:
- id: ruff
args: [ --fix ]

- repo: https://github.com/psf/black
rev: 24.4.2
hooks:
- id: black
language_version: python3
74 changes: 66 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
[build-system]
build-backend = "setuptools.build_meta"
requires = [
"setuptools >= 61.0.0",
]

[project]
name = "model-config-tests"
version = "0.0.1"
Expand All @@ -30,7 +24,7 @@ dependencies = [

[project.optional-dependencies]
test = [
"pylint",
"pytest-cov",
"jsonschema >=4.21.1"
]

Expand All @@ -39,4 +33,68 @@ model-config-tests = "model_config_tests.__main__:main"

[project.urls]
Homepage = "https://github.com/ACCESS-NRI/model-config-tests/"
Issues = "https://github.com/ACCESS-NRI/model-config-tests/issues"
Issues = "https://github.com/ACCESS-NRI/model-config-tests/issues"

[build-system]
build-backend = "setuptools.build_meta"
requires = [
"setuptools >= 61.0.0",
]

[tool.pytest.ini_options]
addopts = "--cov=./src --cov-report=xml"
testpaths = ["tests"]

[tool.ruff]
target-version = "py39"
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".git-rewrite",
".hg",
".ipynb_checkpoints",
".mypy_cache",
".nox",
".pants.d",
".pyenv",
".pytest_cache",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
".vscode",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"site-packages",
"venv",
]
# E402: module level import not at top of file
# E501: line too long - let black worry about that
ignore = [
"E402",
"E501",
]
select = [
# Pyflakes
"F",
# Pycodestyle
"E",
"W",
# isort
"I",
# Pyupgrade
"UP",
]

[tool.ruff.mccabe]
max-complexity = 18

[tool.ruff.isort]
known-first-party = ["model_config_tests"]

0 comments on commit 403cc26

Please sign in to comment.