forked from open-eid/cdoc2-java-ref-impl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinc_versions.sh
executable file
·91 lines (80 loc) · 2.15 KB
/
inc_versions.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
#!/bin/bash
# Increase maven module version for changed modules based on git diff.
# Based on
# https://gist.github.com/corneil/20585cb944615abb434063b8507d2d8d
function itemInModules() {
local e
for e in ${MODULES}; do
if [[ "$e" == "$ITEM" ]]; then
echo "1"
return 0
fi
done
echo "0"
}
function addItem() {
if [ "$MODULES" == "" ]; then
echo "$1"
else
echo "$MODULES $1"
fi
}
PERFORM=true
while getopts ":d" opt; do
case ${opt} in
d)
echo "-d Dry-run mode"
PERFORM=false
;;
?)
echo "Invalid option: -${OPTARG}."
exit 1
;;
esac
done
# Find parent branch
#https://gist.github.com/joechrysler/6073741
#https://stackoverflow.com/questions/3161204/how-to-find-the-nearest-parent-of-a-git-branch?noredirect=1&lq=1
PARENT_BRANCH=$(git show-branch -a \
| grep '\*' \
| grep -v "$(git rev-parse --abbrev-ref HEAD)" \
| head -n1 \
| sed 's/.*\[\(.*\)\].*/\1/' \
| sed 's/[\^~].*//')
echo
echo "Using $PARENT_BRANCH as parent branch"
echo
MODIFIED=$(git diff --name-only "$PARENT_BRANCH")
ALL_MODULES=$(find . -name "pom.xml" -type f -exec dirname '{}' \; | sed 's/\.\///' | sort -r)
MODULES=
for file in $MODIFIED; do
#FILE=$(realpath $file)
echo "$file was changed"
for ITEM in $ALL_MODULES; do
if [[ "$ITEM" != "." ]] && [[ "$file" == *"$ITEM"* ]]; then
echo "Matched $ITEM"
HAS_ITEM=$(itemInModules)
if ((HAS_ITEM == 0)); then
MODULES=$(addItem "$ITEM")
fi
break
fi
done
done
#echo "All modules: $ALL_MODULES"
echo
echo "Changed modules: $MODULES"
echo
for module in $MODULES; do
if [[ "$PERFORM" = true ]]; then
MODULE_VERSION=$(mvn -f "$module" help:evaluate -Dexpression=project.version -q -DforceStdout)
if [[ ${MODULE_VERSION} == *"SNAPSHOT"* ]];then
echo "Ignoring $module as it already on SNAPSHOT "
else
echo "Creating -SNAPSHOT minor version for $module;"
mvn -f "$module" versions:set -DnextSnapshot -DnextSnapshotIndexToIncrement=2
fi
else
echo "Dry-run. Not increasing version for $module."
fi
done