merge-change-log-after-release.sh 1.6 KB

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