mirror of
https://github.com/digital-asset/daml.git
synced 2024-11-10 10:46:11 +03:00
94 lines
2.4 KiB
Bash
Executable File
94 lines
2.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -o errexit # stop the script each time a command fails
|
|
set -o nounset # stop if you attempt to use an undef variable
|
|
|
|
# This script updates a changelog file written according to [Keep a
|
|
# Changelog](http://keepachangelog.com/en/1.0.0/) format. It moves "Unreleased"
|
|
# section to a section that matches the new version and timestamps it.
|
|
#
|
|
# As a convenience to developers, this script updates all entries in form
|
|
# "[jira:XXXX]" to a right JIRA link.
|
|
|
|
# Input:
|
|
# - changelog file
|
|
# - version to assign
|
|
|
|
# Output:
|
|
# - nothing
|
|
|
|
UNRELEASED=$1
|
|
CHANGELOG=$2
|
|
VERSION=$3
|
|
|
|
RELDATE=$(date +'%Y-%m-%d')
|
|
|
|
# replace [jira:XXXX] with actual links to jira, only on lines starting with '-' (kind of sanity check)
|
|
gawk -i inplace '
|
|
/^[-*]/ { print gensub(/\[jira:([\-[:alnum:]]+)\]/, "[\\1](https://digitalasset.atlassian.net/browse/\\1)", "g") }
|
|
!/^[-*]/ { print }
|
|
' "$UNRELEASED"
|
|
|
|
# replace [pr:XXXX] with an actual link to GitHub.
|
|
sed -i -e 's|\[pr:\([0-9]\+\)\]|[#\1](https://github.com/DACH-NY/da/pull/\1)|g' "$UNRELEASED"
|
|
|
|
# clean up unused sections
|
|
# from: https://stackoverflow.com/questions/46729591/remove-empty-sections-in-markdown-with-bash
|
|
gawk -i inplace '
|
|
BEGIN {
|
|
inside_empty_section = "false"
|
|
buffer = ""
|
|
}
|
|
|
|
/^$/ { # Add the empty line to the current section buffer or print it
|
|
if (inside_empty_section == "true") { buffer = buffer $0 "\n" } else { print $0 }; next }
|
|
|
|
/^###/ {
|
|
# This is the beginning of a new section.
|
|
# Either the previous one was empty: just forget its buffer.
|
|
# either it was not empty and has already been printed.
|
|
# In any case, just start buffering a new empty section.
|
|
inside_empty_section = "true"
|
|
buffer = $0
|
|
next
|
|
}
|
|
|
|
{
|
|
# Found a non-empty line: the current section is NOT empty.
|
|
# If it was supposed to be empty, print its buffer.
|
|
if (inside_empty_section == "true") { print buffer }
|
|
inside_empty_section = "false"
|
|
print $0
|
|
next
|
|
}
|
|
' "$UNRELEASED"
|
|
|
|
TXTUNRELEASED=$(cat <<END_HEREDOC
|
|
$(sed '/## Unreleased/q' $UNRELEASED)
|
|
|
|
### Added
|
|
|
|
### Changed
|
|
|
|
### Fixed
|
|
|
|
### Removed
|
|
|
|
END_HEREDOC
|
|
)
|
|
# Get news for the Changelog
|
|
NEWS="## [$VERSION] - $RELDATE\n$(sed '1,/## Unreleased/d' $UNRELEASED)\n"
|
|
|
|
# reconstructing new UNRELEASED.md file
|
|
echo "$TXTUNRELEASED" >| "$UNRELEASED"
|
|
|
|
# Move sections from UNRELEASED to a CHANGELOG
|
|
gawk -v unreleased="$NEWS" -i inplace '
|
|
/^## / && ! inserted {
|
|
print unreleased
|
|
print ""
|
|
inserted++
|
|
}
|
|
{print}
|
|
' "$CHANGELOG"
|