This repository was archived by the owner on Mar 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrelease.sh
executable file
·93 lines (76 loc) · 2.55 KB
/
release.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
set -ex -o pipefail
# Check pre-conditions
if ! [ -f .bumpversion.cfg ]; then
echo "No bumpversion config found, not releasing."
exit 0
fi
if [[ -n "$TRAVIS_PULL_REQUEST" && "$TRAVIS_PULL_REQUEST" != false ]]; then
echo "In a pull request build, not releasing"
exit 0
fi
if [[ -n "$TRAVIS_TAG" ]]; then
echo "In a tag build, not releasing"
exit 0
fi
if [ -z "$GITHUB_TOKEN" ]; then
echo "Error: GITHUB_TOKEN not set"
exit 1
fi
if git show --name-only --pretty='format:' HEAD | grep -qF .bumpversion.cfg; then
echo "Version manually bumped, not releasing"
exit 0
fi
if [ -z "$BUMPVERSION_PRERELEASE_PART" ]; then
bumpversion_prerelease_part="patch"
else
bumpversion_prerelease_part=$BUMPVERSION_PRERELEASE_PART
fi
if [ -z "$1" ]; then
bumpversion_part="patch"
else
bumpversion_part=$1
fi
# Configure git for pushing
git config --global user.email "[email protected]"
git config --global user.name "Cobli CD"
git remote set-url --push origin "https://cobli-cd:${GITHUB_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git"
git checkout "$TRAVIS_BRANCH"
# Install Deps
# Forked githubrelease to fix a issue related to encoding (https://github.com/j0057/github-release/issues/40)
export PYTHONIOENCODING=utf8
[ -x venv ] || virtualenv venv
source venv/bin/activate
pip install "git+https://github.com/peritus/bumpversion.git" \
"git+https://github.com/Cobliteam/github-release.git" \
'urllib3[secure]'
# Fetch tags so bumpversion fails in case of duplicates
git fetch --tags
new_version=$(bumpversion -n --list $bumpversion_part \
| grep new_version \
| sed -E 's/new_version\s*=\s*//')
new_tag="v${new_version}"
# If in master bump release
bumpversion $bumpversion_part \
--commit --tag --tag-name='v{new_version}' \
--message 'Release {new_version} [ci skip]'
# Make the Github releases
gen_release_notes() {
local last_tag=$(git describe --tags --abbrev=0 "${new_tag}^" | head -n1)
local start_date=$(git log -1 --format='%ai' "$last_tag")
local merges=$(git log --merges "${last_tag}..${new_tag}^" --format=$' - %b' | sed -E '/^\s*$/d')
if [ -n "$merges" ]; then
echo "Merges since $start_date:"
echo
echo "$merges"
else
local shortlog=$(git shortlog "${last_tag}..${new_tag}^")
echo "Changes since $start_date:"
echo "<pre>"
echo "$shortlog"
echo "</pre>"
fi
}
githubrelease release "$TRAVIS_REPO_SLUG" create "$new_tag"
githubrelease release "$TRAVIS_REPO_SLUG" edit "$new_tag" --body "$(gen_release_notes)"
githubrelease release "$TRAVIS_REPO_SLUG" publish "$new_tag"