Skip to content

Commit

Permalink
Merge pull request wso2#3103 from slahirucd7/finalPRForCodeCov
Browse files Browse the repository at this point in the history
Code coverage support
  • Loading branch information
pubudu538 authored Oct 21, 2022
2 parents 42d26bb + fde1644 commit 06336f0
Show file tree
Hide file tree
Showing 14 changed files with 424 additions and 19 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
coverage:
status:
project:
default:
target: 27%
threshold: 1%
8 changes: 3 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,10 @@ jobs:
- name: Build with Maven
run: |
export GOFLAGS=-mod=mod
mvn clean install -PRelease -s .maven/settings.xml \
-pl '!:integration' -pl '!:mock-backend-server' -pl '!:test-integration'
- name: Run integration tests
run: |
mvn clean install -PRelease -pl ':integration' -amd -s .maven/settings.xml
mvn clean install -Dskip.code.coverage=false -PRelease -s .maven/settings.xml
- name: Build multi platform Ubuntu images
run: |
./build-ubuntu-multi-platform-images.sh all
docker images
- name: Upload coverage reports to Codecov with GitHub Action
uses: codecov/codecov-action@v3
2 changes: 1 addition & 1 deletion adapter/scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export cc_test_test_uintarray2=-50
export CC_Adapter_Server_Enabled=string

go clean -testcache
go test -race -coverprofile=./target/coverage.txt -covermode=atomic ./...
go test -race -coverprofile=./target/coverage.out -covermode=atomic ./...
if [ $? -ne 0 ]; then
echo "FAILED: Unit tests failure"
exit 1
Expand Down
24 changes: 24 additions & 0 deletions dev-scripts/code-coverage/prepare-files-after-int-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh
# --------------------------------------------------------------------
# Copyright (c) 2022, WSO2 Inc. (http://wso2.com) All Rights Reserved.
#
# Licensed 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.
# -----------------------------------------------------------------------

echo "Preparing code coverage files after integration tests...."
rm -f ../../resources/enforcer/dropins/aggregate.exec
rm ../../.github/workflows/coverage.yml
rm ../../enforcer-parent/commons/target/site/jacoco/jacoco.xml
rm ../../enforcer-parent/enforcer/target/site/jacoco/jacoco.xml
rm -rf ../../router/target/mgw-wasm/.cache/bazel/
echo "Preparing code coverage files after integration tests completed successfully...."
26 changes: 26 additions & 0 deletions dev-scripts/code-coverage/prepare-files-before-int-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh
# --------------------------------------------------------------------
# Copyright (c) 2022, WSO2 Inc. (http://wso2.com) All Rights Reserved.
#
# Licensed 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.
# -----------------------------------------------------------------------

echo "Preparing code coverage files before integration tests..."
mkdir ../../resources/enforcer/dropins/
chmod 777 ../../enforcer-parent/enforcer/target/coverage-aggregate-reports/aggregate.exec
export JAVA_AGENT_ARG="-javaagent:\/home\/wso2\/lib\/org.jacoco.agent-0.8.8-runtime.jar=destfile=\/home\/wso2\/lib\/dropins\/aggregate.exec,append=true"
sed -i "s/JAVA_OPTS.*/JAVA_OPTS=\${JAVA_OPTS} ${JAVA_AGENT_ARG}/g" ../../resources/docker-compose/docker-compose.yaml
sed -i "s/JAVA_OPTS.*/JAVA_OPTS=\${JAVA_OPTS} ${JAVA_AGENT_ARG} -Dhttpclient.hostnameVerifier=AllowAll/g" ../../resources/docker-compose/apim/docker-compose.yaml
sed -i "s/JAVA_OPTS.*/JAVA_OPTS=\${JAVA_OPTS} ${JAVA_AGENT_ARG}/g" ../../integration/test-integration/src/test/resources/dockerCompose/cc-cacert-mounted-mtls.yaml
sed -i "s/JAVA_OPTS.*/JAVA_OPTS=\${JAVA_OPTS} ${JAVA_AGENT_ARG} -Dhttpclient.hostnameVerifier=AllowAll/g" ../../integration/test-integration/src/test/resources/dockerCompose/cc-in-common-network-docker-compose.yaml
echo "Preparing code coverage files before integration tests completed successfully..."
63 changes: 63 additions & 0 deletions enforcer-parent/commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,69 @@
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<skip>${skip.code.coverage}</skip>
</configuration>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
<execution>
<id>default-prepare-agent-integration</id>
<goals>
<goal>prepare-agent-integration</goal>
</goals>
<configuration>
<propertyName>failsafeArgLine</propertyName>
</configuration>
</execution>
<execution>
<id>default-report</id>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>default-report-integration</id>
<goals>
<goal>report-integration</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>@{surefireArgLine}</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${maven.failsafe.plugin.version}</version>
<executions>
<execution>
<id>integration-tests</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<argLine>@{failsafeArgLine}</argLine>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
124 changes: 123 additions & 1 deletion enforcer-parent/enforcer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,40 @@
</includeArtifactIds>
</configuration>
</execution>
<execution>
<id>copy-dependencies-for-code-coverage</id>
<phase>generate-resources</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<skip>${skip.code.coverage}</skip>
<outputDirectory>${project.build.directory}/</outputDirectory>
<includeGroupIds>
org.jacoco
</includeGroupIds>
<includeArtifactIds>
org.jacoco.agent
</includeArtifactIds>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<skip>${skip.code.coverage}</skip>
<executable>${ccBaseDir}/dev-scripts/code-coverage/prepare-files-before-int-tests.sh
</executable>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
Expand Down Expand Up @@ -227,7 +261,7 @@
<executions>
<execution>
<id>docker-build</id>
<phase>package</phase>
<phase>install</phase>
<goals>
<goal>build</goal>
</goals>
Expand Down Expand Up @@ -262,6 +296,87 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<skip>${skip.code.coverage}</skip>
</configuration>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
<execution>
<id>default-prepare-agent-integration</id>
<goals>
<goal>prepare-agent-integration</goal>
</goals>
<configuration>
<propertyName>failsafeArgLine</propertyName>
</configuration>
</execution>
<execution>
<id>default-report</id>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>default-report-integration</id>
<goals>
<goal>report-integration</goal>
</goals>
</execution>
<execution>
<id>merge-results</id>
<phase>test</phase>
<goals>
<goal>merge</goal>
</goals>
<configuration>
<fileSets>
<fileSet>
<directory>${session.executionRootDirectory}</directory>
<includes>
<include>**/*.exec</include>
</includes>
</fileSet>
</fileSets>
<destFile>${project.build.directory}/coverage-aggregate-reports/aggregate.exec</destFile>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>@{surefireArgLine}</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${maven.failsafe.plugin.version}</version>
<executions>
<execution>
<id>integration-tests</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<argLine>@{failsafeArgLine}</argLine>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down Expand Up @@ -499,6 +614,12 @@
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.agent</artifactId>
<version>${jacoco.version}</version>
<classifier>runtime</classifier>
</dependency>
<dependency>
<groupId>javax.xml.soap</groupId>
<artifactId>javax.xml.soap-api</artifactId>
Expand All @@ -512,4 +633,5 @@
<artifactId>graphQL</artifactId>
</dependency>
</dependencies>

</project>
Loading

0 comments on commit 06336f0

Please sign in to comment.