-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjvm_build.sh
75 lines (65 loc) · 2.59 KB
/
jvm_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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
set -e
# Create output directory
mkdir -p build_output
chmod -R 777 .
# initial contents
printf '{}\n' > build_output/results.json
# If a bootstrap script exists, run it first
if [ -f "./bootstrap_script.sh" ]; then
echo "Running bootstrap script..."
source ./bootstrap_script.sh
fi
echo "Running JVM build script..."
# Install jq
apt-get update -yqq && apt-get install -yqq jq
# Initialize build issues count and diagnostic log
issues="-1"
diagnostic_log="[]"
# Detect build tool and run appropriate build command
if [ -f "gradlew" ] || [ -f "./gradlew" ]; then
echo "Gradle project detected"
chmod +x ./gradlew
./gradlew build -x test --console=plain > build.log 2>&1 || true
issues=$(grep -c "FAILURE" build.log || true)
build_tool="gradle"
# Extract failure messages into diagnostic log
diagnostic_log=$(grep "FAILURE" build.log | jq -R -s 'split("\n")[:-1]' || echo "[]")
elif [ -f "build.gradle" ] || [ -f "build.gradle.kts" ]; then
echo "Gradle project detected"
gradle build -x test --console=plain > build.log 2>&1 || true
issues=$(grep -c "FAILURE" build.log || true)
build_tool="gradle"
# Extract failure messages into diagnostic log
diagnostic_log=$(grep "FAILURE" build.log | jq -R -s 'split("\n")[:-1]' || echo "[]")
elif [ -f "mvnw" ] || [ -f "./mvnw" ]; then
echo "Maven project detected"
chmod +x ./mvnw
./mvnw compile -DskipTests -B > build.log 2>&1 || true
issues=$(grep -c "\[ERROR\]" build.log || true)
build_tool="maven"
# Extract error messages into diagnostic log
diagnostic_log=$(grep "\[ERROR\]" build.log | jq -R -s 'split("\n")[:-1]' || echo "[]")
elif [ -f "pom.xml" ]; then
echo "Maven project detected"
mvn compile -DskipTests -B > build.log 2>&1 || true
issues=$(grep -c "\[ERROR\]" build.log || true)
build_tool="maven"
# Extract error messages into diagnostic log
diagnostic_log=$(grep "\[ERROR\]" build.log | jq -R -s 'split("\n")[:-1]' || echo "[]")
else
echo "No supported build tool found"
exit 1
fi
# Add build tool and issues to results
jq --arg tool "$build_tool" \
--arg issues "$issues" \
'. + {"build_tool": $tool, "issues_count": ($issues|tonumber)}' \
build_output/results.json > build_output/temp.json && \
mv build_output/temp.json build_output/results.json
# Add diagnostic log to results
echo "$diagnostic_log" > build_output/diagnostic_log.json
jq -s '.[0] * {"diagnostic_log": .[1]}' build_output/results.json build_output/diagnostic_log.json > build_output/temp.json && \
mv build_output/temp.json build_output/results.json
chmod -R 777 .
exit 0