|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# Collects the pull-requests since the latest release and |
| 4 | +# arranges them in the CHANGES.rst.txt file. |
| 5 | +# |
| 6 | +# This is a script to be run before releasing a new version. |
| 7 | +# |
| 8 | +# Usage /bin/bash update_changes.sh 1.0.1 |
| 9 | +# |
| 10 | + |
| 11 | +# Setting # $ help set |
| 12 | +set -u # Treat unset variables as an error when substituting. |
| 13 | +set -x # Print command traces before executing command. |
| 14 | + |
| 15 | +# Check whether the Upcoming release header is present |
| 16 | +head -1 CHANGES.rst | grep -q Upcoming |
| 17 | +UPCOMING=$? |
| 18 | +if [[ "$UPCOMING" == "0" ]]; then |
| 19 | + head -n3 CHANGES.rst >> newchanges |
| 20 | +fi |
| 21 | + |
| 22 | +# Elaborate today's release header |
| 23 | +HEADER="$1 ($(date '+%B %d, %Y'))" |
| 24 | +echo $HEADER >> newchanges |
| 25 | +echo $( printf "%${#HEADER}s" | tr " " "=" ) >> newchanges |
| 26 | +echo "" >> newchanges |
| 27 | + |
| 28 | +# Search for PRs since previous release |
| 29 | +MERGE_COMMITS=$( git log --grep="Merge pull request\|(#.*)$" `git describe --tags --abbrev=0`..HEAD --pretty='format:%h' ) |
| 30 | +for COMMIT in ${MERGE_COMMITS//\n}; do |
| 31 | + SUB=$( git log -n 1 --pretty="format:%s" $COMMIT ) |
| 32 | + if ( echo $SUB | grep "^Merge pull request" ); then |
| 33 | + # Merge commit |
| 34 | + PR=$( echo $SUB | sed -e "s/Merge pull request \#\([0-9]*\).*/\1/" ) |
| 35 | + TITLE=$( git log -n 1 --pretty="format:%b" $COMMIT ) |
| 36 | + else |
| 37 | + # Squashed merge |
| 38 | + PR=$( echo $SUB | sed -e "s/.*(\#\([0-9]*\))$/\1/" ) |
| 39 | + TITLE=$( echo $SUB | sed -e "s/\(.*\) (\#[0-9]*)$/\1/" ) |
| 40 | + fi |
| 41 | + echo "* $TITLE (#$PR)" >> newchanges |
| 42 | +done |
| 43 | +echo "" >> newchanges |
| 44 | +echo "" >> newchanges |
| 45 | + |
| 46 | +# Add back the Upcoming header if it was present |
| 47 | +if [[ "$UPCOMING" == "0" ]]; then |
| 48 | + tail -n+4 CHANGES.rst >> newchanges |
| 49 | +else |
| 50 | + cat CHANGES.rst >> newchanges |
| 51 | +fi |
| 52 | + |
| 53 | +# Replace old CHANGES.rst with new file |
| 54 | +mv newchanges CHANGES.rst |
0 commit comments