Skip to content

Commit 0bbc1c9

Browse files
authored
🔨 Maintenance/release workflow (#92)
1 parent 2991408 commit 0bbc1c9

File tree

4 files changed

+77
-30
lines changed

4 files changed

+77
-30
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ e.g.
3333
## How to test
3434

3535
<!-- Give reviewers some hits or code snippets on how could this be tested -->
36-
36+
```cmd
37+
make devenv
38+
source .venv/bin/activate
39+
make play
40+
```
3741

3842
## Checklist
3943

Makefile

Lines changed: 71 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ SHELL = /bin/bash
1111

1212
OUTPUT_DIR = $(CURDIR)/.output
1313
TEMPLATE = $(CURDIR)
14+
VERSION := $(shell cat VERSION)
1415

15-
#-----------------------------------
16+
# PYTHON ENVIRON -----------------------------------
1617
.PHONY: devenv
1718
.venv:
1819
@python3 --version
@@ -23,13 +24,9 @@ TEMPLATE = $(CURDIR)
2324
wheel \
2425
setuptools
2526

26-
requirements.txt: requirements.in
27-
# freezes requirements
28-
.venv/bin/pip-compile --upgrade --build-isolation --output-file $@ $(word2, $^)
29-
3027
devenv: .venv ## create a python virtual environment with tools to dev, run and tests cookie-cutter
3128
# installing extra tools
32-
@$</bin/pip3 install -r requirements.txt
29+
@$</bin/pip3 install -r requirements-dev.txt
3330
# your dev environment contains
3431
@$</bin/pip3 list
3532
@echo "To activate the virtual environment, run 'source $</bin/activate'"
@@ -46,7 +43,7 @@ tests: ## tests backed cookie
4643
$(CURDIR)/tests
4744

4845

49-
#-----------------------------------
46+
# COOKIECUTTER -----------------------------------
5047
.PHONY: play
5148

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

7370

71+
# VERSION BUMP -------------------------------------------------------------------------------
7472

7573
.PHONY: version-patch version-minor version-major
7674
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)
7775
# upgrades as $(subst version-,,$@) version, commits and tags
7876
@bump2version --verbose --list $(subst version-,,$@)
7977

8078

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

90-
git_clean_args = -dxf --exclude=.vscode/ --exclude=.venv/ --exclude=.python
80+
# RELEASE -------------------------------------------------------------------------------
81+
82+
prod_prefix := v
83+
_git_get_current_branch = $(shell git rev-parse --abbrev-ref HEAD)
84+
85+
# NOTE: be careful that GNU Make replaces newlines with space which is why this command cannot work using a Make function
86+
_url_encoded_title = $(VERSION)
87+
_url_encoded_tag = $(prod_prefix)$(VERSION)
88+
_url_encoded_target = $(if $(git_sha),$(git_sha),master)
89+
_prettify_logs = $$(git log \
90+
$$(git describe --match="$(prod_prefix)*" --abbrev=0 --tags)..$(if $(git_sha),$(git_sha),HEAD) \
91+
--pretty=format:"- %s")
92+
define _url_encoded_logs
93+
$(shell \
94+
scripts/url-encoder.bash \
95+
"$(_prettify_logs)"\
96+
)
97+
endef
98+
_git_get_repo_orga_name = $(shell git config --get remote.origin.url | \
99+
grep --perl-regexp --only-matching "((?<=git@github\.com:)|(?<=https:\/\/github\.com\/))(.*?)(?=.git)")
100+
101+
.PHONY: .check-master-branch
102+
.check-master-branch:
103+
@if [ "$(_git_get_current_branch)" != "master" ]; then\
104+
echo -e "\e[91mcurrent branch is not master branch."; exit 1;\
105+
fi
106+
107+
.PHONY: release
108+
release pre-release: .check-master-branch ## Creates github release link. Usage: make release-prod git_sha=optional
109+
# ensure tags are up-to-date
110+
@git pull --tags
111+
@echo -e "\e[33mOpen the following link to create a release:";
112+
@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)";
113+
@echo -e "\e[33mOr open the following link to create a release and paste the logs:";
114+
@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)";
115+
@echo -e "\e[34m$(_prettify_logs)"
116+
117+
118+
# TOOLS -----------------------------------
119+
120+
.PHONY: info
121+
info: ## displays info about the scope
122+
# python
123+
@which python
124+
@python --version
125+
@which pip
126+
@pip --version
127+
@pip list
128+
@cookiecutter --version
129+
# environs
130+
@echo "VERSION : $(VERSION)"
131+
@echo "OUTPUT_DIR: $(OUTPUT_DIR)"
132+
@echo "TEMPLATE: $(CURDIR)"
133+
# cookiecutter config
134+
@jq '.' cookiecutter.json
91135

92136
.PHONY: clean clean-force
137+
138+
git_clean_args = -dx --force --exclude=.vscode/ --exclude=.venv/ --exclude=.python
139+
93140
clean: ## cleans all unversioned files in project and temp files create by this makefile
94141
# Cleaning unversioned
95142
@git clean -n $(git_clean_args)
96143
@echo -n "Are you sure? [y/N] " && read ans && [ $${ans:-N} = y ]
97144
@echo -n "$(shell whoami), are you REALLY sure? [y/N] " && read ans && [ $${ans:-N} = y ]
98145
@git clean $(git_clean_args)
99-
-rm -rf $(OUTPUT_DIR)
146+
-rm -r --force $(OUTPUT_DIR)
100147

101148
clean-force: clean
102149
# removing .venv
103-
-@rm -rf .venv
104-
150+
-@rm -r --force .venv
105151

106-
.PHONY: info
107-
info: ## displays info about the scope
108-
# python
109-
@echo $(shell which python)
110-
@python --version
111-
@echo $(shell which pip)
152+
.PHONY: help
153+
help: ## this colorful help
154+
@echo "Recipes for '$(notdir $(CURDIR))':"
155+
@echo ""
156+
@awk --posix 'BEGIN {FS = ":.*?## "} /^[[:alpha:][:space:]_-]+:.*?## / {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
157+
@echo ""

requirements.txt renamed to requirements-dev.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,3 @@ pytest-sugar
1717

1818
# package management
1919
bump2version
20-
pip-tools
21-
yolk3k # obtains info about installed packages or available in PyPi
22-
semantic_version # check compatibility versioning

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[bumpversion]
22
current_version = 0.4.0
33
commit = True
4-
message = cookiecutter version: {current_version} → {new_version}
4+
message = cookiecutter-osparc-service version: {current_version} → {new_version}
55
tag = False
66

77
[bumpversion:file:VERSION]

0 commit comments

Comments
 (0)