File: zip.sh

package info (click to toggle)
golang-github-google-cel-go 0.18.2%2Bds-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,888 kB
  • sloc: sh: 93; makefile: 12
file content (69 lines) | stat: -rwxr-xr-x 2,119 bytes parent folder | download
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
#!/bin/bash
mkdir -p artifacts
touch artifacts/junit_01.xml

input="./bazel-out/k8-fastbuild/testlogs/conformance/ct_dashboard/test.xml"

echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > artifacts/junit_01.xml
echo "<testsuites>" >> artifacts/junit_01.xml
echo "<testsuite>" >> artifacts/junit_01.xml

while IFS= read -r line
do
  testline=$(echo $line | cut -c1-3)
  extendline=$(echo $line | cut -c1-4)
  testcase='<testcase name="'
  end='">'
  close_testcase="</testcase>"

  failure='<failure message="'
  close_failure="</failure>"

  # This checks if the line is a test line (starts with --- but not ----)
  if [ $testline = "---" ] && [ $extendline != '----' ]
  then
    status=$(echo $line | cut -c4-8) # The first four characters after --- are the pass/fail status of the test)
    name=$(echo $line | tail -c +11 | head -c -9) # The next string excluding the time is the name of the test
    echo "$testcase$name$end" >> artifacts/junit_01.xml
    if [ $status = "FAIL" ]
    then
      read line1
      message=$(echo "$line1" | sed 's/</\&lt;/g; s/>/\&gt;/g; s/"/\&quot;/g; s/&/\&amp;/g') # Quote the characters in the failure message that XML might interpret
      echo "$failure$message$end$close_failure" >> artifacts/junit_01.xml
    else
      echo $status >> artifacts/junit_01.xml
    fi
    echo $close_testcase >> artifacts/junit_01.xml
  fi
done < "$input"
tail -2 $input >> artifacts/junit_01.xml

comma=","
quote='"'
startdate=$(date +%s)
timestamp='"timestamp": '
time_string="$timestamp$startdate$comma"

result='"result": "'
test_string=$(tail -n 5 $input)

if [[ $test_string = *"FAIL"* ]] # This operates under the assumption that the overall pass/fail message will be found in the last five lines
then
  test="FAILURE"
else
  test="SUCCESS"
fi
result_string="$result$test$quote"

filedir=$(cat _DATE)
mkdir -p $filedir

touch $filedir/build-log.txt

echo "{" > $filedir/finished.json
echo "$time_string" >> $filedir/finished.json
echo "$result_string" >> $filedir/finished.json
echo "}" >> $filedir/finished.json

mv started.json $filedir/started.json
mv artifacts $filedir/artifacts