-
Notifications
You must be signed in to change notification settings - Fork 254
/
Copy pathbump-version.sh
executable file
·115 lines (95 loc) · 3.42 KB
/
bump-version.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/bash
# Function to get fromVersion from a file
populateFromVersion() {
build/build.sh
local versionString
versionString=$(./jf -v)
fromVersion=${versionString//[^0-9.+]/}
}
# Function to validate arguments
validateArg() {
# Check if both arguments are provided
if [ $# -ne 1 ]; then
echo "Error: Please provide exactly one argument - the version to bump."
exit 1
fi
}
validateVersions() {
# Extract arguments
fromVersion=$1
toVersion=$2
# Check if arguments are non-empty
if [ -z "$fromVersion" ] || [ -z "$toVersion" ]; then
echo "Error: Both fromVersion and toVersion must have non-empty values."
exit 1
fi
# Check if arguments are not identical
if [ "$fromVersion" = "$toVersion" ]; then
echo "Error: fromVersion and toVersion must have different values."
exit 1
fi
echo "Bumping version from $fromVersion to $toVersion"
}
createBranch() {
branchName="bump-ver-from-$fromVersion-to-$toVersion"
git remote rm upstream
git remote add upstream https://github.com/jfrog/jfrog-cli.git
git checkout dev
git fetch upstream dev
git reset --hard upstream/dev
git push
git checkout -b "$branchName"
}
# Function to replace version in file
replaceVersion() {
local filePath=$1
local line=$2
local fromVersion=$3
local toVersion=$4
# Check if the file exists
if [ ! -e "$filePath" ]; then
echo "Error: File '$filePath' not found."
exit 1
fi
# Use awk to replace the value if the line is found
awk -v line="$line" -v from="$fromVersion" -v to="$toVersion" '
index($0, line) {
gsub(from, to);
found=1;
}
{ print }
END {
if (found != 1) {
print "Error: The specified line ('" line "') does not exist in the file ('" filePath "').";
exit 1;
}
}
' "$filePath" > "$filePath.tmp" && mv "$filePath.tmp" "$filePath"
# Validate if the file was modified using git
if git diff --exit-code "$filePath" > /dev/null; then
echo "Error: File '$filePath' was not modified."
exit 1
fi
git add "$filePath"
}
## Validate the argument was received.
validateArg "$@"
## Read the script argument into the toVersion variable
toVersion=$1
## Call the function to populate the fromVersion argument from the current version of the local JFrog CLI binary
populateFromVersion
## Call the function to validate arguments
validateVersions "$fromVersion" "$toVersion"
## Create a new branch
createBranch
## Add calls to the function to replace version in file with specified filePath values
replaceVersion "utils/cliutils/cli_consts.go" "CliVersion = \"$fromVersion\"" "$fromVersion" "$toVersion"
replaceVersion "build/npm/v2/package-lock.json" "\"version\": \"$fromVersion\"," "$fromVersion" "$toVersion"
replaceVersion "build/npm/v2/package.json" "\"version\": \"$fromVersion\"," "$fromVersion" "$toVersion"
replaceVersion "build/npm/v2-jf/package-lock.json" "\"version\": \"$fromVersion\"," "$fromVersion" "$toVersion"
replaceVersion "build/npm/v2-jf/package.json" "\"version\": \"$fromVersion\"," "$fromVersion" "$toVersion"
## Print success message if validation and replacement pass
echo "Version bumped successfully."
## Push the new branch, with the version bump
git commit -m "Bump version from $fromVersion to $toVersion"
git push --set-upstream origin "$branchName"