generated from actions/hello-world-docker-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
executable file
·123 lines (110 loc) · 3.36 KB
/
entrypoint.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
116
117
118
119
120
121
122
123
#!/bin/bash
bumpVersionType=$1
bumpVersion=$2
setVersion=$3
pomLocations=$4
bumpChangelog=$5
changelogDesc=$6
pomVersionTag=$7
mainBranchName=$8
echo "Bump Version Type: $bumpVersionType"
echo "Bump Version: $bumpVersion"
echo "Set Version: $setVersion"
echo "POM Location(s): $pomLocations"
echo "Bump changelog: $bumpChangelog"
echo "Changelog Desc: $changelogDesc"
echo "POM Version Tag: $pomVersionTag"
echo "Main Branch Name: $mainBranchName"
while [ $# -gt 0 ]; do
if [[ $1 == *"--"* ]]; then
param="${1/--/}"
declare $param="$2"
fi
shift
done
IFS="," read -a pomLocationsArray <<< "$pomLocations"
git clean -f
git fetch
#echo git pull
#git pull --rebase
#echo git push
#git push
git show origin/"$mainBranchName":pom.xml > pom.xml.BAK
# Find Next_Version number
if [[ "$bumpVersionType" == "bump" ]]; then
if test -f "pom.xml"; then
CURR_VERSION=$(sed -n "s:.*<$pomVersionTag>\(.*\)</$pomVersionTag>.*:\1:p" pom.xml.BAK)
echo "Current Version: ${CURR_VERSION}"
MAJOR=$(echo ${CURR_VERSION} | cut -d '.' -f 1)
MINOR=$(echo ${CURR_VERSION} | cut -d '.' -f 2)
PATCH=$(echo ${CURR_VERSION} | cut -d '.' -f 3 | cut -d '-' -f 1)
case "$bumpVersion" in
patch)
((PATCH++))
;;
minor)
((MINOR++))
PATCH=0
;;
major)
((MAJOR++))
MINOR=0
PATCH=0
;;
esac
NEXT_VERSION="${MAJOR}.${MINOR}.${PATCH}"
else
echo "pom.xml does not exist"
exit
fi
elif [[ "$bumpVersionType" == "set" ]]; then
if [[ -z "$setVersion" ]]; then
echo "Cannot set version, no version specified"
exit
else
NEXT_VERSION="$setVersion"
fi
else
echo "${bumpVersionType} is not a valid bumpVersionType"
exit
fi
echo "Next Version: ${NEXT_VERSION}"
for (( i=0; i<${#pomLocationsArray[@]}; i++ )); do
# Update _pom.xml_ with the new Version Number
# i.bak is used as in-place flag that works both on Mac (BSD) and Linux
if test -f "${pomLocationsArray[$i]}"; then
sed -i.bak "s:<artifact-version>.*</artifact-version>:<artifact-version>${NEXT_VERSION}-SNAPSHOT</artifact-version>:" "${pomLocationsArray[$i]}"
rm "${pomLocationsArray[$i]}.bak"
echo "Updated Version number in ${pomLocationsArray[$i]} to ${NEXT_VERSION}"
else
echo "${pomLocationsArray[$i]} does not exist"
exit
fi
done
git checkout -m origin/"$mainBranchName" CHANGELOG.md
# i.bak is used as in-place flag that works both on Mac (BSD) and Linux
if [[ "$bumpChangelog" == "true" ]]; then
if test -f "CHANGELOG.md"; then
sed -i.bak "3i* v${NEXT_VERSION}\n * ${changelogDesc}" CHANGELOG.md
rm CHANGELOG.md.bak
echo "Changelog updated with ${NEXT_VERSION}: ${changelogDesc} "
else
echo "Changelog.md does not exist"
exit
fi
fi
# Commit changes
#git checkout "${GITHUB_HEAD_REF}"
git config user.name github-actions
git config user.email [email protected]
for (( i=0; i<${#pomLocationsArray[@]}; i++ )); do
if test -f "${pomLocationsArray[$i]}"; then
git add "${pomLocationsArray[$i]}"
fi
done
git add CHANGELOG.md
git commit -m "GitHub Action - pom.xml and CHANGELOG.md Automations"
echo "git pull"
git pull origin $mainBranchName
echo "git push"
git push -f origin HEAD:"${GITHUB_HEAD_REF}"