Skip to content

Commit fc7161b

Browse files
committed
feat: add release script
1 parent 9705e35 commit fc7161b

File tree

1 file changed

+132
-0
lines changed

1 file changed

+132
-0
lines changed

release

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
#!/usr/bin/env bash
2+
set -eo pipefail; [[ $RELEASE_TRACE ]] && set -x
3+
4+
PACKAGE_NAME='conf_d'
5+
INIT_PACKAGE_NAME='conf_d'
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 -Eo "working (directory|tree) 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+
50+
echo -e "${YELLOW}--->${COLOR_OFF} Retrieving release versions"
51+
52+
current_version=$(cat ${INIT_PACKAGE_NAME}/__init__.py |grep '__version__ ='|sed 's/[^0-9.]//g')
53+
major=$(echo $current_version | awk '{split($0,a,"."); print a[1]}')
54+
minor=$(echo $current_version | awk '{split($0,a,"."); print a[2]}')
55+
patch=$(echo $current_version | awk '{split($0,a,"."); print a[3]}')
56+
57+
if [[ "$@" == "major" ]]; then
58+
major=$(($major + 1));
59+
minor="0"
60+
patch="0"
61+
elif [[ "$@" == "minor" ]]; then
62+
minor=$(($minor + 1));
63+
patch="0"
64+
elif [[ "$@" == "patch" ]]; then
65+
patch=$(($patch + 1));
66+
fi
67+
68+
next_version="${major}.${minor}.${patch}"
69+
70+
echo -e "${YELLOW} >${COLOR_OFF} ${MAGENTA}${current_version}${COLOR_OFF} -> ${MAGENTA}${next_version}${COLOR_OFF}"
71+
72+
echo -e "${YELLOW}--->${COLOR_OFF} Ensuring readme passes lint checks (if this fails, run rst-lint)"
73+
rst-lint README.rst > /dev/null
74+
75+
echo -e "${YELLOW}--->${COLOR_OFF} Creating necessary temp file"
76+
tempfoo=$(basename $0)
77+
TMPFILE=$(mktemp /tmp/${tempfoo}.XXXXXX) || {
78+
echo -e "${RED}WARNING: Cannot create temp file using mktemp in /tmp dir ${COLOR_OFF}\n"
79+
exit 1
80+
}
81+
82+
find_this="__version__ = '$current_version'"
83+
replace_with="__version__ = '$next_version'"
84+
85+
echo -e "${YELLOW}--->${COLOR_OFF} Updating ${INIT_PACKAGE_NAME}/__init__.py"
86+
sed "s/$find_this/$replace_with/" ${INIT_PACKAGE_NAME}/__init__.py > $TMPFILE && mv $TMPFILE ${INIT_PACKAGE_NAME}/__init__.py
87+
88+
echo -e "${YELLOW}--->${COLOR_OFF} Updating README.rst"
89+
find_this="${PACKAGE_NAME}.git@$current_version"
90+
replace_with="${PACKAGE_NAME}.git@$next_version"
91+
sed "s/$find_this/$replace_with/" README.rst > $TMPFILE && mv $TMPFILE README.rst
92+
find_this="${PACKAGE_NAME}==$current_version"
93+
replace_with="${PACKAGE_NAME}==$next_version"
94+
sed "s/$find_this/$replace_with/" README.rst > $TMPFILE && mv $TMPFILE README.rst
95+
96+
if [ -f docs/conf.py ]; then
97+
echo -e "${YELLOW}--->${COLOR_OFF} Updating docs"
98+
find_this="version = '${current_version}'"
99+
replace_with="version = '${next_version}'"
100+
sed "s/$find_this/$replace_with/" docs/conf.py > $TMPFILE && mv $TMPFILE docs/conf.py
101+
102+
find_this="release = '${current_version}'"
103+
replace_with="release = '${next_version}'"
104+
sed "s/$find_this/$replace_with/" docs/conf.py > $TMPFILE && mv $TMPFILE docs/conf.py
105+
fi
106+
107+
echo -e "${YELLOW}--->${COLOR_OFF} Updating CHANGES.rst for new release"
108+
version_header="$next_version ($(date +%F))"
109+
set +e; dashes=$(yes '-'|head -n ${#version_header}|tr -d '\n') ; set -e
110+
gitchangelog |sed "4s/.*/$version_header/"|sed "5s/.*/$dashes/" > $TMPFILE && mv $TMPFILE CHANGES.rst
111+
112+
echo -e "${YELLOW}--->${COLOR_OFF} Adding changed files to git"
113+
git add CHANGES.rst README.rst ${INIT_PACKAGE_NAME}/__init__.py
114+
if [ -f docs/conf.py ]; then git add docs/conf.py; fi
115+
116+
echo -e "${YELLOW}--->${COLOR_OFF} Creating release"
117+
git commit -q -m "Release version $next_version"
118+
119+
echo -e "${YELLOW}--->${COLOR_OFF} Tagging release"
120+
git tag -a $next_version -m "Release version $next_version"
121+
122+
echo -e "${YELLOW}--->${COLOR_OFF} Pushing release and tags to github"
123+
git push -q origin master && git push -q --tags
124+
125+
if [[ "$PUBLIC" == "true" ]]; then
126+
echo -e "${YELLOW}--->${COLOR_OFF} Creating python release"
127+
cp README.rst README
128+
python setup.py sdist bdist_wheel upload > /dev/null
129+
rm README
130+
fi
131+
132+
echo -e "\n${CYAN}RELEASED VERSION ${next_version}!${COLOR_OFF}\n"

0 commit comments

Comments
 (0)