♻️ misc(release): add error handling function
This commit is contained in:
parent
617a940cf8
commit
9585843b14
29
release
29
release
@ -5,10 +5,14 @@ set -eu
|
|||||||
|
|
||||||
VERSION_FORMAT="^v[0-9]+\.[0-9]+\.[0-9]+$"
|
VERSION_FORMAT="^v[0-9]+\.[0-9]+\.[0-9]+$"
|
||||||
|
|
||||||
|
exit_with_message() {
|
||||||
|
echo "$1" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
# Check for a clean working directory.
|
# Check for a clean working directory.
|
||||||
if [ -n "$(git status --porcelain)" ]; then
|
if [ -n "$(git status --porcelain)" ]; then
|
||||||
echo "Your working directory is dirty. Commit or stash your changes before running this script."
|
exit_with_message "Your working directory is dirty. Commit or stash your changes before running this script."
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Ensure the local repository is up-to-date.
|
# Ensure the local repository is up-to-date.
|
||||||
@ -16,21 +20,18 @@ echo "Updating local repository…"
|
|||||||
git fetch origin
|
git fetch origin
|
||||||
git_status=$(git status -uno)
|
git_status=$(git status -uno)
|
||||||
if echo "$git_status" | grep -q "Your branch is behind"; then
|
if echo "$git_status" | grep -q "Your branch is behind"; then
|
||||||
echo "Your local branch is behind the remote. Please pull the latest changes before running this script."
|
exit_with_message "Your local branch is behind the remote. Pull the latest changes before running this script."
|
||||||
exit 1
|
|
||||||
elif echo "$git_status" | grep -q "Your branch is ahead"; then
|
elif echo "$git_status" | grep -q "Your branch is ahead"; then
|
||||||
echo "Your local branch is ahead of the remote. Attempting to push changes..."
|
echo "Your local branch is ahead of the remote. Checking if local changes can be pushed…"
|
||||||
if git push --dry-run 2>&1 | grep -q "Everything up-to-date"; then
|
if git push --dry-run &> /dev/null; then
|
||||||
echo "Local changes can be pushed without conflicts. Proceeding with the release."
|
echo "Local changes can be pushed without conflicts. Proceeding with the release."
|
||||||
else
|
else
|
||||||
echo "Unable to push local changes. Please resolve any conflicts before running this script."
|
exit_with_message "Unable to push local changes. Resolve any conflicts before running this script."
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
elif ! echo "$git_status" | grep -q "Your branch is up to date"; then
|
elif ! echo "$git_status" | grep -q "Your branch is up to date"; then
|
||||||
echo "Unable to determine if branch is up to date. Please check your git status manually."
|
exit_with_message "Unable to determine if branch is up to date. Check your git status manually."
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
echo "Local repository is ready for release preparation."
|
echo "Local repository is ready for release."
|
||||||
|
|
||||||
# Check if a version tag is provided.
|
# Check if a version tag is provided.
|
||||||
if [ "$#" -eq 1 ]; then
|
if [ "$#" -eq 1 ]; then
|
||||||
@ -45,15 +46,13 @@ else
|
|||||||
echo "Proceeding with version $suggested_version."
|
echo "Proceeding with version $suggested_version."
|
||||||
VERSION_TAG=$suggested_version
|
VERSION_TAG=$suggested_version
|
||||||
else
|
else
|
||||||
echo "Release preparation cancelled."
|
exit_with_message "Release preparation cancelled."
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Verify that the version tag matches the expected format.
|
# Verify that the version tag matches the expected format.
|
||||||
if ! [[ $VERSION_TAG =~ $VERSION_FORMAT ]]; then
|
if ! [[ $VERSION_TAG =~ $VERSION_FORMAT ]]; then
|
||||||
echo "Version tag $VERSION_TAG does not match the expected format ${VERSION_FORMAT}."
|
exit_with_message "Version tag $VERSION_TAG does not match the expected format ${VERSION_FORMAT}."
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Preparing release ${VERSION_TAG}…"
|
echo "Preparing release ${VERSION_TAG}…"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user