-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy path.make-release-support
104 lines (92 loc) · 3.12 KB
/
.make-release-support
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
#!/bin/bash
# Check if there are changes in the current Git repository
function hasChanges() {
test -n "$(git status -s .)"
}
# Get the release version from the .release file
function getRelease() {
if [[ -f .release ]]; then
awk -F= '/release/{print $2}' .release
fi
}
# Get the base tag from the .release file
function getBaseTag() {
# Extract the tag value and remove the release version from it
sed -n -e "s/tag=\\(.*\\)$(getRelease)\$/\\1/p" .release
}
# Get the complete tag for the current release
function getTag() {
if [[ -z "$1" ]] ; then
# If no version number is specified, return the tag from the .release file
awk -F= '/tag/{print $2}' .release
else
# Otherwise, append the specified version number to the base tag
echo "$(getBaseTag)$1"
fi
}
# Set the release version in the .release file and update the package.json file
function setRelease() {
if [[ -n "$1" ]] ; then
# Replace the tag and release version in the .release file
sed -i.x -e "s/tag=.*/tag=$(getTag "$1")/" .release
sed -i.x -e "s/release=.*/release=$1/g" .release
# Update the version number in the package.json file
sed -i.x -e '0,/"version": "[^"]*"/s//"version": "'$1'"/' package.json
# Remove backup files created by sed
rm -f .release.x
rm -f package.json.x
else
# Print an error message if no version number is specified
echo "ERROR: missing release version parameter " >&2
return 1
fi
}
# Check if a tag already exists for the current release
function tagExists() {
# Use the specified tag or the current tag if none is specified
tag=${1:-$(getTag)}
# Check if the tag exists in Git
test -n "$tag" && test -n "$(git tag | grep "^$tag\$")"
}
# Check if the current Git repository differs from the current release
function differsFromRelease() {
tag=$(getTag)
# Check if the tag does not exist or if there are differences between the current state and the tag
! tagExists "$tag" || test -n "$(git diff --shortstat -r "$tag" .)"
}
# Get the version number for the current release
function getVersion() {
result=$(getRelease)
if differsFromRelease; then
# Append the short hash of the latest commit if there are differences between the current state and the tag
result="$result-$(git rev-parse --short HEAD)"
fi
if hasChanges ; then
# Append "-dirty" if there are uncommitted changes in the Git repository
result="$result-dirty"
fi
echo "$result"
}
function nextMicroLevel() {
version=${1:-$(getRelease)}
# Increment the micro-level version number by 1
major_and_minor=$(echo "$version" | cut -d. -f1,2)
micro=$(echo "$version" | cut -d. -f3)
version=$(printf "%s.%d" "$major_and_minor" $((micro + 1)))
echo "$version"
}
# Get the next minor-level version number for the current release
function nextMinorLevel() {
version=${1:-$(getRelease)}
major=$(echo "$version" | cut -d. -f1);
minor=$(echo "$version" | cut -d. -f2);
version=$(printf "%d.%d.0" "$major" $((minor + 1))) ;
echo "$version"
}
# Get the next major-level version number for the current release
function nextMajorLevel() {
version=${1:-$(getRelease)}
major=$(echo "$version" | cut -d. -f1);
version=$(printf "%d.0.0" $((major + 1)))
echo "$version"
}