Skip to content

Commit 45e4942

Browse files
committed
Added code coverage workflow
1 parent 8cba62e commit 45e4942

4 files changed

Lines changed: 93 additions & 1 deletion

File tree

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Code coverage
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- dev
7+
8+
jobs:
9+
extender:
10+
runs-on: ubuntu-22.04
11+
steps:
12+
- name: Checkout repo
13+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
14+
- name: Install Java
15+
uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00
16+
with:
17+
java-version: '21.0.5+11.0.LTS'
18+
distribution: 'temurin'
19+
- name: Setup Gradle
20+
uses: gradle/actions/setup-gradle@ac638b010cf58a27ee6c972d7336334ccaf61c96
21+
- name: Run extender tests
22+
run: ./gradlew server:clean server:test server:jacocoTestReport -PexcludeTags="integration" -i
23+
- name: Setup .NET Core # Required to execute ReportGenerator
24+
uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9
25+
with:
26+
dotnet-version: 8.x
27+
dotnet-quality: 'ga'
28+
- name: ReportGenerator
29+
uses: danielpalme/ReportGenerator-GitHub-Action@4c0f60daf67483745c34efdeadd4c4e78a19991e3
30+
with:
31+
reports: '${{ github.workspace }}/server/build/reports/jacoco/test/jacocoTestReport.xml' # REQUIRED # The coverage reports that should be parsed (separated by semicolon). Globbing is supported.
32+
targetdir: 'coveragereport' # REQUIRED # The directory where the generated report should be saved.
33+
reporttypes: 'HtmlInline;MarkdownSummaryGithub' # The output formats and scope (separated by semicolon) Values: Badges, Clover, Cobertura, OpenCover, CsvSummary, Html, Html_Dark, Html_Light, Html_BlueRed, HtmlChart, HtmlInline, HtmlInline_AzurePipelines, HtmlInline_AzurePipelines_Dark, HtmlInline_AzurePipelines_Light, HtmlSummary, Html_BlueRed_Summary, JsonSummary, CodeClimate, Latex, LatexSummary, lcov, MarkdownSummary, MarkdownAssembliesSummary, MarkdownSummaryGithub, MarkdownDeltaSummary, MHtml, SvgChart, SonarQube, TeamCitySummary, TextSummary, TextDeltaSummary, Xml, XmlSummary
34+
sourcedirs: 'server/src/main/java' # Optional directories which contain the corresponding source code (separated by semicolon). The source directories are used if coverage report contains classes without path information.
35+
# historydir: '' # Optional directory for storing persistent coverage information. Can be used in future reports to show coverage evolution.
36+
# workingdir: ${{ github.workspace }} # Optional working directory. If available, the targetdir, sourcedirs and historydir are interpreted relative to the working directory (only if not specified as absolute paths).
37+
# plugins: '' # Optional plugin files for custom reports or custom history storage (separated by semicolon).
38+
# assemblyfilters: '+*' # Optional list of assemblies that should be included or excluded in the report. Exclusion filters take precedence over inclusion filters. Wildcards are allowed.
39+
# classfilters: '+*' # Optional list of classes that should be included or excluded in the report. Exclusion filters take precedence over inclusion filters. Wildcards are allowed.
40+
# filefilters: '+*' # Optional list of files that should be included or excluded in the report. Exclusion filters take precedence over inclusion filters. Wildcards are allowed.
41+
# riskhotspotassemblyfilters: '+*' # Optional list of assemblies that should be included or excluded in the risk hotspots. Exclusion filters take precedence over inclusion filters. Wildcards are allowed.
42+
# riskhotspotclassfilters: '+*' # Optional list of classes that should be included or excluded in the risk hotspots. Exclusion filters take precedence over inclusion filters. Wildcards are allowed.
43+
verbosity: 'Info' # The verbosity level of the log messages. Values: Verbose, Info, Warning, Error, Off
44+
title: 'Extender code coverage report' # Optional title.
45+
tag: '${{ github.run_number }}_${{ github.run_id }}' # Optional tag or build version.
46+
# license: '' # Optional license for PRO version. Get your license here: https://reportgenerator.io/pro
47+
# customSettings: '' # Optional custom settings (separated by semicolon). See: https://github.com/danielpalme/ReportGenerator/wiki/Settings.
48+
toolpath: 'reportgeneratortool' # Default directory for installing the dotnet tool.
49+
- name: Upload test results
50+
if: always()
51+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
52+
with:
53+
name: test-result
54+
path: ${{ github.workspace }}/server/build/reports/tests/
55+
retention-days: 10
56+
- name: Upload coverage report artifact
57+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
58+
with:
59+
name: CoverageReport # Artifact name
60+
path: coveragereport # Directory containing files to upload
61+
retention-days: 10
62+
- name: Add comment to PR # Only applicable if 'MarkdownSummaryGithub' or one of the other Markdown report types is generated
63+
if: github.event_name == 'pull_request'
64+
run: gh pr comment $PR_NUMBER --edit-last --create-if-none --body-file coveragereport/SummaryGithub.md # Adjust path and filename if necessary
65+
env:
66+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
67+
PR_NUMBER: ${{ github.event.number }}
68+
- name: Publish coverage in build summary # Only applicable if 'MarkdownSummaryGithub' or one of the other Markdown report types is generated
69+
run: cat coveragereport/SummaryGithub.md >> $GITHUB_STEP_SUMMARY # Adjust path and filename if necessary
70+
shell: bash

server/build.gradle

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ plugins {
1515
id 'java'
1616
id 'idea'
1717
id 'org.springframework.boot' version '3.3.5'
18+
id 'jacoco'
19+
}
20+
21+
jacoco {
22+
toolVersion = "0.8.13"
1823
}
1924

2025
apply plugin: 'io.spring.dependency-management'
@@ -206,5 +211,18 @@ task buildStandalone() {
206211
}
207212

208213
test {
209-
useJUnitPlatform()
214+
useJUnitPlatform {
215+
if (project.hasProperty("excludeTags")) {
216+
excludeTags project.getProperty("excludeTags")
217+
}
218+
}
219+
finalizedBy jacocoTestReport
210220
}
221+
222+
jacocoTestReport {
223+
dependsOn test // tests must run before report
224+
reports {
225+
xml.required.set(true)
226+
html.required.set(true)
227+
}
228+
}

server/src/test/java/com/defold/extender/AuthenticationTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.apache.commons.io.FileUtils;
1010
import org.junit.jupiter.api.AfterAll;
1111
import org.junit.jupiter.api.BeforeAll;
12+
import org.junit.jupiter.api.Tag;
1213
import org.junit.jupiter.api.Test;
1314
import org.junit.jupiter.api.extension.AfterEachCallback;
1415
import org.junit.jupiter.api.extension.ExtensionContext;
@@ -26,6 +27,7 @@
2627
import java.util.List;
2728
import java.util.stream.Collectors;
2829

30+
@Tag("integration")
2931
public class AuthenticationTest implements AfterEachCallback {
3032

3133
private static final int EXTENDER_PORT = 9001;

server/src/test/java/com/defold/extender/IntegrationTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.jf.dexlib2.iface.DexFile;
1010
import org.junit.jupiter.api.AfterAll;
1111
import org.junit.jupiter.api.BeforeAll;
12+
import org.junit.jupiter.api.Tag;
1213
import org.junit.jupiter.params.ParameterizedTest;
1314
import org.junit.jupiter.params.provider.MethodSource;
1415
import org.slf4j.Logger;
@@ -34,6 +35,7 @@
3435
import java.util.zip.ZipEntry;
3536
import java.util.zip.ZipFile;
3637

38+
@Tag("integration")
3739
public class IntegrationTest {
3840
private static final int EXTENDER_PORT = 9000;
3941

0 commit comments

Comments
 (0)