Skip to content

Commit fa41510

Browse files
committed
* Updates scripts
* Improves deploy
1 parent 8eb8c79 commit fa41510

File tree

3 files changed

+82
-8
lines changed

3 files changed

+82
-8
lines changed

.github/workflows/deploy.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ jobs:
1010
deploy:
1111
name: Build and publish Python 🐍 distributions 📦 to PyPI and TestPyPI
1212
runs-on: ubuntu-latest
13-
if: contains(github.ref, 'master')
1413
steps:
1514
- uses: actions/checkout@v2
1615
- name: Set up latest Python 3
@@ -32,8 +31,7 @@ jobs:
3231
password: ${{ secrets.TEST_PYPI_TOKEN }}
3332
repository_url: https://test.pypi.org/legacy/
3433
verbose: true
35-
- if: startsWith(github.ref, 'refs/tags')
36-
name: Publish distribution 📦 to PyPI
34+
- name: Publish distribution 📦 to PyPI
3735
uses: pypa/gh-action-pypi-publish@release/v1
3836
with:
3937
user: __token__

Makefile

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ build:
126126
python setup.py sdist bdist_wheel
127127

128128

129-
.PHONY: release
130-
release: build # release by-hand (TEMP SOLUTION until FIXME: https://github.com/ITISFoundation/osparc-simcore-python-client/issues/16)
131-
python -m pip install twine
132-
python -m twine upload dist/*
129+
#.PHONY: release
130+
#release: build # release by-hand (TEMP SOLUTION until FIXME: https://github.com/ITISFoundation/osparc-simcore-python-client/issues/16)
131+
# python -m pip install twine
132+
# python -m twine upload dist/*
133133

134134

135135
## DOCKER -------------------------------------------------------------------------------
@@ -141,4 +141,51 @@ image:
141141

142142
.PHONY: shell
143143
shell:
144-
docker run -it $(APP_NAME):latest /bin/bash
144+
docker run -it $(APP_NAME):latest /bin/bash
145+
146+
147+
148+
# RELEASE --------------------------------------------------------------------------------------------------------------------------------------------
149+
150+
staging_prefix := staging_
151+
prod_prefix := v
152+
_git_get_current_branch = $(shell git rev-parse --abbrev-ref HEAD)
153+
154+
# NOTE: be careful that GNU Make replaces newlines with space which is why this command cannot work using a Make function
155+
_url_encoded_title = $(if $(findstring -staging, $@),Staging%20$(name),)$(version)
156+
_url_encoded_tag = $(if $(findstring -staging, $@),$(staging_prefix)$(name),$(prod_prefix))$(version)
157+
_url_encoded_target = $(if $(git_sha),$(git_sha),$(if $(findstring -hotfix, $@),$(_git_get_current_branch),master))
158+
_prettify_logs = $$(git log \
159+
$$(git describe --match="$(if $(findstring -staging, $@),$(staging_prefix),$(prod_prefix))*" --abbrev=0 --tags)..$(if $(git_sha),$(git_sha),HEAD) \
160+
--pretty=format:"- %s")
161+
define _url_encoded_logs
162+
$(shell \
163+
scripts/url-encoder.bash \
164+
"$(_prettify_logs)"\
165+
)
166+
endef
167+
_git_get_repo_orga_name = $(shell git config --get remote.origin.url | \
168+
grep --perl-regexp --only-matching "((?<=git@github\.com:)|(?<=https:\/\/github\.com\/))(.*?)(?=.git)")
169+
170+
.PHONY: .check-master-branch
171+
.check-master-branch:
172+
@if [ "$(_git_get_current_branch)" != "master" ]; then\
173+
echo -e "\e[91mcurrent branch is not master branch."; exit 1;\
174+
fi
175+
176+
.PHONY: release-staging release-prod
177+
release-staging release-prod: .check-master-branch ## Helper to create a staging or production release in Github (usage: make release-staging name=sprint version=1 git_sha=optional or make release-prod version=1.2.3 git_sha=optional)
178+
# ensure tags are up-to-date
179+
@git pull --tags
180+
@echo -e "\e[33mOpen the following link to create the $(if $(findstring -staging, $@),staging,production) release:";
181+
@echo -e "\e[32mhttps://github.com/$(_git_get_repo_orga_name)/releases/new?prerelease=$(if $(findstring -staging, $@),1,0)&target=$(_url_encoded_target)&tag=$(_url_encoded_tag)&title=$(_url_encoded_title)&body=$(_url_encoded_logs)";
182+
@echo -e "\e[33mOr open the following link to create the $(if $(findstring -staging, $@),staging,production) release and paste the logs:";
183+
@echo -e "\e[32mhttps://github.com/$(_git_get_repo_orga_name)/releases/new?prerelease=$(if $(findstring -staging, $@),1,0)&target=$(_url_encoded_target)&tag=$(_url_encoded_tag)&title=$(_url_encoded_title)";
184+
@echo -e "\e[34m$(_prettify_logs)"
185+
186+
.PHONY: release-hotfix
187+
release-hotfix: ## Helper to create a hotfix release in Github (usage: make release-hotfix version=1.2.4 git_sha=optional)
188+
# ensure tags are up-to-date
189+
@git pull --tags
190+
@echo -e "\e[33mOpen the following link to create the $(if $(findstring -staging, $@),staging,production) release:";
191+
@echo -e "\e[32mhttps://github.com/$(_git_get_repo_orga_name)/releases/new?prerelease=$(if $(findstring -staging, $@),1,0)&target=$(_url_encoded_target)&tag=$(_url_encoded_tag)&title=$(_url_encoded_title)&body=$(_url_encoded_logs)";

scripts/url-encoder.bash

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
# strict mode
4+
set -o errexit # abort on nonzero exitstatus
5+
set -o nounset # abort on unbound variable
6+
set -o pipefail # don't hide errors within pipes
7+
IFS=$'\n\t'
8+
9+
# https://stackoverflow.com/questions/296536/how-to-urlencode-data-for-curl-command
10+
11+
rawurlencode() {
12+
local string="${1}"
13+
local strlen=${#string}
14+
local encoded=""
15+
local pos c o
16+
17+
for (( pos=0 ; pos<strlen ; pos++ )); do
18+
c=${string:$pos:1}
19+
case "$c" in
20+
[-_.~a-zA-Z0-9] ) o="${c}" ;;
21+
* ) printf -v o '%%%02x' "'$c"
22+
esac
23+
encoded+="${o}"
24+
done
25+
echo "${encoded}" # You can either set a return variable (FASTER)
26+
REPLY="${encoded}" #+or echo the result (EASIER)... or both... :p
27+
}
28+
29+
rawurlencode "$@"

0 commit comments

Comments
 (0)