-
-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathversion_bump.sh
executable file
·80 lines (65 loc) · 1.8 KB
/
version_bump.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
# Documentation:
# This script bumps the project version number.
# You can append --no-semver to disable semantic version validation.
# Usage:
# version_bump.sh [--no-semver]
# e.g. `bash scripts/version_bump.sh`
# e.g. `bash scripts/version_bump.sh --no-semver`
# Exit immediately if a command exits with a non-zero status
set -e
# Use the script folder to refer to other scripts.
FOLDER="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
SCRIPT_VERSION_NUMBER="$FOLDER/version_number.sh"
# Parse --no-semver argument
VALIDATE_SEMVER=true
for arg in "$@"; do
case $arg in
--no-semver)
VALIDATE_SEMVER=false
shift # Remove --no-semver from processing
;;
esac
done
# Start script
echo ""
echo "Bumping version number..."
echo ""
# Get the latest version
VERSION=$($SCRIPT_VERSION_NUMBER)
if [ $? -ne 0 ]; then
echo "Failed to get the latest version"
exit 1
fi
# Print the current version
echo "The current version is: $VERSION"
# Function to validate semver format, including optional -rc.<INT> suffix
validate_semver() {
if [ "$VALIDATE_SEMVER" = false ]; then
return 0
fi
if [[ $1 =~ ^v?[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?$ ]]; then
return 0
else
return 1
fi
}
# Prompt user for new version
while true; do
read -p "Enter the new version number: " NEW_VERSION
# Validate the version number to ensure that it's a semver version
if validate_semver "$NEW_VERSION"; then
break
else
echo "Invalid version format. Please use semver format (e.g., 1.2.3, v1.2.3, 1.2.3-rc.1, etc.)."
exit 1
fi
done
# Push the new tag
git push -u origin HEAD
git tag $NEW_VERSION
git push --tags
# Complete successfully
echo ""
echo "Version tag pushed successfully!"
echo ""