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 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485
|
#!/bin/sh
#
# Put into Public Domain, by Nicolas Sebrecht
#
# Create new releases in OfflineIMAP.
# TODO: https://developer.github.com/v3/repos/releases/#create-a-release
# https://developer.github.com/libraries/
# https://github.com/turnkeylinux/octohub
# https://github.com/michaelliao/githubpy (onefile)
# https://github.com/sigmavirus24/github3.py
# https://github.com/copitux/python-github3
# https://github.com/PyGithub/PyGithub
# https://github.com/micha/resty (curl)
# TODO: move configuration out and source it.
# TODO: implement rollback.
__VERSION__='v0.3'
SPHINXBUILD=sphinx-build
MAILING_LIST='offlineimap-project@lists.alioth.debian.org'
GITHUB_FILE_LINK_PREFIX='https://raw.githubusercontent.com/OfflineIMAP/offlineimap'
DOCSDIR='docs'
ANNOUNCE_MAGIC='#### Notes '
CHANGELOG_MAGIC='{:toc}'
CHANGELOG='Changelog.md'
CACHEDIR='.git/offlineimap-release'
WEBSITE='website'
WEBSITE_LATEST="${WEBSITE}/_data/latest.yml"
TMP_CHANGELOG_EXCERPT="${CACHEDIR}/changelog.excerpt.md"
TMP_CHANGELOG_EXCERPT_OLD="${TMP_CHANGELOG_EXCERPT}.old"
TMP_CHANGELOG="${CACHEDIR}/changelog.md"
TMP_ANNOUNCE="${CACHEDIR}/announce.txt"
True=0
False=1
Yes=$True
No=$False
DEBUG=$True
#
# $1: EXIT_CODE
# $2..: message
function die () {
n=$1
shift
echo $*
exit $n
}
function debug () {
if test $DEBUG -eq $True
then
echo "DEBUG: $*" >&2
fi
}
#
# $1: question
# $2: message on abort
#
function ask () {
echo
echo -n "--- $1 "
read -r ans
test "n$ans" = 'n' -o "n$ans" = 'ny' && return $Yes
test "n$ans" = "ns" -o "n$ans" = 'nn' && return $No
die 1 "! $2"
}
#
# $1: message
# $1: path to file
#
function edit_file () {
ask "Press Enter to $1"
test $? -eq $Yes && {
$EDITOR "$2"
reset
}
}
function fix_pwd () {
debug 'in fix_pwd'
cd "$(git rev-parse --show-toplevel)" || \
die 2 "cannot determine the root of the repository"
}
function prepare_env () {
debug 'in prepare_env'
mkdir "$CACHEDIR" 2>/dev/null
test ! -d "$CACHEDIR" && die 5 "Could not make cache directory $CACHEDIR"
}
function check_dirty () {
debug 'in check_dirty'
git diff --quiet 2>/dev/null && git diff --quiet --cached 2>/dev/null || {
die 4 "Commit all your changes first!"
}
}
function welcome () {
debug 'in welcome'
cat <<EOF
You will be prompted to answer questions.
Answer by:
- 'y' : yes, continue (default)
- '<Enter>' : yes, continue
- 'n' : no
- 's' : skip (ONLY where applicable, otherwise continue)
Any other key will abort the program.
EOF
ask 'Ready?'
}
function checkout_next () {
debug 'in checkout_next'
git checkout --quiet next || {
die 6 "Could not checkout 'next' branch"
}
}
function merge_maint () {
debug 'in merge_maint'
git merge --quiet -Xours maint || {
die 7 "Could not merge 'maint' branch"
}
}
function get_version () {
debug 'in get_version'
echo "v$(./offlineimap.py --version)"
}
function update_offlineimap_version () {
debug 'in update_offlineimap_version'
edit_file 'update the version in __init__.py' offlineimap/__init__.py
}
#
# $1: previous version
#
function get_git_history () {
debug 'in get_git_history'
git log --format='- %h %s. [%aN]' --no-merges "${1}.."
}
#
# $1: previous version
#
function get_git_who () {
debug 'in get_git_who'
git shortlog --no-merges -sn "${1}.." | \
sed -r -e 's, +([0-9]+)\t(.*),- \2 (\1),'
}
#
# $1: new version
# $2: shortlog
function changelog_template_part1 () {
debug 'in changelog_template_part1'
cat <<EOF
// vim: expandtab ts=2 syntax=markdown
// WARNING: let at least one empy line before the real content.
//
// Write a new Changelog entry.
//
// Comments MUST start at the beginning of the lile with two slashes.
// They will by be ignored by the template engine.
//
### OfflineIMAP $1 ($(date +%Y-%m-%d))
#### Notes
// Add some notes. Good notes are about what was done in this release from the
// bigger perspective.
// HINT: explain most important changes.
#### Authors
EOF
}
function changelog_template_part2 () {
debug 'in changelog_template_part2'
cat <<EOF
#### Features
// Use list syntax with '- '
#### Fixes
// Use list syntax with '- '
#### Changes
// Use list syntax with '- '
// The preformatted log was added below. Make use of this to fill the sections
// above.
EOF
}
#
# $1: new version
# $2: previous version
#
function update_changelog () {
debug 'in update_changelog'
# Write Changelog excerpt.
if test ! -f "$TMP_CHANGELOG_EXCERPT"
then
changelog_template_part1 "$1" > "$TMP_CHANGELOG_EXCERPT"
get_git_who "$2" >> "$TMP_CHANGELOG_EXCERPT"
changelog_template_part2 >> "$TMP_CHANGELOG_EXCERPT"
get_git_history "$2" >> "$TMP_CHANGELOG_EXCERPT"
edit_file "the Changelog excerpt" $TMP_CHANGELOG_EXCERPT
# Remove comments.
grep -v '//' "$TMP_CHANGELOG_EXCERPT" > "${TMP_CHANGELOG_EXCERPT}.nocomment"
mv -f "${TMP_CHANGELOG_EXCERPT}.nocomment" "$TMP_CHANGELOG_EXCERPT"
fi
# Write new Changelog.
cat "$CHANGELOG" > "$TMP_CHANGELOG"
debug "include excerpt $TMP_CHANGELOG_EXCERPT to $TMP_CHANGELOG"
sed -i -e "/${CHANGELOG_MAGIC}/ r ${TMP_CHANGELOG_EXCERPT}" "$TMP_CHANGELOG"
debug 'remove trailing whitespaces'
sed -i -r -e 's, +$,,' "$TMP_CHANGELOG" # Remove trailing whitespaces.
debug "copy to $TMP_CHANGELOG -> $CHANGELOG"
cp -f "$TMP_CHANGELOG" "$CHANGELOG"
# Check and edit Changelog.
ask "Next step: you'll be asked to review the diff of $CHANGELOG"
while true
do
git diff -- "$CHANGELOG" | less
ask 'edit Changelog?' $CHANGELOG
test ! $? -eq $Yes && break
# Asked to edit the Changelog; will loop again.
$EDITOR "$CHANGELOG"
done
}
#
# $1: new version
#
function git_release () {
debug 'in git_release'
git commit -as -m"$1"
git tag -a "$1" -m"$1"
git checkout master
git merge next
git checkout next
}
function get_last_rc () {
git tag | grep -E '^v([0-9][\.-]){3}rc' | sort -V | tail -n1
}
function get_last_stable () {
git tag | grep -E '^v([0-9][\.])+' | grep -v '\-rc' | sort -V | tail -n1
}
function update_website_releases_info() {
cat > "$WEBSITE_LATEST" <<EOF
# DO NOT EDIT MANUALLY: it is generated by a script (release.sh)
stable: $(get_last_stable)
rc: $(get_last_rc)
EOF
}
#
# $1: new version
#
function update_website () {
debug 'in update_website'
ask "update API of the website? (require $SPHINXBUILD)"
if test $? -eq $Yes
then
# Check sphinx is available.
$SPHINXBUILD --version > /dev/null 2>&1
if test ! $? -eq 0
then
echo "Oops! you don't have $SPHINXBUILD installed?"
echo "Cannot update the webite documentation..."
echo "You should install it and run:"
echo " $ cd docs"
echo " $ make websitedoc"
echo "Then, commit and push changes of the website."
ask 'continue'
return
fi
# Check website sources are available.
cd website
if test ! $? -eq 0
then
echo "ERROR: cannot go to the website sources"
ask 'continue'
return
fi
# Stash any WIP in the website sources.
git diff --quiet 2>/dev/null && git diff --quiet --cached 2>/dev/null || {
echo "There is WIP in the website repository, stashing"
echo "git stash create 'WIP during offlineimap API import'"
git stash create 'WIP during offlineimap API import'
ask 'continue'
}
cd .. # Back to offlineimap.git.
update_website_releases_info
cd "./$DOCSDIR" # Enter the docs directory in offlineimap.git.
# Build the docs!
make websitedoc && {
# Commit changes in a branch.
cd ../website # Enter the website sources.
branch_name="import-$1"
git checkout -b "$branch_name"
git add '_doc/versions'
git commit -a -s -m"update for offlineimap $1"
echo "website: branch '$branch_name' ready for a merge in master!"
}
ask 'website updated locally; continue'
fi
}
function git_username () {
git config --get user.name
}
function git_usermail () {
git config --get user.email
}
#
# $1: new version
#
function announce_header () {
cat <<EOF
Message-Id: <$(git log HEAD~1.. --oneline --pretty='%H.%t.release.%ce')>
Date: $(git log HEAD~1.. --oneline --pretty='%cD')
From: $(git_username) <$(git_usermail)>
To: $MAILING_LIST
Subject: [ANNOUNCE] OfflineIMAP $1 released
OfflineIMAP $1 is out.
Downloads:
http://github.com/OfflineIMAP/offlineimap/archive/${1}.tar.gz
http://github.com/OfflineIMAP/offlineimap/archive/${1}.zip
Pip:
wget "${GITHUB_FILE_LINK_PREFIX}/${1}/requirements.txt" -O requirements.txt
pip install -r ./requirements.txt --user git+https://github.com/OfflineIMAP/offlineimap.git@${1}
EOF
}
function announce_footer () {
cat <<EOF
--
$(git_username)
EOF
}
#
# $1: new version
# $2: previous version
#
function build_announce () {
announce_header "$1" > "$TMP_ANNOUNCE"
grep -v '^### OfflineIMAP' "$TMP_CHANGELOG_EXCERPT" | \
grep -v '^#### Notes' >> "$TMP_ANNOUNCE"
sed -i -r -e "s,^$ANNOUNCE_MAGIC,," "$TMP_ANNOUNCE"
sed -i -r -e "s,^#### ,# ," "$TMP_ANNOUNCE"
announce_footer >> "$TMP_ANNOUNCE"
}
function edit_announce () {
edit_file 'edit announce' "$TMP_ANNOUNCE"
}
#
# run
#
function run () {
debug 'in run'
fix_pwd
check_dirty
prepare_env
checkout_next
clear
welcome
if test -f "$TMP_CHANGELOG_EXCERPT"
then
head "$TMP_CHANGELOG_EXCERPT"
ask "A previous Changelog excerpt (head above) was found, use it?"
if test ! $? -eq $Yes
then
mv -f "$TMP_CHANGELOG_EXCERPT" "$TMP_CHANGELOG_EXCERPT_OLD"
fi
fi
previous_version="$(get_version)"
message="Safety check: release after version:"
ask "$message $previous_version ?"
update_offlineimap_version
new_version="$(get_version)"
ask "Safety check: make a new release with version: '$new_version'" "Clear changes and restart"
update_changelog "$new_version" "$previous_version"
build_announce "$new_version" "$previous_version"
edit_announce
# Wait for the mainline and announce to be built to not include commits from
# maint.
merge_maint
git_release $new_version
# Wait for all the Changelogs to be up-to-date in next.
update_website $new_version
}
run
cat <<EOF
Release is ready!
Make your checks and push the changes for both offlineimap and the website.
Announce template stands in '$TMP_ANNOUNCE'.
Command samples to do manually:
- git push <remote> master next $new_version
- python setup.py sdist && twine upload dist/* && rm -rf dist MANIFEST
- cd website
- git checkout master
- git merge $branch_name
- git push <remote> master
- cd ..
- git send-email $TMP_ANNOUNCE
Have fun! ,-)
EOF
# vim: expandtab ts=2 :
|