-
Notifications
You must be signed in to change notification settings - Fork 1
/
builder.sh
135 lines (113 loc) · 4.48 KB
/
builder.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
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash +x
wget https://raw.githubusercontent.com/mevan-karu/pom_version_property_finder/master/src/version_property_finder.py
echo ""
echo "=========================================================="
echo " PR_LINK: $PR_LINK"
USER=$(echo $PR_LINK | awk -F'/' '{print $4}')
REPO=$(echo $PR_LINK | awk -F'/' '{print $5}')
PULL_NUMBER=$(echo $PR_LINK | awk -F'/' '{print $7}')
PR_LINK=${PR_LINK%/}
echo " USER: $USER"
echo " REPO: $REPO"
echo " PULL_NUMBER: $PULL_NUMBER"
echo "::set-output name=REPO_NAME::$REPO"
echo "=========================================================="
echo "Cloning product-is"
echo "=========================================================="
git clone https://github.com/wso2/product-is
echo ""
echo "PR is for the dependency repository $REPO."
echo ""
echo "Cloning $USER/$REPO"
echo "=========================================================="
git clone https://github.com/$USER/$REPO
echo ""
echo "Determining dependency version property key..."
echo "=========================================================="
VERSION_PROPERTY=$(python version_property_finder.py $REPO product-is 2>&1)
VERSION_PROPERTY_KEY=""
if [ "$VERSION_PROPERTY" != "invalid" ]; then
echo "Version property key for the $REPO is $VERSION_PROPERTY"
VERSION_PROPERTY_KEY=$VERSION_PROPERTY
else
echo ""
echo "=========================================================="
echo "$REPO is not yet supported! Exiting..."
echo "=========================================================="
echo ""
echo "::error::PR builder not supprted"
exit 1
fi
echo ""
echo "Property key found: $VERSION_PROPERTY_KEY"
cd $REPO
DEPENDENCY_VERSION=$(mvn -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec)
echo "Dependency Version: $DEPENDENCY_VERSION"
echo ""
echo "Applying PR $PULL_NUMBER as a diff..."
echo "=========================================================="
wget -q --output-document=diff.diff $PR_LINK.diff
cat diff.diff
echo "=========================================================="
git apply diff.diff || {
echo 'Applying diff failed. Exiting...'
echo "::error::Applying diff failed."
exit 1
}
echo ""
echo "Building dependency repo $REPO..."
echo "=========================================================="
mvn clean install --batch-mode | tee mvn-build.log
echo ""
echo "Dependency repo $REPO build complete."
echo "Built version: $DEPENDENCY_VERSION"
echo "=========================================================="
echo ""
REPO_BUILD_STATUS=$(cat mvn-build.log | grep "\[INFO\] BUILD" | grep -oE '[^ ]+$')
REPO_TEST_RESULT=$(sed -n -e '/Results :/,/Tests run:/ p' mvn-build.log)
REPO_FINAL_RESULT=$(
echo "==========================================================="
echo "$REPO BUILD $REPO_BUILD_STATUS"
echo "=========================================================="
echo ""
echo "Built version: $DEPENDENCY_VERSION"
echo ""
echo "$REPO_TEST_RESULT"
)
REPO_BUILD_RESULT_LOG_TEMP=$(echo "$REPO_FINAL_RESULT" | sed 's/$/%0A/')
REPO_BUILD_RESULT_LOG=$(echo $REPO_BUILD_RESULT_LOG_TEMP)
echo "::warning::$REPO_BUILD_RESULT_LOG"
if [ "$REPO_BUILD_STATUS" != "SUCCESS" ]; then
echo "$REPO BUILD not successfull. Aborting."
echo "::error::$REPO BUILD not successfull. Check artifacts for logs."
exit 1
fi
cd ../product-is
echo "Updating dependency version in product-is..."
echo "=========================================================="
echo ""
sed -i "s/<$VERSION_PROPERTY_KEY>.*<\/$VERSION_PROPERTY_KEY>/<$VERSION_PROPERTY_KEY>$DEPENDENCY_VERSION<\/$VERSION_PROPERTY_KEY>/" pom.xml
cat pom.xml
mvn clean install --batch-mode | tee mvn-build.log
PR_BUILD_STATUS=$(cat mvn-build.log | grep "\[INFO\] BUILD" | grep -oE '[^ ]+$')
PR_TEST_RESULT=$(sed -n -e '/\[INFO\] Results:/,/\[INFO\] Tests run:/ p' mvn-build.log)
PR_BUILD_FINAL_RESULT=$(
echo "==========================================================="
echo "product-is BUILD $PR_BUILD_STATUS"
echo "=========================================================="
echo ""
echo "$PR_TEST_RESULT"
)
PR_BUILD_RESULT_LOG_TEMP=$(echo "$PR_BUILD_FINAL_RESULT" | sed 's/$/%0A/')
PR_BUILD_RESULT_LOG=$(echo $PR_BUILD_RESULT_LOG_TEMP)
echo "::warning::$PR_BUILD_RESULT_LOG"
if [ "$PR_BUILD_STATUS" != "SUCCESS" ]; then
echo "PR BUILD not successfull. Aborting."
echo "::error::PR BUILD not successfull. Check artifacts for logs."
exit 1
fi
echo ""
echo "=========================================================="
echo "Build completed"
echo "=========================================================="
echo ""