2023-07-17 00:47:26 +00:00
|
|
|
#!/bin/bash
|
2021-11-30 14:12:04 +00:00
|
|
|
|
|
|
|
# developed on macOS and probably doesn't work on Linux yet due to minor
|
|
|
|
# differences in flags on sed
|
|
|
|
|
|
|
|
# requires github cli tool for automatic release draft creation
|
|
|
|
|
2023-12-23 19:17:56 +00:00
|
|
|
set -eEuo pipefail
|
2021-11-30 14:12:04 +00:00
|
|
|
|
|
|
|
DIR=$1
|
|
|
|
|
|
|
|
LINUX=""
|
|
|
|
MACOS=""
|
|
|
|
|
|
|
|
if [ "$(uname)" = "Darwin" ]; then
|
|
|
|
MACOS="1"
|
|
|
|
fi
|
|
|
|
|
|
|
|
CARGO_MANIFEST=$DIR/Cargo.toml
|
|
|
|
README_FILE=$DIR/README.md
|
|
|
|
|
2022-01-05 04:24:40 +00:00
|
|
|
# determine changelog file name
|
|
|
|
if [ -f "$DIR/CHANGES.md" ]; then
|
2023-07-17 00:47:26 +00:00
|
|
|
CHANGELOG_FILE="$DIR/CHANGES.md"
|
2022-01-05 04:24:40 +00:00
|
|
|
elif [ -f "$DIR/CHANGELOG.md" ]; then
|
2023-07-17 00:47:26 +00:00
|
|
|
CHANGELOG_FILE="$DIR/CHANGELOG.md"
|
2022-01-05 04:24:40 +00:00
|
|
|
fi
|
|
|
|
|
2021-11-30 14:12:04 +00:00
|
|
|
# get current version
|
|
|
|
PACKAGE_NAME="$(sed -nE 's/^name ?= ?"([^"]+)"$/\1/ p' "$CARGO_MANIFEST" | head -n 1)"
|
2022-01-19 02:09:25 +00:00
|
|
|
CURRENT_VERSION="$(sed -nE 's/^version ?= ?"([^"]+)"$/\1/ p' "$CARGO_MANIFEST" | head -n 1)"
|
2021-11-30 14:12:04 +00:00
|
|
|
|
|
|
|
CHANGE_CHUNK_FILE="$(mktemp)"
|
|
|
|
echo saving changelog to $CHANGE_CHUNK_FILE
|
|
|
|
echo
|
|
|
|
|
2023-07-17 00:47:26 +00:00
|
|
|
if [ -n "${CHANGELOG_FILE-}" ]; then
|
|
|
|
# get changelog chunk and save to temp file
|
|
|
|
cat "$CHANGELOG_FILE" |
|
|
|
|
# skip up to unreleased heading
|
|
|
|
sed '1,/Unreleased/ d' |
|
|
|
|
# take up to previous version heading
|
|
|
|
sed "/$CURRENT_VERSION/ q" |
|
|
|
|
# drop last line
|
|
|
|
sed '$d' \
|
|
|
|
>"$CHANGE_CHUNK_FILE"
|
|
|
|
fi
|
2021-11-30 14:12:04 +00:00
|
|
|
|
|
|
|
# if word count of changelog chunk is 0 then insert filler changelog chunk
|
|
|
|
if [ "$(wc -w "$CHANGE_CHUNK_FILE" | awk '{ print $1 }')" = "0" ]; then
|
2021-12-29 08:59:15 +00:00
|
|
|
echo "- No significant changes since \`$CURRENT_VERSION\`." >"$CHANGE_CHUNK_FILE"
|
2021-12-11 00:28:38 +00:00
|
|
|
echo >>"$CHANGE_CHUNK_FILE"
|
2021-11-30 14:12:04 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "${2-}" ]; then
|
|
|
|
NEW_VERSION="$2"
|
|
|
|
else
|
|
|
|
echo
|
|
|
|
echo "--- Changes since $CURRENT_VERSION ----"
|
|
|
|
cat "$CHANGE_CHUNK_FILE"
|
|
|
|
echo
|
|
|
|
read -p "Update version to: " NEW_VERSION
|
|
|
|
fi
|
|
|
|
|
2021-12-18 03:27:32 +00:00
|
|
|
# strip leading v from input
|
|
|
|
if [ "${NEW_VERSION:0:1}" = "v" ]; then
|
|
|
|
NEW_VERSION="${NEW_VERSION:1}"
|
|
|
|
fi
|
|
|
|
|
2023-07-17 00:47:26 +00:00
|
|
|
echo "updating from $CURRENT_VERSION => $NEW_VERSION"
|
2021-11-30 14:12:04 +00:00
|
|
|
|
|
|
|
# update package.version field
|
|
|
|
sed -i.bak -E "s/^version ?= ?\"[^\"]+\"$/version = \"$NEW_VERSION\"/" "$CARGO_MANIFEST"
|
|
|
|
|
|
|
|
# update readme
|
|
|
|
[ -f "$README_FILE" ] && sed -i.bak -E "s#$CURRENT_VERSION([/)])#$NEW_VERSION\1#g" "$README_FILE"
|
|
|
|
|
2023-07-17 00:47:26 +00:00
|
|
|
if [ -n "${CHANGELOG_FILE-}" ]; then
|
|
|
|
# update changelog file
|
|
|
|
(
|
|
|
|
sed '/Unreleased/ q' "$CHANGELOG_FILE" # up to unreleased heading
|
|
|
|
echo # blank line
|
|
|
|
echo "## $NEW_VERSION" # new version heading
|
|
|
|
cat "$CHANGE_CHUNK_FILE" # previously unreleased changes
|
|
|
|
sed "/$CURRENT_VERSION/ q" "$CHANGELOG_FILE" | tail -n 1 # the previous version heading
|
|
|
|
sed "1,/$CURRENT_VERSION/ d" "$CHANGELOG_FILE" # everything after previous version heading
|
|
|
|
) >"$CHANGELOG_FILE.bak"
|
|
|
|
mv "$CHANGELOG_FILE.bak" "$CHANGELOG_FILE"
|
|
|
|
|
|
|
|
# format CHANGELOG file according to prettier
|
|
|
|
npx -y prettier --write "$CHANGELOG_FILE" || true
|
|
|
|
fi
|
2023-02-26 00:55:57 +00:00
|
|
|
|
2021-11-30 14:12:04 +00:00
|
|
|
# done; remove backup files
|
|
|
|
rm -f $CARGO_MANIFEST.bak
|
|
|
|
rm -f $README_FILE.bak
|
|
|
|
|
2023-12-16 10:20:28 +00:00
|
|
|
if [ -n "${CHANGELOG_FILE-}" ]; then
|
|
|
|
rm -f $CHANGELOG_FILE.bak
|
|
|
|
fi
|
|
|
|
|
2021-11-30 14:12:04 +00:00
|
|
|
echo "manifest, changelog, and readme updated"
|
|
|
|
echo
|
|
|
|
echo "check other references:"
|
2022-07-22 19:19:15 +00:00
|
|
|
rg --glob='**/{Cargo.toml,README.md}' "\
|
2021-12-11 00:21:30 +00:00
|
|
|
${PACKAGE_NAME} ?= ?\"[^\"]+\"\
|
|
|
|
|${PACKAGE_NAME} ?=.*version ?= ?\"([^\"]+)\"\
|
|
|
|
|package ?= ?\"${PACKAGE_NAME}\".*version ?= ?\"([^\"]+)\"\
|
|
|
|
|version ?= ?\"([^\"]+)\".*package ?= ?\"${PACKAGE_NAME}\"" || true
|
|
|
|
|
|
|
|
echo
|
|
|
|
read -p "Update all references: (y/N) " UPDATE_REFERENCES
|
|
|
|
UPDATE_REFERENCES="${UPDATE_REFERENCES:-n}"
|
|
|
|
|
|
|
|
if [ "$UPDATE_REFERENCES" = 'y' ] || [ "$UPDATE_REFERENCES" = 'Y' ]; then
|
2024-01-08 15:17:36 +00:00
|
|
|
if [[ $NEW_VERSION == *".0.0" ]]; then
|
|
|
|
NEW_VERSION_SPEC="${NEW_VERSION%.0.0}"
|
|
|
|
elif [[ $NEW_VERSION == *".0" ]]; then
|
|
|
|
NEW_VERSION_SPEC="${NEW_VERSION%.0}"
|
|
|
|
else
|
|
|
|
NEW_VERSION_SPEC="$NEW_VERSION"
|
|
|
|
fi
|
2021-12-11 00:21:30 +00:00
|
|
|
|
|
|
|
for f in $(fd Cargo.toml); do
|
|
|
|
sed -i.bak -E \
|
2024-01-08 15:17:36 +00:00
|
|
|
"s/^(${PACKAGE_NAME} ?= ?\")[^\"]+(\")$/\1${NEW_VERSION_SPEC}\2/g" $f
|
2021-12-11 00:21:30 +00:00
|
|
|
sed -i.bak -E \
|
2024-01-08 15:17:36 +00:00
|
|
|
"s/^(${PACKAGE_NAME} ?=.*version ?= ?\")[^\"]+(\".*)$/\1${NEW_VERSION_SPEC}\2/g" $f
|
2021-12-11 00:21:30 +00:00
|
|
|
sed -i.bak -E \
|
2024-01-08 15:17:36 +00:00
|
|
|
"s/^(.*package ?= ?\"${PACKAGE_NAME}\".*version ?= ?\")[^\"]+(\".*)$/\1${NEW_VERSION_SPEC}\2/g" $f
|
2021-12-11 00:21:30 +00:00
|
|
|
sed -i.bak -E \
|
2024-01-08 15:17:36 +00:00
|
|
|
"s/^(.*version ?= ?\")[^\"]+(\".*package ?= ?\"${PACKAGE_NAME}\".*)$/\1${NEW_VERSION_SPEC}\2/g" $f
|
2021-12-11 00:21:30 +00:00
|
|
|
|
|
|
|
# remove backup file
|
|
|
|
rm -f $f.bak
|
|
|
|
done
|
|
|
|
|
|
|
|
fi
|
2021-11-30 14:12:04 +00:00
|
|
|
|
|
|
|
if [ $MACOS ]; then
|
2023-08-29 00:18:37 +00:00
|
|
|
printf "chore($PACKAGE_NAME): prepare release $NEW_VERSION" | pbcopy
|
2023-12-23 19:17:56 +00:00
|
|
|
echo "placed the recommended commit message on the clipboard"
|
2021-11-30 14:12:04 +00:00
|
|
|
else
|
|
|
|
echo
|
|
|
|
echo "commit message:"
|
2023-08-29 00:18:37 +00:00
|
|
|
echo "chore($PACKAGE_NAME): prepare release $NEW_VERSION"
|
2021-11-30 14:12:04 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
SHORT_PACKAGE_NAME="$(echo $PACKAGE_NAME | sed 's/^actix-web-//' | sed 's/^actix-//')"
|
|
|
|
GIT_TAG="$(echo $SHORT_PACKAGE_NAME-v$NEW_VERSION)"
|
|
|
|
RELEASE_TITLE="$(echo $PACKAGE_NAME: v$NEW_VERSION)"
|
|
|
|
|
2021-12-18 03:27:32 +00:00
|
|
|
if [ "$(echo $NEW_VERSION | grep beta)" ] || [ "$(echo $NEW_VERSION | grep rc)" ] || [ "$(echo $NEW_VERSION | grep alpha)" ]; then
|
2023-02-26 00:55:57 +00:00
|
|
|
FLAGS="--prerelease"
|
|
|
|
else
|
|
|
|
FLAGS="--latest"
|
2021-12-18 03:27:32 +00:00
|
|
|
fi
|
|
|
|
|
2021-11-30 14:12:04 +00:00
|
|
|
echo
|
|
|
|
echo "GitHub release command:"
|
2023-02-26 00:55:57 +00:00
|
|
|
GH_CMD="gh release create \"$GIT_TAG\" --draft --title \"$RELEASE_TITLE\" --notes-file \"$CHANGE_CHUNK_FILE\" ${FLAGS:-}"
|
2021-12-18 03:27:32 +00:00
|
|
|
echo "$GH_CMD"
|
2021-11-30 14:12:04 +00:00
|
|
|
|
|
|
|
read -p "Submit draft GH release: (y/N) " GH_RELEASE
|
|
|
|
GH_RELEASE="${GH_RELEASE:-n}"
|
|
|
|
|
|
|
|
if [ "$GH_RELEASE" = 'y' ] || [ "$GH_RELEASE" = 'Y' ]; then
|
2021-12-18 03:27:32 +00:00
|
|
|
eval "$GH_CMD"
|
2021-11-30 14:12:04 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo
|