Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions scripts/version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,22 @@ esac
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
echo "$NEW_VERSION" > VERSION

TODAY=$(date +%Y-%m-%d)
CHANGELOG_TEMP=$(mktemp)

Comment on lines +49 to +50
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve the script's robustness, it's a good practice to ensure temporary files are cleaned up, especially when set -e is active. An unexpected error could cause the script to exit, leaving the temporary file behind. Using trap ensures the cleanup command is executed upon script exit, regardless of whether it's a normal exit or an error.

Suggested change
CHANGELOG_TEMP=$(mktemp)
CHANGELOG_TEMP=$(mktemp)
trap 'rm -f -- "$CHANGELOG_TEMP"' EXIT

cat > "$CHANGELOG_TEMP" << EOF
# Changelog

## [$NEW_VERSION] - $TODAY

*

EOF

if [ -f CHANGELOG.md ]; then
tail -n +3 CHANGELOG.md >> "$CHANGELOG_TEMP"
fi

mv "$CHANGELOG_TEMP" CHANGELOG.md

echo "Bumped version to $NEW_VERSION"
Loading