Skip to content

Commit

Permalink
Update build.yml to handle coverage correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
ibro45 committed Nov 30, 2024
1 parent f2b8595 commit 92c8859
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 99 deletions.
1 change: 1 addition & 0 deletions .github/workflows/auto-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:

jobs:
build:
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand Down
27 changes: 19 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ name: Lighter CI

on:
push:
branches:
- main
branches: [main]
pull_request:
branches:
- main
branches: [main]

permissions:
contents: write

jobs:
build:
Expand All @@ -16,20 +17,20 @@ jobs:
python-version: ["3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2.2.2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install poetry
run: make setup

- name: Set up cache
uses: actions/cache@v2.1.6
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }}-${{ hashFiles('poetry.lock') }}
key: venv-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }}

- name: Install dependencies
run: |
Expand All @@ -42,6 +43,7 @@ jobs:
make check-safety
- name: Run style checks
continue-on-error: true
run: |
poetry install --with style
make check-codestyle
Expand All @@ -51,3 +53,12 @@ jobs:
poetry install --with tests
make test
- name: Update coverage badge
if: github.ref == 'refs/heads/main' && matrix.python-version == '3.11'
run: |
make coverage
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add assets/images/coverage.svg
git commit -m "Update coverage badge" || echo "No changes to commit"
git push
113 changes: 23 additions & 90 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,14 @@
SHELL := /usr/bin/env bash
PYTHON := python
PYTHONPATH := `pwd`
#* Docker variables
IMAGE := lighter
VERSION := latest


#* Poetry

#* Fix for issue with poetry
#* Poetry Setup
.PHONY: setup
setup: poetry-download
@echo export PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring >> ~/.bashrc
@echo export PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring >> ~/.profile
source ~/.bashrc
source ~/.profile
poetry self add poetry-bumpversion@latest
poetry self add poetry-plugin-export@latest


.PHONY: poetry-download
poetry-download:
setup:
curl -sSL https://install.python-poetry.org | $(PYTHON) -

.PHONY: poetry-remove
poetry-remove:
curl -sSL https://install.python-poetry.org | $(PYTHON) - --uninstall
@echo "export PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring" >> ~/.bashrc
@echo "export PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring" >> ~/.profile
poetry self add poetry-bumpversion@latest poetry-plugin-export@latest

#* Installation
.PHONY: install
Expand All @@ -37,91 +20,41 @@ install:
pre-commit-install:
poetry run pre-commit install

#* Formatters
.PHONY: codestyle
codestyle:
poetry run pyupgrade --exit-zero-even-if-changed --py37-plus **/*.py
poetry run isort --settings-path pyproject.toml ./
poetry run black --config pyproject.toml ./

.PHONY: formatting
formatting: codestyle

#* Linting
.PHONY: test
test:
PYTHONPATH=$(PYTHONPATH) poetry run pytest -c pyproject.toml --cov-report=html --cov=lighter tests/
poetry run coverage-badge -o assets/images/coverage.svg -f

#* Linting & Testing
.PHONY: check-codestyle
check-codestyle:
poetry run isort --diff --check-only --settings-path pyproject.toml ./
poetry run black --diff --check --config pyproject.toml ./
poetry run pylint lighter

.PHONY: mypy
mypy:
poetry run mypy --config-file pyproject.toml ./

.PHONY: check-safety
check-safety:
poetry check
poetry export | poetry run safety check --stdin
poetry run bandit -ll --recursive lighter tests

.PHONY: lint
lint: test check-codestyle mypy check-safety
.PHONY: test
test:
PYTHONPATH=$(PYTHONPATH) poetry run pytest -c pyproject.toml --cov-report=html --cov=lighter tests/

.PHONY: coverage
coverage:
poetry run coverage-badge -o assets/images/coverage.svg -f

#* Dependency Management
.PHONY: update-dev-deps
update-dev-deps:
poetry add -G dev bandit@latest "isort[colors]@latest" mypy@latest pre-commit@latest pydocstyle@latest pylint@latest pytest@latest pyupgrade@latest safety@latest coverage@latest coverage-badge@latest pytest-html@latest pytest-cov@latest
poetry add -G dev bandit@latest "isort[colors]@latest" mypy@latest pre-commit@latest pydocstyle@latest \
pylint@latest pytest@latest pyupgrade@latest safety@latest coverage@latest coverage-badge@latest \
pytest-html@latest pytest-cov@latest
poetry add -G dev --allow-prereleases black@latest

#* Docker
# Example: make docker-build VERSION=latest
# Example: make docker-build IMAGE=some_name VERSION=0.0.1
.PHONY: docker-build
docker-build:
@echo Building docker $(IMAGE):$(VERSION) ...
docker build \
-t $(IMAGE):$(VERSION) . \
-f ./docker/Dockerfile --no-cache

# Example: make docker-remove VERSION=latest
# Example: make docker-remove IMAGE=some_name VERSION=0.0.1
.PHONY: docker-remove
docker-remove:
@echo Removing docker $(IMAGE):$(VERSION) ...
docker rmi -f $(IMAGE):$(VERSION)
.PHONY: update-deps
update-deps:
poetry add torch@latest torchvision@latest pytorch_lightning@latest torchmetrics@latest monai@latest

#* Cleaning
.PHONY: pycache-remove
pycache-remove:
find . | grep -E "(__pycache__|\.pyc|\.pyo$$)" | xargs rm -rf

.PHONY: dsstore-remove
dsstore-remove:
find . | grep -E ".DS_Store" | xargs rm -rf

.PHONY: mypycache-remove
mypycache-remove:
find . | grep -E ".mypy_cache" | xargs rm -rf

.PHONY: ipynbcheckpoints-remove
ipynbcheckpoints-remove:
find . | grep -E ".ipynb_checkpoints" | xargs rm -rf

.PHONY: pytestcache-remove
pytestcache-remove:
find . | grep -E ".pytest_cache" | xargs rm -rf

.PHONY: build-remove
build-remove:
.PHONY: clean
clean:
find . | grep -E "(__pycache__|\.pyc|\.pyo$$|.DS_Store|.mypy_cache|.pytest_cache|.ipynb_checkpoints)" | xargs rm -rf
rm -rf build/

.PHONY: cleanup
cleanup: pycache-remove dsstore-remove mypycache-remove ipynbcheckpoints-remove pytestcache-remove

.PHONY: get-latest-deps
get-latest-deps:
poetry add torch@latest torchvision@latest pytorch_lightning@latest torchmetrics@latest monai@latest
1 change: 0 additions & 1 deletion diagram.svg

This file was deleted.

0 comments on commit 92c8859

Please sign in to comment.