Skip to content

Commit 348a238

Browse files
committed
Add release script
1 parent 708b377 commit 348a238

File tree

1 file changed

+127
-0
lines changed

1 file changed

+127
-0
lines changed

release

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

0 commit comments

Comments
 (0)