-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First steps for github actions and publish to PYPI
- Loading branch information
Showing
11 changed files
with
1,407 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: 'run-checks' | ||
description: 'Composite action to run checks for code formatting and to run the unittests.' | ||
runs: | ||
using: 'composite' | ||
steps: | ||
|
||
- name: Formatting check | ||
run: | | ||
source .venv/bin/activate | ||
make lint | ||
shell: bash | ||
|
||
- name: Test with pytest | ||
run: | | ||
source .venv/bin/activate | ||
make test | ||
shell: bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
name: merge-to-main | ||
on: | ||
push: | ||
branches: | ||
- main | ||
tags-ignore: | ||
- '**' | ||
jobs: | ||
quality: | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
- name: Check out | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up the environment | ||
uses: ./.github/workflows/setup-poetry | ||
|
||
- name: Run checks | ||
uses: ./.github/workflows/checks | ||
|
||
tox: | ||
runs-on: ubuntu-latest | ||
needs: quality | ||
strategy: | ||
matrix: | ||
python-version: [ '3.10' ] | ||
steps: | ||
|
||
- name: Check out | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up the environment | ||
uses: ./.github/workflows/setup-poetry | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Test with tox | ||
run: | | ||
source .venv/bin/activate | ||
poetry add tox-gh-actions | ||
tox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
name: "Setup Poetry" | ||
description: "Composite action to setup the Python and poetry environment." | ||
inputs: | ||
python-version: | ||
required: false | ||
description: "The python version to use" | ||
default: 3.10.4 | ||
runs: | ||
using: "composite" | ||
steps: | ||
#---------------------------------------------- | ||
# from: https://github.com/snok/install-poetry | ||
# check-out repo and set-up python | ||
#---------------------------------------------- | ||
- name: Check out repository | ||
uses: actions/checkout@v2 | ||
- name: Set up python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ inputs.python-version }} | ||
#---------------------------------------------- | ||
# ----- install & configure poetry ----- | ||
#---------------------------------------------- | ||
- name: Install Poetry | ||
uses: snok/install-poetry@v1 | ||
with: | ||
virtualenvs-create: true | ||
virtualenvs-in-project: true | ||
installer-parallel: true | ||
|
||
#---------------------------------------------- | ||
# load cached venv if cache exists | ||
#---------------------------------------------- | ||
- name: Load cached venv | ||
id: cached-poetry-dependencies | ||
uses: actions/cache@v2 | ||
with: | ||
path: .venv | ||
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }} | ||
|
||
#---------------------------------------------- | ||
# install dependencies if cache does not exist | ||
#---------------------------------------------- | ||
- name: Install dependencies | ||
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' | ||
run: poetry install --no-interaction --no-root | ||
shell: bash | ||
#---------------------------------------------- | ||
# install your root project, if required | ||
#---------------------------------------------- | ||
- name: Install library | ||
run: poetry install --no-interaction | ||
shell: bash | ||
- name: Activate environment | ||
run: source .venv/bin/activate | ||
shell: bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,207 @@ | ||
ECHOCMD:=/bin/echo -e | ||
SHELL := /bin/bash | ||
|
||
args = `arg="$(filter-out $@,$(MAKECMDGOALS))" && echo $${arg:-${1}}` | ||
|
||
PYTHON_VERSION := $(shell python3 --version) | ||
|
||
PROJECT_NAME := $(shell poetry version | awk {'print $$1'}) | ||
PROJECT_VERSION := $(shell poetry version | awk {'print $$2'}) | ||
|
||
# guess OS (Linux, Darwin,...) | ||
OS_NAME := $(shell uname -s 2>/dev/null || echo "unknown") | ||
CPU_ARCH := $(shell uname -m 2>/dev/null || uname -p 2>/dev/null || echo "unknown") | ||
|
||
# Included custom configs change the value of MAKEFILE_LIST | ||
# Extract the required reference beforehand so we can use it for help target | ||
MAKEFILE_NAME := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)) | ||
|
||
# Application | ||
APP_ROOT := $(abspath $(lastword $(MAKEFILE_NAME))/..) | ||
|
||
# it is evaluated when is used (recursively expanded variable) | ||
# https://ftp.gnu.org/old-gnu/Manuals/make-3.79.1/html_chapter/make_6.html#SEC59 | ||
# get the tag | ||
git_tag = $(shell git describe --abbrev=0 --tag) | ||
# regex version project | ||
tag_regex := ^[0-9]+\.[0-9]+(\.[0-9]+)?$$ | ||
|
||
BOLD := \033[1m | ||
RESET := \033[0m | ||
|
||
.PHONY: version | ||
version: ## display current version | ||
@-echo "$(PROJECT_NAME) $(PROJECT_VERSION)" | ||
|
||
.PHONY: info | ||
info: ## display make information | ||
@echo "Information about your make execution:" | ||
@echo " OS Name $(OS_NAME)" | ||
@echo " CPU Architecture $(CPU_ARCH)" | ||
@echo " Python Version $(PYTHON_VERSION)" | ||
@echo " Application Root $(APP_ROOT)" | ||
@echo " Application Name $(PROJECT_NAME)" | ||
@echo " Application Version $(PROJECT_VERSION)" | ||
|
||
.PHONY: bake | ||
bake: ## bake without inputs and overwrite if exists. | ||
@cookiecutter --no-input . --overwrite-if-exists | ||
|
||
.PHONY: bake-with-inputs | ||
bake-with-inputs: ## bake with inputs and overwrite if exists. | ||
@cookiecutter . --overwrite-if-exists | ||
|
||
.PHONY: install | ||
install: ## Install the poetry environment | ||
@echo "🚀 Creating virtual environment using pyenv and poetry" | ||
@poetry install | ||
@poetry shell | ||
|
||
.PHONY: format | ||
format: ## Format code using isort and black. | ||
@echo "🚀 Formatting code: Running isort and black" | ||
@isort . | ||
@black . | ||
|
||
.PHONY: lint | ||
lint: ## Check code formatting using isort and black. | ||
@echo "🚀 Checking code formatting: Running isort and black" | ||
@isort --check-only --diff $(APP_ROOT) | ||
@black --check $(APP_ROOT) | ||
|
||
.PHONY: test | ||
test: ## Test the code with pytest | ||
@echo "🚀 Testing code: Running pytest" | ||
@pytest -s --doctest-modules tests | ||
|
||
.PHONY: bump-version | ||
bump-version: ## Bump the project version | ||
@poetry version $(PROJECT_VERSION) | ||
|
||
## --- Build and publish packages --- ## | ||
|
||
.PHONY: git-tags-local | ||
git-tags-local: ## List local repository tags list | ||
@echo "Local Tags:" | ||
@git tag -n | ||
|
||
.PHONY: git-tags-remote | ||
git-tags-remote: ## List remote repository tags list | ||
@echo "Remote tags:" | ||
@git ls-remote --tags origin | ||
|
||
.PHONY: git-tags | ||
git-tags: git-tags-local git-tags-remote ## List local and remote repository tags | ||
|
||
.PHONY: release | ||
release: ## Create a Github release commit + tag | ||
ifeq ($(PROJECT_VERSION),) | ||
@echo "nothing yet here" | ||
else | ||
@if ! [[ $(PROJECT_VERSION) =~ ^[0-9]+\.[0-9]+(\.[0-9]+)?$$ ]]; then \ | ||
echo "(!!) ERROR - bad version; expected x.y[.z], where x, y, and z are all integers." >&2; \ | ||
exit 1; \ | ||
fi | ||
# @if git status --porcelain | grep .; then \ | ||
# echo "(!!) ERROR - Git working tree is dirty; commit changes and try again." >&2; \ | ||
# exit 1; \ | ||
# fi | ||
@if git tag | grep $(PROJECT_VERSION); then \ | ||
echo "(!!) ERROR - release $(PROJECT_VERSION) already exists." >&2; \ | ||
exit 1; \ | ||
fi | ||
@git add $^ && git commit -m 'Release $(PROJECT_VERSION)' | ||
@git tag $(PROJECT_VERSION) | ||
|
||
@git push && git push --tags | ||
endif | ||
|
||
.PHONY: build | ||
build: clean-build bump-version ## Build wheel file using poetry | ||
@echo "🚀 Creating wheel file" | ||
@poetry build | ||
|
||
.PHONY: publish | ||
publish: ## publish a release to pypi. | ||
@echo "🚀 Publishing: Dry run." | ||
@echo $(PYPI_TOKEN) | ||
@poetry config pypi-token.pypi $(PYPI_TOKEN) | ||
@poetry publish --dry-run | ||
@echo "🚀 Publishing." | ||
@poetry publish | ||
|
||
.PHONY: build-and-publish | ||
build-and-publish: build publish ## Build and publish. | ||
|
||
## --- Cleanup targets --- ## | ||
|
||
.PHONY: clean | ||
clean: clean-all ## alias for 'clean-all' target | ||
|
||
.PHONY: clean-all | ||
clean-all: clean-build clean-pyc clean-test ## remove all artifacts | ||
|
||
.PHONY: clean-build | ||
clean-build: ## remove build artifacts | ||
@echo "Cleaning build artifacts..." | ||
@-rm -fr build/ | ||
@-rm -fr dist/ | ||
@-rm -fr downloads/ | ||
@-rm -fr .eggs/ | ||
@find . -type d -name '*.egg-info' -exec rm -fr {} + | ||
@find . -type f -name '*.egg' -exec rm -f {} + | ||
|
||
.PHONY: clean-pyc | ||
clean-pyc: ## Remove Python file artifacts | ||
@echo "Cleaning Python artifacts..." | ||
@find . -type f -name '*.pyc' -exec rm -f {} + | ||
@find . -type f -name '*.pyo' -exec rm -f {} + | ||
@find . -type f -name '*~' -exec rm -f {} + | ||
@find . -type f -name '__pycache__' -exec rm -fr {} + | ||
|
||
.PHONY: clean-test | ||
clean-test: ## remove test and coverage artifacts | ||
@echo "Cleaning tests artifacts..." | ||
@-rm -fr .tox/ | ||
@-rm -fr .pytest_cache/ | ||
@-rm -fr htmlcov/ | ||
@-rm -f .coverage* | ||
@-rm -f coverage.* | ||
@-rm -fr "$(APP_ROOT)/coverage/" | ||
@-rm -fr "$(APP_ROOT)/node_modules" | ||
@-rm -f "$(APP_ROOT)/package-lock.json" | ||
|
||
## --- Documentation section --- ## | ||
|
||
.PHONY: docs-test | ||
docs-test: ## Test if documentation can be built without warnings or errors | ||
@mkdocs build -s | ||
|
||
.PHONY: docs | ||
docs: ## Build and serve the documentation | ||
@mkdocs serve | ||
|
||
.PHONY: coverage | ||
coverage: ## Generate coverage reports | ||
@coverage erase | ||
@coverage run --source $(APP_ROOT) setup.py test | ||
@coverage report -m --skip-empty | ||
@coverage html -q | ||
|
||
|
||
## --- Misc --- ## | ||
|
||
.PHONY: todos | ||
todos: ## Look for TODOs in the source files. | ||
@git grep -EIn "TODO|FIXME|XXX" -- './*' ':(exclude)Makefile' | ||
|
||
.PHONY: authors | ||
authors: ## Recreate the AUTHORS.md file with all the authors that have committed to the code | ||
@echo "Authors\n=======\n\nA huge thanks to all of our contributors:\n" > docs/AUTHORS.md | ||
@git log --raw | grep "^Author: " | cut -d ' ' -f2- | cut -d '<' -f1 | sed 's/^/- /' | sort | uniq >> docs/AUTHORS.md | ||
|
||
.PHONY: help | ||
help: | ||
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' | ||
|
||
.DEFAULT_GOAL := help |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Authors\n=======\n\nA huge thanks to all of our contributors:\n | ||
- Zaharia Constantin |
Oops, something went wrong.