Add gitlab coverage report

This commit is contained in:
Oystein Kristoffer Tveit 2021-02-24 00:03:53 +01:00
parent a299221be4
commit ac17921a63
2 changed files with 67 additions and 5 deletions

View File

@ -22,8 +22,11 @@ cache:
stages: stages:
- build - build
- test - test
- coverage
- report
- deploy
build-job: build:
stage: build stage: build
script: script:
- "mvn clean compile $MAVEN_CLI_OPTS" - "mvn clean compile $MAVEN_CLI_OPTS"
@ -31,10 +34,9 @@ build-job:
paths: paths:
- target/ - target/
unittest-job: unittest:
stage: test stage: test
dependencies: needs: [build]
- build-job
script: script:
- "mvn package $MAVEN_CLI_OPTS" - "mvn package $MAVEN_CLI_OPTS"
artifacts: artifacts:
@ -46,7 +48,39 @@ unittest-job:
- target/surefire-reports/TEST-*.xml - target/surefire-reports/TEST-*.xml
- target/failsafe-reports/TEST-*.xml - target/failsafe-reports/TEST-*.xml
generate-coverage:
stage: coverage
script:
- 'mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent test jacoco:report'
artifacts:
paths:
- target/site/
- target/site/jacoco/jacoco.xml
report-coverage:
stage: report
image: haynes/jacoco2cobertura:1.0.4
script:
# convert report from jacoco to cobertura
- 'python /opt/cover2cover.py target/site/jacoco/jacoco.xml src/main/java > target/site/cobertura.xml'
# read the <source></source> tag and prepend the path to every filename attribute
- 'python /opt/source2filename.py target/site/cobertura.xml'
needs: [generate-coverage]
artifacts:
reports:
cobertura: target/site/cobertura.xml
pages:
stage: deploy
needs: [generate-coverage]
script:
- mv target/site/* public/
artifacts:
paths:
- public
expire_in: 30 days
only:
- master
# integrationtest-job: # integrationtest-job:
# stage: test # stage: test

30
pom.xml
View File

@ -88,7 +88,12 @@
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version> <version>3.0.0-M5</version>
<configuration> <configuration>
<argLine>--enable-preview</argLine> <argLine>@{argLine} --enable-preview</argLine>
<forkCount>1</forkCount>
<reuseForks>true</reuseForks>
<!-- <includes>
<include>**/test/**/*Test.java</include>
</includes> -->
</configuration> </configuration>
</plugin> </plugin>
@ -101,6 +106,29 @@
<mainClass>app.Main</mainClass> <mainClass>app.Main</mainClass>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.6</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins> </plugins>
</build> </build>
</project> </project>