103 lines
1.6 KiB
Bash
Executable file
103 lines
1.6 KiB
Bash
Executable file
#!/bin/sh
|
|
|
|
usage() {
|
|
printf "Usage: %s [-h] -f /path/to/CHANGELOG.md\n" "$0"
|
|
}
|
|
|
|
help() {
|
|
cat << EOH
|
|
SYNOPSIS
|
|
$0 [-h] -f /path/to/CHANGELOG.md
|
|
|
|
DESCRIPTION
|
|
|
|
$0 generates a markdown content of a changelog file.
|
|
|
|
OPTIONS
|
|
|
|
-h Show this help
|
|
|
|
-f FILE
|
|
Path to changelog
|
|
EOH
|
|
}
|
|
|
|
on_interrupt() {
|
|
print "Process aborted!\n"
|
|
|
|
exit 130
|
|
}
|
|
|
|
main() {
|
|
while getopts "hf:" option; do
|
|
case "${option}" in
|
|
h) help; exit 0;;
|
|
f) CHANGELOG_FILE="$OPTARG";;
|
|
*) usage; exit 1;;
|
|
esac
|
|
done
|
|
|
|
if [ -z "$CHANGELOG_FILE" ]; then
|
|
printf "The file of the changelog is required.\n"
|
|
exit 1
|
|
fi
|
|
|
|
if [ ! -f "$CHANGELOG_FILE" ]; then
|
|
printf "No such file: %s\n" "$CHANGELOG_FILE"
|
|
exit 1
|
|
fi
|
|
|
|
temp_directory="$(mktemp -d)"
|
|
version=
|
|
is_first=1
|
|
|
|
cat << EOF
|
|
---
|
|
hide:
|
|
- toc
|
|
---
|
|
|
|
# Changelog
|
|
|
|
EOF
|
|
|
|
|
|
while read -r line; do
|
|
if printf "%s" "$line" | grep -q -E '^## '; then
|
|
version="$(printf "%s" "$line" | sed 's/^## //')"
|
|
|
|
if [ "$version" = "[Unreleased]" ]; then
|
|
version=""
|
|
fi
|
|
elif [ -n "$version" ]; then
|
|
printf "%s\n" "$line" >> "$temp_directory/$version"
|
|
fi
|
|
done < "$CHANGELOG_FILE"
|
|
|
|
while read -r line; do
|
|
if printf "%s" "$line" | grep -q -E '^## '; then
|
|
version="$(printf "%s" "$line" | sed 's/^## //')"
|
|
|
|
if [ "$version" != "[Unreleased]" ]; then
|
|
if [ $is_first -eq 1 ]; then
|
|
printf "???+ success \"%s\"\n" "$version"
|
|
is_first=0
|
|
else
|
|
printf "??? abstract \"%s\"\n" "$version"
|
|
fi
|
|
|
|
sed \
|
|
-e 's/### \(.*\)/\n **\1**\n/g' \
|
|
-e 's/^/ /g' \
|
|
"$temp_directory/$version"
|
|
fi
|
|
fi
|
|
done < "$CHANGELOG_FILE"
|
|
|
|
exit 0
|
|
}
|
|
|
|
trap on_interrupt INT
|
|
|
|
main "$@"
|