Skip to content
This repository was archived by the owner on Jun 30, 2021. It is now read-only.

Commit 3e21b3c

Browse files
committed
Automate releases via github.com/hub
1 parent 326c503 commit 3e21b3c

File tree

6 files changed

+84
-9
lines changed

6 files changed

+84
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ tmposx/
2828
*.log
2929
NEXT_RELEASE.md
3030
temp.md
31+
git_shortlog.stdout

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Travis [steps](https://docs.travis-ci.com/user/docker/#Pushing-a-Docker-Image-to
4545
travis env set DOCKER_EMAIL [email protected]
4646
travis env set DOCKER_USERNAME elgalubot
4747
travis env set DOCKER_PASSWORD secretsecret #1st space in purpose
48-
travis env set GH_TOKEN secretsecret
48+
travis env set GITHUB_TOKEN secretsecret
4949

5050
### Bot setup
5151
#### github.com

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.6.0-p6
1+
3.6.0-p7

test/before_install_setup

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ if [ "${TRAVIS_OS_NAME}" = "osx" ]; then
1111
# docker --version || exit 0
1212
# docker --version && exit 1 #that's how I'll know
1313
./test/before_install_docker_osx
14+
# https://github.com/github/hub#homebrew
15+
brew install hub
1416
else
1517
sudo -E bash -c './test/before_install_docker_linux'
18+
sudo -E bash -c './test/install_hub_cli'
1619
fi
1720
docker --version || (echo "FATAL: No docker installed" && exit 1)
1821

test/install_hub_cli

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
3+
# set -e: exit asap if a command exits with a non-zero status
4+
# set -x: print each command right before it is executed
5+
set -xe
6+
7+
mkdir -p tmp_hub
8+
cd tmp_hub
9+
10+
wget -nv -O hub.tgz "https://github.com/github/hub/releases/download/v2.3.0-pre10/hub-linux-amd64-2.3.0-pre10.tgz"
11+
tar -xvzf hub.tgz
12+
./hub*/bin/hub --version
13+
mv hub*/bin/hub /usr/bin/
14+
15+
cd ..
16+
rm -rf tmp_hub

test/script_push

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ git_config() {
7777
git_co_fetch_merge_stash() {
7878
echo "script_push::git_co_fetch_merge_stash"
7979
git checkout -b travis-${TRAVIS_TAG}
80-
git remote add github "https://elgalubot:${GH_TOKEN}@github.com/elgalu/docker-selenium.git"
80+
git remote add github "https://elgalubot:${GITHUB_TOKEN}@github.com/elgalu/docker-selenium.git"
8181
git fetch github
8282
git stash save || true
8383
git checkout -t github/master -b github/master
@@ -171,10 +171,41 @@ generate_NEXT_RELEASE_by_updating_TBDs() {
171171
sed -i -- "s/TBD_TIME_ZONE/${TBD_TIME_ZONE}/g" NEXT_RELEASE.md || true
172172
sed -i -- "s/UBUNTU_FLAVOR/${UBUNTU_FLAVOR}/g" NEXT_RELEASE.md || true
173173
sed -i -- "s/UBUNTU_DATE/${UBUNTU_DATE}/g" NEXT_RELEASE.md || true
174+
}
175+
176+
#############################################################
177+
# Add commits grouped by authors in between NEXT_RELEASE.md #
178+
#############################################################
179+
add_commits_to_NEXT_RELEASE() {
180+
# Get commits history grouped by author
181+
# https://www.kernel.org/pub/software/scm/git/docs/git-log.html#_pretty_formats
182+
# e.g. git shortlog --format="[%h] %s" 3.6.0-p6..HEAD
183+
# e.g. git shortlog --format="[%h] %s" --no-merges --author='^(?!Leo Gallucci Bot).*$' --perl-regexp 3.6.0-p6..HEAD
184+
rm -f git_shortlog.stdout
185+
git shortlog \
186+
--format="[%h] %s" \
187+
--no-merges \
188+
--author='^(?!Leo Gallucci Bot).*$' --perl-regexp \
189+
${TBD_PREV_COM}..HEAD > git_shortlog.stdout
190+
191+
# Add some indentation prefix
192+
sed -i -e 's/^/ + /' git_shortlog.stdout
193+
194+
# Use a temporal file
195+
rm -f temp.md
196+
mv NEXT_RELEASE.md temp.md
197+
198+
# Add first 2 lines to the final new release change log part
199+
head -n 2 temp.md > NEXT_RELEASE.md
174200

175-
# TODO: Add `git shortlog ${TBD_PREV_COM}..HEAD` with indent ` + ` in the 3rd line
176-
# ...
201+
# Add git short log with indent ` + ` in the 3rd line of NEXT_RELEASE.md
202+
cat git_shortlog.stdout >> NEXT_RELEASE.md
177203

204+
# Add the rest of the original NEXT_RELEASE.md
205+
tail -n +3 temp.md >> NEXT_RELEASE.md
206+
207+
# Remove intermediate files
208+
rm temp.md git_shortlog.stdout
178209
}
179210

180211
add_NEXT_RELEASE_to_top_of_CHANGELOG() {
@@ -185,7 +216,28 @@ add_NEXT_RELEASE_to_top_of_CHANGELOG() {
185216
}
186217

187218
github_release_from_NEXT_RELEASE() {
188-
echo "TODO: Release via GH API"
219+
echo "Release via GH API"
220+
221+
[ -z "${GITHUB_TOKEN}" ] && die "Need env var GITHUB_TOKEN"
222+
[ "${TRAVIS_TAG}" == "" ] && die "Need env var TRAVIS_TAG"
223+
224+
hub --version || die "github.com/hub is not installed!"
225+
226+
# If the release exists, delete it
227+
if hub release | grep -q "^${TRAVIS_TAG}\$"; then
228+
hub release delete "${TRAVIS_TAG}"
229+
fi
230+
231+
# https://github.com/github/hub/blob/master/share/man/man1/hub.1.ronn#L123
232+
export HUB_VERBOSE=1
233+
234+
# https://github.com/github/hub/blob/master/commands/release.go#L59
235+
# TODO: Add real assents (.deb, ...)
236+
hub release create \
237+
--asset "Dockerfile" \
238+
--asset "capabilities.json" \
239+
--file "NEXT_RELEASE.md" \
240+
"${TRAVIS_TAG}"
189241
}
190242

191243
#########################
@@ -194,8 +246,8 @@ github_release_from_NEXT_RELEASE() {
194246
update_changelog() {
195247
echo "script_push::update_changelog"
196248
generate_NEXT_RELEASE_by_updating_TBDs
249+
add_commits_to_NEXT_RELEASE
197250
add_NEXT_RELEASE_to_top_of_CHANGELOG
198-
github_release_from_NEXT_RELEASE
199251
}
200252

201253
####################################
@@ -224,7 +276,7 @@ git_push_tag_push() {
224276
if git push github HEAD:master >git_push_master.log 2>&1; then \
225277
failed=false; else failed=true; fi
226278
# hide secrets
227-
sed -i -- "s/${GH_TOKEN}/\[SECRET\]/g" git_push_master.log || true
279+
sed -i -- "s/${GITHUB_TOKEN}/\[SECRET\]/g" git_push_master.log || true
228280
if [ ${failed} == "true" ]; then
229281
echoerr "Failed to git push to master!"
230282
cat git_push_master.log 1>&2
@@ -237,7 +289,7 @@ git_push_tag_push() {
237289
if git push --tags -f >git_push_tags.log 2>&1; then \
238290
failed=false; else failed=true; fi
239291
# hide secrets
240-
sed -i -- "s/${GH_TOKEN}/\[SECRET\]/g" git_push_tags.log || true
292+
sed -i -- "s/${GITHUB_TOKEN}/\[SECRET\]/g" git_push_tags.log || true
241293
if [ ${failed} == "true" ]; then
242294
echoerr "Failed to push git tags!"
243295
cat git_push_master.log 1>&2
@@ -272,6 +324,9 @@ elif [ "${TRAVIS_TAG}" != "latest" ] && [ "${TRAVIS_TAG}" != "" ]; then
272324
update_changelog
273325
git_diff_add_commit
274326
git_push_tag_push
327+
github_release_from_NEXT_RELEASE
328+
# Remove intermediate files (optional)
329+
rm NEXT_RELEASE.md
275330
else
276331
echo "This is not git tagged so no version push to docker"
277332
fi

0 commit comments

Comments
 (0)