-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathrelease.sh
executable file
·147 lines (125 loc) · 3.21 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/bin/bash -e
VERSION_FILE="learnosity_sdk/_version.py"
CHANGELOG="ChangeLog.md"
check_git_clean () {
if [[ $(git status --porcelain | wc -l) -gt 0 ]]; then
echo -e "Working directory not clean; please add/commit, \`make clean\` and/or \`git clean -fdx\`\n"
git status
exit 1
fi
}
expect_yes() {
if ! [[ "${prompt}" =~ [yY](es)* ]]
then
echo "Aborting..."
return 1
fi
return 0
}
check_version () {
version="$1"
if ! [[ "${version}" =~ ^v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]
then
echo -e "\\nThat version does not match semver (vM.m.r)"
return 1
else
return 0
fi
}
confirm_branch () {
current_branch=$(git rev-parse --abbrev-ref HEAD)
read -rp "Do you want to tag the current branch (${current_branch})? <y/N> " prompt
if ! expect_yes; then
echo "Please checkout the correct branch and retry."
exit 1
fi
}
get_hash () {
current_hash=$(git rev-parse HEAD)
}
list_last_tags () {
n_tags=5
echo "Last ${n_tags} tags:"
git tag --sort=v:refname | tail -n $n_tags
}
get_new_version () {
# Get new version to release
read -rp "What version do you want to release? " new_version
while ! check_version "$new_version"; do
read -rp "New version: " new_version
done
check_version "${new_version}"
}
get_prev_version () {
# Get previous version to generate release notes
read -rp "What previous version should be used to generate release notes? " prev_version
while ! check_version "$prev_version"; do
read -rp "Previous version: " prev_version
done
}
print_release_notes () {
# Print release notes
echo -e "\\nRelease notes: "
changelog=$(sed -n '/Unreleased/,/^## /{/^## /d;p}' "${CHANGELOG}")
echo -e "${changelog}"
}
confirm_tagging () {
# prompt to continue
read -rp "Are you sure you want to update the version and tag? <y/N> " prompt
expect_yes || exit 1
}
update_version () {
# update and commit local version file used by tracking telemetry
echo -e "\\nWriting version file..."
sed -i "s/^__version__ *=.*/__version__ = '${new_version}'/" ${VERSION_FILE}
echo -e "Updating ${CHANGELOG}..."
sed -i "s/^## \[Unreleased]$/&\n\n## [${new_version}] - $(date +%Y-%m-%d)/" "${CHANGELOG}"
echo -e "Committing release files..."
git add "${VERSION_FILE}" "${CHANGELOG}"
git commit --allow-empty -m "[RELEASE] ${new_version}"
}
create_tag () {
echo -e "\\nTagging..."
git tag -a "${new_version}" -m "[RELEASE] ${new_version}" \
-m "Changes:" -m "${changelog}"
}
confirm_push () {
# prompt to continue
read -rp "Are you sure you want to push the new tag? <y/N> " prompt
if ! expect_yes; then
revert_tag
exit 1
fi
}
push_tag () {
# push commit and tag
git push origin "${current_branch}"
git push origin tag "${new_version}"
}
test_dist() {
make dist || revert_tag
}
revert_tag() {
echo -e "\\nReverting tag..."
git tag -d "${new_version}"
git reset HEAD^
exit 1
}
handle_package_manager () {
# script or instructions to push to package manager
echo -e "\\nYou should now publish this version to the appropriate package manager"
}
check_git_clean
confirm_branch
get_hash
list_last_tags
get_new_version
get_prev_version
print_release_notes
confirm_tagging
update_version
create_tag
test_dist
confirm_push
push_tag
handle_package_manager