Showing
1 changed file
with
136 additions
and
0 deletions
release
0 → 100755
1 | +#!/usr/bin/env bash | ||
2 | +set -eo pipefail; [[ $RELEASE_TRACE ]] && set -x | ||
3 | + | ||
4 | +PACKAGE_NAME='kappa' | ||
5 | +INIT_PACKAGE_NAME='kappa' | ||
6 | +PUBLIC="true" | ||
7 | + | ||
8 | +# Colors | ||
9 | +COLOR_OFF="\033[0m" # unsets color to term fg color | ||
10 | +RED="\033[0;31m" # red | ||
11 | +GREEN="\033[0;32m" # green | ||
12 | +YELLOW="\033[0;33m" # yellow | ||
13 | +MAGENTA="\033[0;35m" # magenta | ||
14 | +CYAN="\033[0;36m" # cyan | ||
15 | + | ||
16 | +# ensure wheel is available | ||
17 | +pip install wheel > /dev/null | ||
18 | + | ||
19 | +# ensure Pygment is available | ||
20 | +pip install Pygments > /dev/null | ||
21 | + | ||
22 | +command -v gitchangelog >/dev/null 2>&1 || { | ||
23 | + echo -e "${RED}WARNING: Missing gitchangelog binary, please run: pip install gitchangelog==2.2.0${COLOR_OFF}\n" | ||
24 | + exit 1 | ||
25 | +} | ||
26 | + | ||
27 | +command -v rst-lint > /dev/null || { | ||
28 | + echo -e "${RED}WARNING: Missing rst-lint binary, please run: pip install restructuredtext_lint${COLOR_OFF}\n" | ||
29 | + exit 1 | ||
30 | +} | ||
31 | + | ||
32 | +if [[ "$@" != "major" ]] && [[ "$@" != "minor" ]] && [[ "$@" != "patch" ]]; then | ||
33 | + echo -e "${RED}WARNING: Invalid release type, must specify 'major', 'minor', or 'patch'${COLOR_OFF}\n" | ||
34 | + exit 1 | ||
35 | +fi | ||
36 | + | ||
37 | +echo -e "\n${GREEN}STARTING RELEASE PROCESS${COLOR_OFF}\n" | ||
38 | + | ||
39 | +set +e; | ||
40 | +git status | grep "working directory clean" &> /dev/null | ||
41 | +if [ ! $? -eq 0 ]; then # working directory is NOT clean | ||
42 | + echo -e "${RED}WARNING: You have uncomitted changes, you may have forgotten something${COLOR_OFF}\n" | ||
43 | + exit 1 | ||
44 | +fi | ||
45 | +set -e; | ||
46 | + | ||
47 | +echo -e "${YELLOW}--->${COLOR_OFF} Updating local copy" | ||
48 | +git pull -q origin master | ||
49 | +git fetch --tags > /dev/null | ||
50 | + | ||
51 | +echo -e "${YELLOW}--->${COLOR_OFF} Retrieving release versions" | ||
52 | + | ||
53 | +current_version=$(cat ${INIT_PACKAGE_NAME}/__init__.py |grep '__version__ ='|sed 's/[^0-9.]//g') | ||
54 | +major=$(echo $current_version | awk '{split($0,a,"."); print a[1]}') | ||
55 | +minor=$(echo $current_version | awk '{split($0,a,"."); print a[2]}') | ||
56 | +patch=$(echo $current_version | awk '{split($0,a,"."); print a[3]}') | ||
57 | + | ||
58 | +if [[ "$@" == "major" ]]; then | ||
59 | + major=$(($major + 1)); | ||
60 | + minor="0" | ||
61 | + patch="0" | ||
62 | +elif [[ "$@" == "minor" ]]; then | ||
63 | + minor=$(($minor + 1)); | ||
64 | + patch="0" | ||
65 | +elif [[ "$@" == "patch" ]]; then | ||
66 | + patch=$(($patch + 1)); | ||
67 | +fi | ||
68 | + | ||
69 | +next_version="${major}.${minor}.${patch}" | ||
70 | + | ||
71 | +echo -e "${YELLOW} >${COLOR_OFF} ${MAGENTA}${current_version}${COLOR_OFF} -> ${MAGENTA}${next_version}${COLOR_OFF}" | ||
72 | + | ||
73 | +echo -e "${YELLOW}--->${COLOR_OFF} Ensuring readme passes lint checks (if this fails, run rst-lint)" | ||
74 | +rst-lint README.rst > /dev/null | ||
75 | + | ||
76 | +echo -e "${YELLOW}--->${COLOR_OFF} Creating necessary temp file" | ||
77 | +tempfoo=$(basename $0) | ||
78 | +TMPFILE=$(mktemp /tmp/${tempfoo}.XXXXXX) || { | ||
79 | + echo -e "${RED}WARNING: Cannot create temp file using mktemp in /tmp dir ${COLOR_OFF}\n" | ||
80 | + exit 1 | ||
81 | +} | ||
82 | + | ||
83 | +find_this="__version__ = '$current_version'" | ||
84 | +replace_with="__version__ = '$next_version'" | ||
85 | + | ||
86 | +echo -e "${YELLOW}--->${COLOR_OFF} Updating ${INIT_PACKAGE_NAME}/__init__.py" | ||
87 | +sed "s/$find_this/$replace_with/" ${INIT_PACKAGE_NAME}/__init__.py > $TMPFILE && mv $TMPFILE ${INIT_PACKAGE_NAME}/__init__.py | ||
88 | + | ||
89 | +echo -e "${YELLOW}--->${COLOR_OFF} Updating README.rst" | ||
90 | +find_this="${PACKAGE_NAME}.git@$current_version" | ||
91 | +replace_with="${PACKAGE_NAME}.git@$next_version" | ||
92 | +sed "s/$find_this/$replace_with/" README.rst > $TMPFILE && mv $TMPFILE README.rst | ||
93 | +find_this="${PACKAGE_NAME}==$current_version" | ||
94 | +replace_with="${PACKAGE_NAME}==$next_version" | ||
95 | +sed "s/$find_this/$replace_with/" README.rst > $TMPFILE && mv $TMPFILE README.rst | ||
96 | + | ||
97 | +if [ -f docs/conf.py ]; then | ||
98 | + echo -e "${YELLOW}--->${COLOR_OFF} Updating docs" | ||
99 | + find_this="version = '${current_version}'" | ||
100 | + replace_with="version = '${next_version}'" | ||
101 | + sed "s/$find_this/$replace_with/" docs/conf.py > $TMPFILE && mv $TMPFILE docs/conf.py | ||
102 | + | ||
103 | + find_this="release = '${current_version}'" | ||
104 | + replace_with="release = '${next_version}'" | ||
105 | + sed "s/$find_this/$replace_with/" docs/conf.py > $TMPFILE && mv $TMPFILE docs/conf.py | ||
106 | +fi | ||
107 | + | ||
108 | +echo -e "${YELLOW}--->${COLOR_OFF} Updating CHANGES.rst for new release" | ||
109 | +version_header="$next_version ($(date +%F))" | ||
110 | +set +e; dashes=$(yes '-'|head -n ${#version_header}|tr -d '\n') ; set -e | ||
111 | +gitchangelog |sed "4s/.*/$version_header/"|sed "5s/.*/$dashes/" > $TMPFILE && mv $TMPFILE CHANGES.rst | ||
112 | + | ||
113 | +echo -e "${YELLOW}--->${COLOR_OFF} Adding changed files to git" | ||
114 | +git add CHANGES.rst README.rst ${INIT_PACKAGE_NAME}/__init__.py | ||
115 | +if [ -f docs/conf.py ]; then git add docs/conf.py; fi | ||
116 | + | ||
117 | +echo -e "${YELLOW}--->${COLOR_OFF} Creating release" | ||
118 | +git commit -q -m "Release version $next_version" | ||
119 | + | ||
120 | +echo -e "${YELLOW}--->${COLOR_OFF} Tagging release" | ||
121 | +git tag -a $next_version -m "Release version $next_version" | ||
122 | + | ||
123 | +echo -e "${YELLOW}--->${COLOR_OFF} Pushing release and tags to github" | ||
124 | +git push -q origin master && git push -q --tags | ||
125 | + | ||
126 | +if [[ "$PUBLIC" == "true" ]]; then | ||
127 | + echo -e "${YELLOW}--->${COLOR_OFF} Creating python release" | ||
128 | + cp README.rst README | ||
129 | + python setup.py sdist bdist_wheel upload > /dev/null | ||
130 | + rm README | ||
131 | +else | ||
132 | + echo -e "${YELLOW}--->${COLOR_OFF} Creating local python dist and wheel for manual release" | ||
133 | + python setup.py sdist bdist_wheel > /dev/null | ||
134 | +fi | ||
135 | + | ||
136 | +echo -e "\n${CYAN}RELEASED VERSION ${next_version}${COLOR_OFF}\n" |
-
Please register or login to post a comment