You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2023/12/06 15:51:10 UTC

(plc4x) branch develop updated: fix: Updated the build to output failed go tests when being run in the maven build.

This is an automated email from the ASF dual-hosted git repository.

cdutz pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git


The following commit(s) were added to refs/heads/develop by this push:
     new 8fd198c25a fix: Updated the build to output failed go tests when being run in the maven build.
8fd198c25a is described below

commit 8fd198c25a0940ab36b8a961dbcf6ebc01739165
Author: Christofer Dutz <cd...@apache.org>
AuthorDate: Wed Dec 6 16:51:03 2023 +0100

    fix: Updated the build to output failed go tests when being run in the maven build.
---
 plc4go/pom.xml                                | 107 +++++++++++++++++++++-----
 plc4go/script/validate-go-test-results.groovy |  36 +++++++++
 2 files changed, 122 insertions(+), 21 deletions(-)

diff --git a/plc4go/pom.xml b/plc4go/pom.xml
index 587a66201e..7ceef7c4cd 100644
--- a/plc4go/pom.xml
+++ b/plc4go/pom.xml
@@ -64,6 +64,28 @@
   <build>
     <sourceDirectory>pkg</sourceDirectory>
     <plugins>
+      <!--
+        Create surefire folder for report, as this is required to exist.
+      -->
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-antrun-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>generate-sources</id>
+            <phase>generate-sources</phase>
+            <goals>
+              <goal>run</goal>
+            </goals>
+            <configuration>
+              <target>
+                <mkdir dir="target${file.separator}surefire-reports" />
+              </target>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+
       <!--
         Copy the test-resources in here
       -->
@@ -282,6 +304,10 @@
           </execution>
 
           <!-- Processes code that uses old APIs and rewrites them use newer ones -->
+          <!--
+            REMARK: The default lifecycle defines this is run in the "validate" phase,
+            we redefine it to run in the process-sources so it also processes generated code.
+          -->
           <execution>
             <id>default-fix</id>
             <phase>process-sources</phase>
@@ -326,15 +352,22 @@
           <execution>
             <id>default-test</id>
             <phase>test</phase>
-            <!-- TODO: Which goal?!? -->
+            <goals>
+              <goal>test</goal>
+            </goals>
             <configuration>
               <buildFlags>
-                <flag>-v</flag>
+                <!--flag>-v</flag-->
                 <!-- TODO: race detection temporary disabled till root cause for the issue is found https://github.com/golang/go/issues/40343 -->
                 <!--flag>-race</flag-->
                 <flag>${go.cover.flag}</flag>
               </buildFlags>
               <outLogFile>test-out-verbose.log</outLogFile>
+              <!--
+                Don't fail the build if we have test failures as we'll have the results translated
+                to junit format and will have the failsafe-plugin then fail the build. This way Jenkins
+                can display the results better.
+              -->
               <ignoreErrorExitCode>true</ignoreErrorExitCode>
               <packages>
                 <package>./...</package>
@@ -342,9 +375,8 @@
             </configuration>
           </execution>
 
-          <execution>
+          <!--execution>
             <id>readable-test</id>
-            <!-- TODO: Possibly move to test or prepare-package -->
             <phase>test</phase>
             <goals>
               <goal>custom</goal>
@@ -359,11 +391,11 @@
                 <package>./...</package>
               </packages>
             </configuration>
-          </execution>
+          </execution-->
 
           <!-- Convert generated test report into go-junit-report format and save as file -->
-          <execution>
-            <id>makeJUnitReport</id>
+          <!--execution>
+            <id>make-junit-report</id>
             <phase>test</phase>
             <goals>
               <goal>custom</goal>
@@ -371,7 +403,11 @@
             <configuration>
               <skip>${skipTests}</skip>
               <exec>go-junit-report</exec>
-              <!--customCommand>-set-exit-code</customCommand-->
+              <!- -
+                This is just stupid, I need to provide something here, or the build won't work ...
+                this should hopefully have very little side-effects
+              - ->
+              <customCommand>-no-xml-header</customCommand>
               <buildFlags>
                 <flag>-in</flag>
                 <flag>${project.build.directory}${file.separator}reports${file.separator}test-out-verbose.log</flag>
@@ -386,7 +422,7 @@
                 <package>target${file.separator}surefire-reports${file.separator}go-junit-report.xml</package>
               </packages>
             </configuration>
-          </execution>
+          </execution-->
 
           <execution>
             <id>run-go-vet</id>
@@ -406,27 +442,56 @@
         </configuration>
       </plugin>
 
-      <!--
-        Create surefire folder for report
-      -->
       <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-antrun-plugin</artifactId>
-        <version>3.1.0</version>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>exec-maven-plugin</artifactId>
         <executions>
           <execution>
-            <id>generate-sources</id>
-            <phase>generate-sources</phase>
+            <id>make-junit-report</id>
+            <!-- We need to ensure it's after test and before verify -->
+            <phase>prepare-package</phase>
             <goals>
-              <goal>run</goal>
+              <goal>exec</goal>
             </goals>
             <configuration>
-              <target>
-                <mkdir dir="target${file.separator}surefire-reports" />
-              </target>
+              <executable>${project.build.directory}/go-junit-report</executable>
+              <arguments>
+                <argument>-in</argument>
+                <argument>${project.build.directory}${file.separator}reports${file.separator}test-out-verbose.log</argument>
+                <argument>-out</argument>
+                <argument>target${file.separator}surefire-reports${file.separator}go-junit-report.xml</argument>
+              </arguments>
+              <successCodes>
+                <successCode>0</successCode>
+              </successCodes>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+
+      <plugin>
+        <groupId>org.codehaus.gmaven</groupId>
+        <artifactId>groovy-maven-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>output-failing-tests</id>
+            <phase>prepare-package</phase>
+            <goals>
+              <goal>execute</goal>
+            </goals>
+            <inherited>false</inherited>
+            <configuration>
+              <source>${project.basedir}/script/validate-go-test-results.groovy</source>
             </configuration>
           </execution>
         </executions>
+        <dependencies>
+          <dependency>
+            <groupId>org.apache.groovy</groupId>
+            <artifactId>groovy-xml</artifactId>
+            <version>4.0.16</version>
+          </dependency>
+        </dependencies>
       </plugin>
 
       <!-- Ensure we don't deploy anything -->
diff --git a/plc4go/script/validate-go-test-results.groovy b/plc4go/script/validate-go-test-results.groovy
new file mode 100644
index 0000000000..cd3b414aa8
--- /dev/null
+++ b/plc4go/script/validate-go-test-results.groovy
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+// Only if there's output, do we
+def file = new File("target/surefire-reports/go-junit-report.xml")
+if (file.exists()) {
+    // Read the go-junit-report.xml file.
+    def testResults = new XmlSlurper().parse(file)
+
+    // If there are errors, output the entries for these failed tests and fail the build after that.
+    if(testResults.@failures != "0" && testResults.@failures != "") {
+        def failedTestSuites = testResults.testsuite.find { node -> node.@failures != '0' || node.@errors != '0' }
+        for (failedTestSuite in failedTestSuites) {
+            print failedTestSuite
+        }
+        throw new RuntimeException("There were test failures in Go.")
+    }
+}
+
+