Last active
September 27, 2022 11:29
-
-
Save Tjitse-E/d36b0c8a97df3a8ea15ad79b3008b1cf to your computer and use it in GitHub Desktop.
Fix common errors in CHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
sed=$(which sed) | |
if [ "$(uname -s)" = "Darwin" ] | |
then | |
sed=$(which gsed) | |
fi | |
# Fix incorrect date format. For example 1-01-2021 | |
$sed -i -E "s/^([0-9])-([0-9]{2})-([0-9]{4})/0\1-\2-\3/" CHANGELOG.md | |
# Fix European dates, convert to US | |
for i in $(cat CHANGELOG.md | grep -o -E '\d{2}-\d{2}-\d{4}') | |
do | |
exploded=( $(echo $i | grep -Eo '\d{2,4}') ) | |
day="${exploded[1]}" | |
month="${exploded[2]}" | |
year="${exploded[3]}" | |
usDate="${year}-${month}-${day}" | |
$sed -i "s/${i}/${usDate}/" CHANGELOG.md | |
done | |
# Remove release from changelog | |
$sed -i -E "s/## Release/##/" CHANGELOG.md | |
# Fix bullet list that starts with space | |
$sed -i -E "s/^\s-/-/g" CHANGELOG.md | |
# Fix h2 themes | |
$sed -i -E "s/^#{2}\s([a-zA-Z]+)/### \1/g" CHANGELOG.md | |
# Fix comments, prefix with - | |
$sed -i -E "2,6 ! s/^([^#-]+)/- \1/" CHANGELOG.md | |
# Fix incorrect bullet | |
# For example: | |
# -[DEV] | |
# There should be a space between the hyphen and the first word | |
$sed -i -E "s/^-(\S)/- \1/" CHANGELOG.md | |
# Also fix the incorrect releases. That look like this: | |
# 2.1.2 2022-01-01 | |
# Add a hyphen between the release version and the date | |
$sed -i -E "s/^## ([0-9\.]+) ([0-9-]+)$/## \1 - \2/" CHANGELOG.md | |
# Fix releases without dates. We'll use the date 2012-12-21. | |
$sed -i -E "s/^## ([0,9]\.[0-9]{1,3}\.[0-9]{1,3})$/## \1 - 2012-12-21/" CHANGELOG.md | |
$sed -i -E "s/^## ([0-9]\.[0-9]{1,3}\.[0-9]{1,3}) ?$/## \1 - 2012-12-21/" CHANGELOG.md | |
# Change updated theme | |
$sed -i -E "s/### Updated/### Changed/" CHANGELOG.md | |
echo "Done! Check your CHANGELOG.md" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment