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

haonan pushed a commit to branch support_codecov
in repository https://gitbox.apache.org/repos/asf/tsfile.git

commit eef64a5c5e9d911bf39be108d28036e1cb0d4d07
Author: HTHou <[email protected]>
AuthorDate: Sat Jul 27 00:32:20 2024 +0800

    Support codecov to show code coverage
---
 .github/workflows/unit-test.yml             |  27 ++++-
 code-coverage/copy-code-coverage-sources.sh |  31 ++++++
 code-coverage/pom.xml                       | 132 ++++++++++++++++++++++
 codecov.yml                                 |  47 ++++++++
 java/examples/pom.xml                       |   2 +-
 pom.xml                                     | 165 +++++++++++++++++++++++++++-
 6 files changed, 400 insertions(+), 4 deletions(-)

diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml
index 2192e465..9f1aa26d 100644
--- a/.github/workflows/unit-test.yml
+++ b/.github/workflows/unit-test.yml
@@ -38,7 +38,7 @@ jobs:
       fail-fast: false
       max-parallel: 20
       matrix:
-        java: [ 8, 11, 17, 21 ]
+        java: [ 8, 17, 21 ]
         os: [ ubuntu-latest, macos-latest, windows-latest ]
     runs-on: ${{ matrix.os }}
 
@@ -78,7 +78,30 @@ jobs:
             }
 
       # Run the actual maven build including all unit- and integration-tests.
-      - name: Build and test with Maven (All others)
+      - name: Build and test with Maven
         shell: bash
         run: |
           ./mvnw${{ steps.platform_suffix.outputs.platform_suffix }} -P 
with-java,with-cpp,with-python clean verify
+
+
+  codecov:
+    runs-on: ubuntu-latest
+    if: github.event_name == 'pull_request' && 
github.event.pull_request.head.repo.full_name == 'apache/iotdb' || 
github.event_name == 'push'
+
+    steps:
+      - uses: actions/checkout@v4
+      - name: Cache Maven packages
+        uses: actions/cache@v4
+        with:
+          path: ~/.m2
+          key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
+          restore-keys: ${{ runner.os }}-m2-
+      - name: Test
+        run: |
+          ./mvn -B -P with-java,with-cpp,with-python,with-code-coverage clean 
verify
+          mvn -B -P with-code-coverage clean post-integration-test
+      - name: Upload coverage reports to codecov
+        uses: codecov/codecov-action@v4
+        with:
+          token: ${{ secrets.CODECOV_TOKEN }}
+          files: ./code-coverage/target/jacoco-merged-reports/jacoco.xml
diff --git a/code-coverage/copy-code-coverage-sources.sh 
b/code-coverage/copy-code-coverage-sources.sh
new file mode 100755
index 00000000..19c24fd1
--- /dev/null
+++ b/code-coverage/copy-code-coverage-sources.sh
@@ -0,0 +1,31 @@
+#!/usr/bin/env bash
+#
+# 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.
+#
+
+for file in ../java/*/target/*.exec
+do
+   cp $file ./target/
+done
+
+for file in ../java/*/target/classes
+do
+   echo "copy from" ${file}
+   cp -r $file ./target/
+done
+
diff --git a/code-coverage/pom.xml b/code-coverage/pom.xml
new file mode 100644
index 00000000..b75bee1e
--- /dev/null
+++ b/code-coverage/pom.xml
@@ -0,0 +1,132 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.tsfile</groupId>
+        <artifactId>tsfile-parent</artifactId>
+        <version>1.0.1-SNAPSHOT</version>
+    </parent>
+    <artifactId>tsfile-code-coverage</artifactId>
+    <packaging>pom</packaging>
+    <name>TsFile: Code-Coverage</name>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>exec-maven-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>make-cmake-executable</id>
+                        <goals>
+                            <goal>exec</goal>
+                        </goals>
+                        <phase>process-resources</phase>
+                        <configuration>
+                            <basedir>${project.basedir}</basedir>
+                            <executable>chmod</executable>
+                            <arguments>
+                                <argument>+x</argument>
+                                
<argument>copy-code-coverage-sources.sh</argument>
+                            </arguments>
+                        </configuration>
+                    </execution>
+                    <execution>
+                        <id>collect-code-coverage-results</id>
+                        <goals>
+                            <goal>exec</goal>
+                        </goals>
+                        <phase>post-integration-test</phase>
+                        <configuration>
+                            
<executable>${project.basedir}/copy-code-coverage-sources.sh</executable>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.jacoco</groupId>
+                <artifactId>jacoco-maven-plugin</artifactId>
+                <configuration>
+                    <rules>
+                        <rule 
implementation="org.jacoco.maven.RuleConfiguration">
+                            <element>BUNDLE</element>
+                            <limits>  
+                                <!-- Cover methodes >=30%. (the plugin does 
not support
+                                ignore getter and setter and toString etc..) 
-->
+                                <limit 
implementation="org.jacoco.report.check.Limit">
+                                    <counter>METHOD</counter>
+                                    <value>COVEREDRATIO</value>
+                                    <minimum>0.00</minimum>
+                                </limit>
+                                <!-- if-else, swtich etc.. >=70% -->
+                                <limit 
implementation="org.jacoco.report.check.Limit">
+                                    <counter>BRANCH</counter>
+                                    <value>COVEREDRATIO</value>
+                                    <minimum>0.00</minimum>
+                                </limit>
+                                <!-- class files >=95% -->
+                                <limit 
implementation="org.jacoco.report.check.Limit">
+                                    <counter>CLASS</counter>
+                                    <value>COVEREDRATIO</value>
+                                    <minimum>0.00</minimum>
+                                </limit>
+                            </limits>
+                        </rule>
+                    </rules>
+                </configuration>
+                <executions>
+                    <!-- see 
https://natritmeyer.com/howto/reporting-aggregated-unit-and-integration-test-coverage-with-jacoco/-->
+                    <execution>
+                        <id>merge-unit-and-integration-final</id>
+                        <goals>
+                            <goal>merge</goal>
+                        </goals>
+                        <phase>post-integration-test</phase>
+                        <configuration>
+                            <fileSets>
+                                <fileSet>
+                                    
<directory>${project.build.directory}/</directory>
+                                    <includes>
+                                        <include>*.exec</include>
+                                    </includes>
+                                </fileSet>
+                            </fileSets>
+                            
<destFile>${project.build.directory}/merged.exec</destFile>
+                        </configuration>
+                    </execution>
+                    <execution>
+                        <id>create-merged-report-final</id>
+                        <goals>
+                            <goal>report</goal>
+                            <goal>check</goal>
+                        </goals>
+                        <phase>post-integration-test</phase>
+                        <configuration>
+                            
<dataFile>${project.build.directory}/merged.exec</dataFile>
+                            
<outputDirectory>${project.build.directory}/jacoco-merged-reports</outputDirectory>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+</project>
diff --git a/codecov.yml b/codecov.yml
new file mode 100644
index 00000000..aefe55fa
--- /dev/null
+++ b/codecov.yml
@@ -0,0 +1,47 @@
+#
+# 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.
+#
+
+coverage:
+  precision: 2
+  round: down
+  range: "50...100"
+
+  status:
+    project: yes
+    patch: no
+    changes: no
+
+parsers:
+  jacoco:
+    partials_as_hits: true #false by default
+
+ignore:
+  - "**/pom.xml"
+  - "**/*.md"
+  - "**/*.sh"
+  - "**/*.cmd"
+  - "**/*.bat"
+  - "**/*.yml"
+  - ".mvn"
+  - "mvnw"
+  - "NOTICE"
+  - "NOTICE-binary"
+  - "License"
+  - "LICENSE-binary"
+  - "DISCLAIMER"
diff --git a/java/examples/pom.xml b/java/examples/pom.xml
index 13e1ffca..8f215aaa 100644
--- a/java/examples/pom.xml
+++ b/java/examples/pom.xml
@@ -28,7 +28,7 @@
     </parent>
     <artifactId>examples</artifactId>
     <packaging>pom</packaging>
-    <name>TSFile: Java: Examples</name>
+    <name>TsFile: Java: Examples</name>
     <dependencies>
         <dependency>
             <groupId>ch.qos.logback</groupId>
diff --git a/pom.xml b/pom.xml
index 9f44c3ff..22463a69 100644
--- a/pom.xml
+++ b/pom.xml
@@ -608,7 +608,19 @@
                     [JEP 396: Strongly Encapsulate JDK Internals by Default],
                     [JEP 403: Strongly Encapsulate JDK Internals]
                 -->
-                
<argLine>--add-opens=java.base/java.util.concurrent=ALL-UNNAMED 
--add-opens=java.base/java.lang=ALL-UNNAMED 
--add-opens=java.base/java.util=ALL-UNNAMED 
--add-opens=java.base/java.nio=ALL-UNNAMED 
--add-opens=java.base/java.io=ALL-UNNAMED 
--add-opens=java.base/java.net=ALL-UNNAMED 
--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED 
--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED 
--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add [...]
+                <argLine><![CDATA[
+                        --add-opens=java.base/java.lang=ALL-UNNAMED
+                        --add-opens=java.base/java.util=ALL-UNNAMED
+                        --add-opens=java.base/java.nio=ALL-UNNAMED
+                        --add-opens=java.base/java.io=ALL-UNNAMED
+                        --add-opens=java.base/java.net=ALL-UNNAMED
+                        --add-opens=java.base/java.util.concurrent=ALL-UNNAMED
+                        
--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
+                        
--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
+                        
--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
+                        
--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
+                        
--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
+                      ]]></argLine>
             </properties>
         </profile>
         <!-- Current version of spotless cannot support JDK11 below -->
@@ -875,6 +887,157 @@
                 </plugins>
             </build>
         </profile>
+        <profile>
+            <id>with-code-coverage</id>
+            <modules>
+                <module>code-coverage</module>
+            </modules>
+            <build>
+                <plugins>
+                    <!--
+            Jacoco is a code coverage analysis plugin when tests run.
+            (not a static code analysis tool)
+          -->
+                    <plugin>
+                        <groupId>org.jacoco</groupId>
+                        <artifactId>jacoco-maven-plugin</artifactId>
+                        <version>0.8.12</version>
+                        <configuration>
+                            <rules>
+                                <rule 
implementation="org.jacoco.maven.RuleConfiguration">
+                                    <element>BUNDLE</element>
+                                    <limits>  
+                                        <!-- Cover methodes >=30%. (the plugin 
does not support
+                                        ignore getter and setter and toString 
etc..) -->
+                                        <limit 
implementation="org.jacoco.report.check.Limit">
+                                            <counter>METHOD</counter>
+                                            <value>COVEREDRATIO</value>
+                                            <minimum>0.00</minimum>
+                                        </limit>
+                                        <!-- if-else, swtich etc.. >=70% -->
+                                        <limit 
implementation="org.jacoco.report.check.Limit">
+                                            <counter>BRANCH</counter>
+                                            <value>COVEREDRATIO</value>
+                                            <minimum>0.00</minimum>
+                                        </limit>
+                                        <!-- class files >=95% -->
+                                        <limit 
implementation="org.jacoco.report.check.Limit">
+                                            <counter>CLASS</counter>
+                                            <value>COVEREDRATIO</value>
+                                            <minimum>0.00</minimum>
+                                        </limit>
+                                    </limits>
+                                </rule>
+                            </rules>
+                        </configuration>
+                        <executions>
+                            <!-- For UT-->
+                            <execution>
+                                <id>prepare-ut</id>
+                                <goals>
+                                    <goal>prepare-agent</goal>
+                                </goals>
+                                <configuration>
+                                    
<destFile>${project.build.directory}/${project.build.finalName}-jacoco-unit-tests.exec</destFile>
+                                    
<propertyName>surefire.jacoco.args</propertyName>
+                                </configuration>
+                            </execution>
+                            <!-- attached to Maven test phase -->
+                            <execution>
+                                <id>ut-report</id>
+                                <goals>
+                                    <goal>report</goal>
+                                    <goal>check</goal>
+                                </goals>
+                                <phase>test</phase>
+                                <configuration>
+                                    
<dataFile>${project.build.directory}/${project.build.finalName}-jacoco-unit-tests.exec</dataFile>
+                                    
<outputDirectory>${project.build.directory}/jacoco-unit-reports</outputDirectory>
+                                </configuration>
+                            </execution>
+                            <!-- For IT-->
+                            <execution>
+                                <id>before-integration-test-execution</id>
+                                <goals>
+                                    <goal>prepare-agent</goal>
+                                </goals>
+                                <phase>pre-integration-test</phase>
+                                <configuration>
+                                    
<destFile>${project.build.directory}/${project.build.finalName}-jacoco-integration-tests.exec</destFile>
+                                    
<propertyName>failsafe.jacoco.args</propertyName>
+                                </configuration>
+                            </execution>
+                            <execution>
+                                <id>after-integration-test-execution</id>
+                                <goals>
+                                    <goal>report</goal>
+                                    <goal>check</goal>
+                                </goals>
+                                <phase>integration-test</phase>
+                                <configuration>
+                                    
<dataFile>${project.build.directory}/${project.build.finalName}-jacoco-integration-tests.exec</dataFile>
+                                    
<outputDirectory>${project.build.directory}/jacoco-integration-reports</outputDirectory>
+                                </configuration>
+                            </execution>
+                            <execution>
+                                <id>merge-unit-and-integration</id>
+                                <goals>
+                                    <goal>merge</goal>
+                                </goals>
+                                <phase>post-integration-test</phase>
+                                <configuration>
+                                    <fileSets>
+                                        <fileSet>
+                                            
<directory>${project.build.directory}/</directory>
+                                            <includes>
+                                                <include>*.exec</include>
+                                            </includes>
+                                        </fileSet>
+                                    </fileSets>
+                                    
<destFile>${project.build.directory}/${project.build.finalName}-merged.exec</destFile>
+                                </configuration>
+                            </execution>
+                            <execution>
+                                <id>create-merged-report</id>
+                                <goals>
+                                    <goal>report</goal>
+                                    <goal>check</goal>
+                                </goals>
+                                <phase>post-integration-test</phase>
+                                <configuration>
+                                    
<dataFile>${project.build.directory}/${project.build.finalName}-merged.exec</dataFile>
+                                    
<outputDirectory>${project.build.directory}/jacoco-merged-reports</outputDirectory>
+                                </configuration>
+                            </execution>
+                        </executions>
+                    </plugin>
+                    <!-- overwrite argLine-->
+                    <plugin>
+                        <groupId>org.apache.maven.plugins</groupId>
+                        <artifactId>maven-surefire-plugin</artifactId>
+                        <configuration>
+                            <argLine>${argLine} @{surefire.jacoco.args} 
-Xmx1024m</argLine>
+                        </configuration>
+                    </plugin>
+                    <!-- for IT-->
+                    <plugin>
+                        <groupId>org.apache.maven.plugins</groupId>
+                        <artifactId>maven-failsafe-plugin</artifactId>
+                        <configuration>
+                            <argLine>${argLine} @{failsafe.jacoco.args} 
-Xmx1024m</argLine>
+                        </configuration>
+                        <executions>
+                            <execution>
+                                <goals>
+                                    <goal>integration-test</goal>
+                                    <goal>verify</goal>
+                                </goals>
+                            </execution>
+                        </executions>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
         <profile>
             <id>enforce</id>
             <properties>

Reply via email to