Skip to content
This repository was archived by the owner on Jan 19, 2018. It is now read-only.

Commit 0ebf267

Browse files
authored
Merge pull request #787 from cdrage/release-script
Add release script for Atomic App
2 parents acf6613 + dc0393d commit 0ebf267

File tree

1 file changed

+326
-0
lines changed

1 file changed

+326
-0
lines changed

script/release.sh

Lines changed: 326 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,326 @@
1+
#!/bin/bash
2+
UPSTREAM_REPO="projectatomic"
3+
CLI="atomicapp"
4+
LIBRARY="nulecule-library"
5+
6+
7+
usage() {
8+
echo "This will prepare Atomic App for release!"
9+
echo ""
10+
echo "Requirements:"
11+
echo " git"
12+
echo " gpg - with a valid GPG key already generated"
13+
echo " hub"
14+
echo " github-release"
15+
echo " GITHUB_TOKEN in your env variable"
16+
echo " "
17+
echo "Not only that, but you must have permission for:"
18+
echo " Tagging releases for Atomic App on Github"
19+
echo " Access to hub.docker.com builds"
20+
echo ""
21+
}
22+
23+
requirements() {
24+
if [ ! -f /usr/bin/git ] && [ ! -f /usr/local/bin/git ]; then
25+
echo "No git. What's wrong with you?"
26+
return 1
27+
fi
28+
29+
if [ ! -f /usr/bin/gpg ] && [ ! -f /usr/local/bin/gpg ]; then
30+
echo "No gpg. What's wrong with you?"
31+
return 1
32+
fi
33+
34+
if [ ! -f $GOPATH/bin/github-release ]; then
35+
echo "No $GOPATH/bin/github-release. Please run 'go get -v github.com/aktau/github-release'"
36+
return 1
37+
fi
38+
39+
if [ ! -f /usr/bin/hub ]; then
40+
echo "No hub. Please run install hub @ github.com/github/hub"
41+
return 1
42+
fi
43+
44+
if [[ -z "$GITHUB_TOKEN" ]]; then
45+
echo "export GITHUB_TOKEN=yourtoken needed for using github-release"
46+
fi
47+
}
48+
49+
# Clone and then change to user's upstream repo for pushing to master / opening PR's :)
50+
clone() {
51+
git clone ssh://git@github.com/$UPSTREAM_REPO/$CLI.git
52+
if [ $? -eq 0 ]; then
53+
echo OK
54+
else
55+
echo FAIL
56+
exit
57+
fi
58+
cd $CLI
59+
git remote remove origin
60+
git remote add origin git@github.com:$ORIGIN_REPO/$CLI.git
61+
git checkout -b release-$1
62+
cd ..
63+
}
64+
65+
replaceversion() {
66+
cd $CLI
67+
OLD_VERSION=`python setup.py --version`
68+
echo "OLD VERSION:" $OLD_VERSION
69+
70+
echo "1. Replaced Dockerfile versioning"
71+
find . -name 'Dockerfile*' -type f -exec sed -i "s/$OLD_VERSION/$1/g" {} \;
72+
73+
echo "2. Replaced .py versioning"
74+
find . -name '*.py' -type f -exec sed -i "s/$OLD_VERSION/$1/g" {} \;
75+
76+
echo "3. Replaced docs versioning"
77+
find docs/ -name '*.md' -type f -exec sed -i "s/$OLD_VERSION/$1/g" {} \;
78+
79+
echo "4. Replaced README.md versioning"
80+
sed -i "s/$OLD_VERSION/$1/g" README.md
81+
82+
cd ..
83+
}
84+
85+
changelog() {
86+
cd $CLI
87+
echo "Getting commit changes. Writing to ../changes.txt"
88+
LOG=`git shortlog --email --no-merges --pretty=%s ${1}..`
89+
echo -e "\`\`\`\n$LOG\n\`\`\`" > ../changes.txt
90+
echo "Changelog has been written to changes.txt"
91+
echo "!!PLEASE REVIEW BEFORE CONTINUING!!"
92+
echo "Open changes.txt and add the release information"
93+
echo "to the beginning of the file before the git shortlog"
94+
cd ..
95+
}
96+
97+
changelog_md() {
98+
echo "Generating CHANGELOG.md"
99+
CHANGES=$(cat changes.txt)
100+
cd $CLI
101+
DATE=$(date +"%m-%d-%Y")
102+
CHANGELOG=$(cat CHANGELOG.md)
103+
HEADER="## Atomic App $1 ($DATE)"
104+
echo -e "$HEADER\n\n$CHANGES\n\n$CHANGELOG" >CHANGELOG.md
105+
echo "Changes have been written to CHANGELOG.md"
106+
cd ..
107+
}
108+
109+
git_commit() {
110+
cd $CLI
111+
112+
BRANCH=`git symbolic-ref --short HEAD`
113+
if [ -z "$BRANCH" ]; then
114+
echo "Unable to get branch name, is this even a git repo?"
115+
return 1
116+
fi
117+
echo "Branch: " $BRANCH
118+
119+
git add .
120+
git commit -m "$1 Release"
121+
git push origin $BRANCH
122+
hub pull-request -b $UPSTREAM_REPO/$CLI:master -h $ORIGIN_REPO/$CLI:$BRANCH
123+
124+
cd ..
125+
echo ""
126+
echo "PR opened against master"
127+
echo ""
128+
}
129+
130+
sign() {
131+
# Tarball it!
132+
cp -r $CLI $CLI-$1
133+
sudo rm -rf $CLI-$1/.git*
134+
sudo tar czf $CLI-$1.tar.gz $CLI-$1
135+
if [ $? -eq 0 ]; then
136+
echo TARBALL OK
137+
else
138+
echo TARBALL FAIL
139+
exit
140+
fi
141+
142+
# Sign it!
143+
echo -e "SIGN THE TARBALL!\n"
144+
gpg --detach-sign --armor $CLI-$1.tar.gz
145+
if [ $? -eq 0 ]; then
146+
echo SIGN OK
147+
else
148+
echo SIGN FAIL
149+
exit
150+
fi
151+
152+
echo ""
153+
echo "The tar.gz. is now located at $CLI-$1.tar.gz"
154+
echo "and the signed one at $CLI-$1.tar.gz.asc"
155+
echo ""
156+
}
157+
158+
push() {
159+
CHANGES=$(cat changes.txt)
160+
# Release it!
161+
github-release release \
162+
--user $UPSTREAM_REPO \
163+
--repo $CLI \
164+
--tag $1 \
165+
--name "$1" \
166+
--description "$CHANGES"
167+
if [ $? -eq 0 ]; then
168+
echo RELEASE UPLOAD OK
169+
else
170+
echo RELEASE UPLOAD FAIL
171+
exit
172+
fi
173+
174+
github-release upload \
175+
--user $UPSTREAM_REPO \
176+
--repo $CLI \
177+
--tag $1 \
178+
--name "$CLI-$1.tar.gz" \
179+
--file $CLI-$1.tar.gz
180+
if [ $? -eq 0 ]; then
181+
echo TARBALL UPLOAD OK
182+
else
183+
echo TARBALL UPLOAD FAIL
184+
exit
185+
fi
186+
187+
github-release upload \
188+
--user $UPSTREAM_REPO \
189+
--repo $CLI\
190+
--tag $1 \
191+
--name "$CLI-$1.tar.gz.asc" \
192+
--file $CLI-$1.tar.gz.asc
193+
if [ $? -eq 0 ]; then
194+
echo SIGNED TARBALL UPLOAD OK
195+
else
196+
echo SIGNED TARBALL UPLOAD FAIL
197+
exit
198+
fi
199+
200+
echo "DONE"
201+
echo "DOUBLE CHECK IT:"
202+
echo "!!!"
203+
echo "https://github.com/$UPSTREAM_REPO/$CLI/releases/edit/$1"
204+
echo "!!!"
205+
echo "REMEMBER TO UPDATE DOCKER BUILDS! :D"
206+
}
207+
208+
update_library() {
209+
BRANCH=sync-with-$1
210+
rm -rf $LIBRARY
211+
212+
# Clone
213+
git clone ssh://git@github.com/$UPSTREAM_REPO/$LIBRARY.git
214+
if [ $? -eq 0 ]; then
215+
echo OK
216+
else
217+
echo FAIL
218+
exit
219+
fi
220+
cd $LIBRARY
221+
git remote remove origin
222+
git remote add origin git@github.com:$ORIGIN_REPO/$LIBRARY.git
223+
git checkout -b $BRANCH
224+
225+
# Commit
226+
find . -type f -iname 'Dockerfile' -exec sed -i "s,^FROM.projectatomic*,FROM projectatomic/atomicapp:$1," "{}" +;
227+
git add .
228+
git commit -m "Sync with $1 release"
229+
git push origin $BRANCH
230+
hub pull-request -b $UPSTREAM_REPO/$LIBRARY:master -h $ORIGIN_REPO/$LIBRARY:$BRANCH
231+
cd ..
232+
}
233+
234+
clean() {
235+
rm -rf $CLI $CLI-$1 $CLI-$1.tar.gz $CLI-$1.tar.gz.asc $LIBRARY changes.txt
236+
}
237+
238+
main() {
239+
local cmd=$1
240+
usage
241+
242+
echo "What is your Github username? (location of your atomicapp fork)"
243+
read ORIGIN_REPO
244+
echo "You entered: $ORIGIN_REPO"
245+
echo ""
246+
247+
echo ""
248+
echo "First, please enter the version of the NEW release: "
249+
read VERSION
250+
echo "You entered: $VERSION"
251+
echo ""
252+
253+
echo ""
254+
echo "Second, please enter the version of the LAST release: "
255+
read PREV_VERSION
256+
echo "You entered: $PREV_VERSION"
257+
echo ""
258+
259+
clear
260+
261+
echo "Now! It's time to go through each step of releasing Atomic App!"
262+
echo "If one of these steps fails / does not work, simply re-run ./release.sh"
263+
echo "Re-enter the information at the beginning and continue on the failed step"
264+
echo ""
265+
266+
PS3='Please enter your choice: '
267+
options=(
268+
"Git clone master"
269+
"Replace version number"
270+
"Generate changelog"
271+
"Generate changelog for release"
272+
"Create PR against atomicapp"
273+
"!!! Before continuing, make sure the Atomic App release PR has been merged !!!"
274+
"Update and create PR against nulecule-library"
275+
"Tarball and sign atomicapp - requires gpg key"
276+
"Upload the tarball and push to Github release page"
277+
"!!! Build the new atomicapp docker image on hub.docker.com with the tagged release and then merge the nulecule-library PR !!!"
278+
"Clean"
279+
"Quit")
280+
select opt in "${options[@]}"
281+
do
282+
echo ""
283+
case $opt in
284+
"Git clone master")
285+
clone $VERSION
286+
;;
287+
"Replace version number")
288+
replaceversion $VERSION
289+
;;
290+
"Generate changelog")
291+
changelog $PREV_VERSION
292+
;;
293+
"Generate changelog for release")
294+
changelog_md $VERSION
295+
;;
296+
"Create PR against atomicapp")
297+
git_commit $VERSION
298+
;;
299+
"Update and create PR against nulecule-library")
300+
update_library $VERSION
301+
;;
302+
"Tarball and sign atomicapp - requires gpg key")
303+
sign $VERSION
304+
;;
305+
"Upload the tarball and push to Github release page")
306+
push $VERSION
307+
;;
308+
"Clean")
309+
clean $VERSION
310+
;;
311+
"Quit")
312+
clear
313+
break
314+
;;
315+
*) echo invalid option;;
316+
esac
317+
echo ""
318+
done
319+
}
320+
321+
main "$@"
322+
echo "If you're done, make sure you have done the following:"
323+
echo " Triggered hub.docker.com build for the new atomicapp version"
324+
echo " Merge the nulecule-library PR so the new containers have been created"
325+
echo " Upload the new release to download.projectatomic.io and edit index.html"
326+
echo ""

0 commit comments

Comments
 (0)