-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsync-version.sh
executable file
·50 lines (40 loc) · 1.05 KB
/
sync-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
#!/bin/bash
# This script is used to sync the version number of the current branch with the previous branch.
current_branch=$(git branch --show-current)
env_file="release.env"
lines=()
while IFS= read -r line; do
lines+=("$line")
done < "$env_file"
previous_version=()
found_previous_branch=0
for (( i=0; i<${#lines[@]}; i++ )); do
line="${lines[i]}"
if [[ "$line" =~ ^([a-zA-Z0-9_]+)$ ]]; then
if [ "$line" == "$current_branch" ]; then
if [ "$found_previous_branch" -eq 1 ]; then
break
else
exit 0
fi
fi
found_previous_branch=1
previous_version=()
fi
if [[ "$line" =~ ^(MAJOR=|MINOR=|PATCH=) ]]; then
previous_version+=("$line")
fi
done
if [ ${#previous_version[@]} -ne 0 ]; then
for (( i=0; i<${#lines[@]}; i++ )); do
if [[ "${lines[i]}" == "$current_branch" ]]; then
lines[i+1]="${previous_version[0]}"
lines[i+2]="${previous_version[1]}"
lines[i+3]="${previous_version[2]}"
break
fi
done
printf "%s\n" "${lines[@]}" > "$env_file"
else
exit 0
fi