-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathafter_maven.sh
executable file
·40 lines (31 loc) · 1.54 KB
/
after_maven.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
#This script can be sourced after running maven
# It will fill a fill and source a file 'job.env'
# It will contain a few new variables
setProperty(){
if [ ! -e $3 ] ; then
touch $3
fi
awk -v pat="^$1=" -v value="$1=$2" 'BEGIN {found=0; } { if ($0 ~ pat) { found=1; print value; } else print $0; } END { if (! found) print value }' $3 > $3.tmp
mv -f $3.tmp $3 >/dev/null
}
setProperty "PROJECT_VERSION" "$(mvn -ntp help:evaluate -Dexpression=project.version -q -DforceStdout)" job.env
mapfile -t counts < <(find . -name 'surefire-reports' -exec find \{\} -name '*.txt' -print0 \; | xargs -0 cat 2>/dev/null | grep -E "^Tests run:" | awk -F'[, ]+' 'BEGIN {t=0; f=0; e=0; s=0} {t+=$3; f+=$5; e+=$7; s+=$9} END {print t"\n"f"\n"e"\n"s}' )
setProperty "JOB_ID_BUILD_STAGE" "$CI_JOB_ID" job.env
setProperty "MAVEN_TESTS_RUN" "${counts[0]}" job.env
setProperty "MAVEN_TESTS_FAILED" "${counts[1]}" job.env
setProperty "MAVEN_TESTS_ERROR" "${counts[2]}" job.env
setProperty "MAVEN_TESTS_SKIPPED" "${counts[3]}" job.env
# make sure some files exist otherwise 'reports' gets confused
if [ ${counts[0]} -eq 0 ]; then
echo no tests found. Making empty suites
mkdir -p empty/target/surefire-reports ; echo '<testsuite />' > empty/target/surefire-reports/TEST-empty.xml
mkdir -p empty/target/failsafe-reports ; echo '<testsuite />' > empty/target/surefire-reports/TEST-empty.xml
fi
wc -l job.env
if [ -d target/site ]; then
cp -r target/site/* public
else
mkdir -p public
date --iso-8601=seconds > public/date
fi
source job.env