Skip to content

Commit

Permalink
🔨 Maintenance/release workflow (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov authored Oct 20, 2022
1 parent 2991408 commit 0bbc1c9
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 30 deletions.
6 changes: 5 additions & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ e.g.
## How to test

<!-- Give reviewers some hits or code snippets on how could this be tested -->

```cmd
make devenv
source .venv/bin/activate
make play
```

## Checklist

Expand Down
96 changes: 71 additions & 25 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ SHELL = /bin/bash

OUTPUT_DIR = $(CURDIR)/.output
TEMPLATE = $(CURDIR)
VERSION := $(shell cat VERSION)

#-----------------------------------
# PYTHON ENVIRON -----------------------------------
.PHONY: devenv
.venv:
@python3 --version
Expand All @@ -23,13 +24,9 @@ TEMPLATE = $(CURDIR)
wheel \
setuptools

requirements.txt: requirements.in
# freezes requirements
.venv/bin/pip-compile --upgrade --build-isolation --output-file $@ $(word2, $^)

devenv: .venv ## create a python virtual environment with tools to dev, run and tests cookie-cutter
# installing extra tools
@$</bin/pip3 install -r requirements.txt
@$</bin/pip3 install -r requirements-dev.txt
# your dev environment contains
@$</bin/pip3 list
@echo "To activate the virtual environment, run 'source $</bin/activate'"
Expand All @@ -46,7 +43,7 @@ tests: ## tests backed cookie
$(CURDIR)/tests


#-----------------------------------
# COOKIECUTTER -----------------------------------
.PHONY: play

$(OUTPUT_DIR):
Expand All @@ -71,41 +68,90 @@ endif
@echo "To see generated code, lauch 'code $(OUTPUT_DIR)'"


# VERSION BUMP -------------------------------------------------------------------------------

.PHONY: version-patch version-minor version-major
version-patch version-minor version-major: ## commits version as patch (bug fixes not affecting the API), minor/minor (backwards-compatible/INcompatible API addition or changes)
# upgrades as $(subst version-,,$@) version, commits and tags
@bump2version --verbose --list $(subst version-,,$@)


#-----------------------------------
.PHONY: help
# thanks to https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
help: ## this colorful help
@echo "Recipes for '$(notdir $(CURDIR))':"
@echo ""
@awk --posix 'BEGIN {FS = ":.*?## "} /^[[:alpha:][:space:]_-]+:.*?## / {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
@echo ""

git_clean_args = -dxf --exclude=.vscode/ --exclude=.venv/ --exclude=.python
# RELEASE -------------------------------------------------------------------------------

prod_prefix := v
_git_get_current_branch = $(shell git rev-parse --abbrev-ref HEAD)

# NOTE: be careful that GNU Make replaces newlines with space which is why this command cannot work using a Make function
_url_encoded_title = $(VERSION)
_url_encoded_tag = $(prod_prefix)$(VERSION)
_url_encoded_target = $(if $(git_sha),$(git_sha),master)
_prettify_logs = $$(git log \
$$(git describe --match="$(prod_prefix)*" --abbrev=0 --tags)..$(if $(git_sha),$(git_sha),HEAD) \
--pretty=format:"- %s")
define _url_encoded_logs
$(shell \
scripts/url-encoder.bash \
"$(_prettify_logs)"\
)
endef
_git_get_repo_orga_name = $(shell git config --get remote.origin.url | \
grep --perl-regexp --only-matching "((?<=git@github\.com:)|(?<=https:\/\/github\.com\/))(.*?)(?=.git)")

.PHONY: .check-master-branch
.check-master-branch:
@if [ "$(_git_get_current_branch)" != "master" ]; then\
echo -e "\e[91mcurrent branch is not master branch."; exit 1;\
fi

.PHONY: release
release pre-release: .check-master-branch ## Creates github release link. Usage: make release-prod git_sha=optional
# ensure tags are up-to-date
@git pull --tags
@echo -e "\e[33mOpen the following link to create a release:";
@echo -e "\e[32mhttps://github.com/$(_git_get_repo_orga_name)/releases/new?prerelease=$(if $(findstring pre-, $@),1,0)&target=$(_url_encoded_target)&tag=$(_url_encoded_tag)&title=$(_url_encoded_title)&body=$(_url_encoded_logs)";
@echo -e "\e[33mOr open the following link to create a release and paste the logs:";
@echo -e "\e[32mhttps://github.com/$(_git_get_repo_orga_name)/releases/new?prerelease=$(if $(findstring pre-, $@),1,0)&target=$(_url_encoded_target)&tag=$(_url_encoded_tag)&title=$(_url_encoded_title)";
@echo -e "\e[34m$(_prettify_logs)"


# TOOLS -----------------------------------

.PHONY: info
info: ## displays info about the scope
# python
@which python
@python --version
@which pip
@pip --version
@pip list
@cookiecutter --version
# environs
@echo "VERSION : $(VERSION)"
@echo "OUTPUT_DIR: $(OUTPUT_DIR)"
@echo "TEMPLATE: $(CURDIR)"
# cookiecutter config
@jq '.' cookiecutter.json

.PHONY: clean clean-force

git_clean_args = -dx --force --exclude=.vscode/ --exclude=.venv/ --exclude=.python

clean: ## cleans all unversioned files in project and temp files create by this makefile
# Cleaning unversioned
@git clean -n $(git_clean_args)
@echo -n "Are you sure? [y/N] " && read ans && [ $${ans:-N} = y ]
@echo -n "$(shell whoami), are you REALLY sure? [y/N] " && read ans && [ $${ans:-N} = y ]
@git clean $(git_clean_args)
-rm -rf $(OUTPUT_DIR)
-rm -r --force $(OUTPUT_DIR)

clean-force: clean
# removing .venv
-@rm -rf .venv

-@rm -r --force .venv

.PHONY: info
info: ## displays info about the scope
# python
@echo $(shell which python)
@python --version
@echo $(shell which pip)
.PHONY: help
help: ## this colorful help
@echo "Recipes for '$(notdir $(CURDIR))':"
@echo ""
@awk --posix 'BEGIN {FS = ":.*?## "} /^[[:alpha:][:space:]_-]+:.*?## / {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
@echo ""
3 changes: 0 additions & 3 deletions requirements.txt → requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,3 @@ pytest-sugar

# package management
bump2version
pip-tools
yolk3k # obtains info about installed packages or available in PyPi
semantic_version # check compatibility versioning
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[bumpversion]
current_version = 0.4.0
commit = True
message = cookiecutter version: {current_version} → {new_version}
message = cookiecutter-osparc-service version: {current_version} → {new_version}
tag = False

[bumpversion:file:VERSION]
Expand Down

0 comments on commit 0bbc1c9

Please sign in to comment.