forked from graphql-java-kickstart/graphql-java-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
github-build.sh
53 lines (42 loc) · 1.33 KB
/
github-build.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
#!/bin/bash
set -ev
getVersion() {
grep -m1 -o "<version>.*</version>$" pom.xml | awk -F'[><]' '{print $3}'
}
removeSnapshots() {
sed -i 's/-SNAPSHOT//' pom.xml
}
commitRelease() {
local APP_VERSION=$(getVersion)
git commit -a -m "Update version for release"
git tag -a "v${APP_VERSION}" -m "Tag release version"
}
bumpVersion() {
echo "Bump version number"
local APP_VERSION=$(getVersion | xargs)
local SEMANTIC_REGEX='^([0-9]+)\.([0-9]+)(\.([0-9]+))?$'
if [[ ${APP_VERSION} =~ ${SEMANTIC_REGEX} ]]; then
if [[ ${BASH_REMATCH[4]} ]]; then
nextVersion=$((BASH_REMATCH[4] + 1))
nextVersion="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.${nextVersion}-SNAPSHOT"
else
nextVersion=$((BASH_REMATCH[2] + 1))
nextVersion="${BASH_REMATCH[1]}.${nextVersion}-SNAPSHOT"
fi
echo "Next version: ${nextVersion}"
sed -i "0,/<version>.*<\/version>/s//<version>${nextVersion}<\/version>/" pom.xml
else
echo "No semantic version and therefore cannot publish to maven repository: '${APP_VERSION}'"
fi
}
commitNextVersion() {
git commit -a -m "Update version for release"
}
git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions"
echo "Deploying release to Maven Central"
removeSnapshots
mvn --batch-mode -Prelease deploy
commitRelease
bumpVersion
commitNextVersion