| 
 | 1 | +#!/bin/bash -e  | 
 | 2 | + | 
 | 3 | +# this script merges release notes for $VERSION into CHANGELOG.md  | 
 | 4 | +# the release date for $VERSION should be available in $RELEASE_DATE  | 
 | 5 | +# and the release notes for $VERSION should be available in /tmp/changelog-section.md  | 
 | 6 | + | 
 | 7 | +if [[ $VERSION =~ ^[0-9]+\.[0-9]+\.0 ]]; then  | 
 | 8 | +  # this was not a patch release, so the version exists already in the CHANGELOG.md  | 
 | 9 | + | 
 | 10 | +  # update the release date  | 
 | 11 | +  sed -Ei "s/## Version $VERSION .*/## Version $VERSION ($RELEASE_DATE)/" CHANGELOG.md  | 
 | 12 | + | 
 | 13 | +  # the entries are copied over from the release branch to support workflows  | 
 | 14 | +  # where change log entries may be updated after preparing the release branch  | 
 | 15 | + | 
 | 16 | +  {  | 
 | 17 | +    # copy the portion above the release, up to and including the heading  | 
 | 18 | +    sed -n "0,/^## Version $VERSION /p" CHANGELOG.md  | 
 | 19 | +    # copy the release notes for $VERSION  | 
 | 20 | +    cat /tmp/changelog-section.md  | 
 | 21 | +    # copy the portion below the release  | 
 | 22 | +    sed -n "0,/^## Version $VERSION /d;0,/^## Version /{/^## Version/!d};p" CHANGELOG.md  | 
 | 23 | +  } > /tmp/CHANGELOG.md  | 
 | 24 | + | 
 | 25 | +  # update the real CHANGELOG.md  | 
 | 26 | +  cp /tmp/CHANGELOG.md CHANGELOG.md  | 
 | 27 | + | 
 | 28 | +else  | 
 | 29 | +  # this was a patch release, so the version does not exist already in the CHANGELOG.md  | 
 | 30 | + | 
 | 31 | +  {  | 
 | 32 | +    # copy the portion above the top-most release, not including the heading  | 
 | 33 | +    sed -n "0,/^## Version /{ /^## Version /!p }" CHANGELOG.md  | 
 | 34 | +    # add the heading  | 
 | 35 | +    echo "## Version $VERSION ($RELEASE_DATE)"  | 
 | 36 | +    # copy the release notes for $VERSION  | 
 | 37 | +    cat /tmp/changelog-section.md  | 
 | 38 | +    # copy the portion starting from the top-most release  | 
 | 39 | +    sed -n "/^## Version /,\$p" CHANGELOG.md  | 
 | 40 | +  } > /tmp/CHANGELOG.md  | 
 | 41 | + | 
 | 42 | +  # update the real CHANGELOG.md  | 
 | 43 | +  cp /tmp/CHANGELOG.md CHANGELOG.md  | 
 | 44 | +fi  | 
0 commit comments