1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-11-28 20:41:48 +00:00

changelog file is optional in bump script

This commit is contained in:
Rob Ede 2023-07-17 01:47:26 +01:00
parent ce3af777a0
commit c34a18f64a
No known key found for this signature in database
GPG key ID: 97C636207D3EF933

View file

@ -1,4 +1,4 @@
#!/bin/sh #!/bin/bash
# developed on macOS and probably doesn't work on Linux yet due to minor # developed on macOS and probably doesn't work on Linux yet due to minor
# differences in flags on sed # differences in flags on sed
@ -21,12 +21,9 @@ README_FILE=$DIR/README.md
# determine changelog file name # determine changelog file name
if [ -f "$DIR/CHANGES.md" ]; then if [ -f "$DIR/CHANGES.md" ]; then
CHANGELOG_FILE=$DIR/CHANGES.md CHANGELOG_FILE="$DIR/CHANGES.md"
elif [ -f "$DIR/CHANGELOG.md" ]; then elif [ -f "$DIR/CHANGELOG.md" ]; then
CHANGELOG_FILE=$DIR/CHANGELOG.md CHANGELOG_FILE="$DIR/CHANGELOG.md"
else
echo "No changelog file found"
exit 1
fi fi
# get current version # get current version
@ -37,15 +34,17 @@ CHANGE_CHUNK_FILE="$(mktemp)"
echo saving changelog to $CHANGE_CHUNK_FILE echo saving changelog to $CHANGE_CHUNK_FILE
echo echo
# get changelog chunk and save to temp file if [ -n "${CHANGELOG_FILE-}" ]; then
cat "$CHANGELOG_FILE" | # get changelog chunk and save to temp file
# skip up to unreleased heading cat "$CHANGELOG_FILE" |
sed '1,/Unreleased/ d' | # skip up to unreleased heading
# take up to previous version heading sed '1,/Unreleased/ d' |
sed "/$CURRENT_VERSION/ q" | # take up to previous version heading
# drop last line sed "/$CURRENT_VERSION/ q" |
sed '$d' \ # drop last line
>"$CHANGE_CHUNK_FILE" sed '$d' \
>"$CHANGE_CHUNK_FILE"
fi
# if word count of changelog chunk is 0 then insert filler changelog chunk # if word count of changelog chunk is 0 then insert filler changelog chunk
if [ "$(wc -w "$CHANGE_CHUNK_FILE" | awk '{ print $1 }')" = "0" ]; then if [ "$(wc -w "$CHANGE_CHUNK_FILE" | awk '{ print $1 }')" = "0" ]; then
@ -68,8 +67,7 @@ if [ "${NEW_VERSION:0:1}" = "v" ]; then
NEW_VERSION="${NEW_VERSION:1}" NEW_VERSION="${NEW_VERSION:1}"
fi fi
DATE="$(date -u +"%Y-%m-%d")" echo "updating from $CURRENT_VERSION => $NEW_VERSION"
echo "updating from $CURRENT_VERSION => $NEW_VERSION ($DATE)"
# update package.version field # update package.version field
sed -i.bak -E "s/^version ?= ?\"[^\"]+\"$/version = \"$NEW_VERSION\"/" "$CARGO_MANIFEST" sed -i.bak -E "s/^version ?= ?\"[^\"]+\"$/version = \"$NEW_VERSION\"/" "$CARGO_MANIFEST"
@ -77,19 +75,21 @@ sed -i.bak -E "s/^version ?= ?\"[^\"]+\"$/version = \"$NEW_VERSION\"/" "$CARGO_M
# update readme # update readme
[ -f "$README_FILE" ] && sed -i.bak -E "s#$CURRENT_VERSION([/)])#$NEW_VERSION\1#g" "$README_FILE" [ -f "$README_FILE" ] && sed -i.bak -E "s#$CURRENT_VERSION([/)])#$NEW_VERSION\1#g" "$README_FILE"
# update changelog file if [ -n "${CHANGELOG_FILE-}" ]; then
( # update changelog file
sed '/Unreleased/ q' "$CHANGELOG_FILE" # up to unreleased heading (
echo # blank line sed '/Unreleased/ q' "$CHANGELOG_FILE" # up to unreleased heading
echo "## $NEW_VERSION - $DATE" # new version heading echo # blank line
cat "$CHANGE_CHUNK_FILE" # previously unreleased changes echo "## $NEW_VERSION" # new version heading
sed "/$CURRENT_VERSION/ q" "$CHANGELOG_FILE" | tail -n 1 # the previous version heading cat "$CHANGE_CHUNK_FILE" # previously unreleased changes
sed "1,/$CURRENT_VERSION/ d" "$CHANGELOG_FILE" # everything after previous version heading sed "/$CURRENT_VERSION/ q" "$CHANGELOG_FILE" | tail -n 1 # the previous version heading
) >"$CHANGELOG_FILE.bak" sed "1,/$CURRENT_VERSION/ d" "$CHANGELOG_FILE" # everything after previous version heading
mv "$CHANGELOG_FILE.bak" "$CHANGELOG_FILE" ) >"$CHANGELOG_FILE.bak"
mv "$CHANGELOG_FILE.bak" "$CHANGELOG_FILE"
# format CHANGELOG file according to prettier # format CHANGELOG file according to prettier
npx -y prettier --write "$CHANGELOG_FILE" || true npx -y prettier --write "$CHANGELOG_FILE" || true
fi
# done; remove backup files # done; remove backup files
rm -f $CARGO_MANIFEST.bak rm -f $CARGO_MANIFEST.bak