Skip to content

Commit 921395f

Browse files
authored
CI workflow changes for code coverage report generation and upload (#116)
* CI workflow changes for code coverage report generation and upload Signed-off-by: wrigleyDan <[email protected]> * change names for jobs according to plugin name Signed-off-by: wrigleyDan <[email protected]> --------- Signed-off-by: wrigleyDan <[email protected]>
1 parent 0c1cce6 commit 921395f

File tree

3 files changed

+180
-29
lines changed

3 files changed

+180
-29
lines changed

.github/workflows/CI.yml

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
name: Build and Test User Behavior Insights
2+
on:
3+
push:
4+
branches:
5+
- "*"
6+
pull_request:
7+
branches:
8+
- "*"
9+
jobs:
10+
Get-CI-Image-Tag:
11+
uses: opensearch-project/opensearch-build/.github/workflows/get-ci-image-tag.yml@main
12+
with:
13+
product: opensearch
14+
15+
Check-ubi-linux:
16+
needs: Get-CI-Image-Tag
17+
strategy:
18+
matrix:
19+
java: [21, 24]
20+
os: [ubuntu-latest]
21+
22+
name: Gradle Check Linux
23+
runs-on: ${{ matrix.os }}
24+
container:
25+
# using the same image which is used by opensearch-build team to build the OpenSearch Distribution
26+
# this image tag is subject to change as more dependencies and updates will arrive over time
27+
image: ${{ needs.Get-CI-Image-Tag.outputs.ci-image-version-linux }}
28+
# need to switch to root so that github actions can install runner binary on container without permission issues.
29+
options: ${{ needs.Get-CI-Image-Tag.outputs.ci-image-start-options }}
30+
31+
steps:
32+
- name: Run start commands
33+
run: ${{ needs.Get-CI-Image-Tag.outputs.ci-image-start-command }}
34+
35+
- uses: actions/checkout@v4
36+
37+
- name: Setup Java ${{ matrix.java }}
38+
uses: actions/setup-java@v4
39+
with:
40+
distribution: 'temurin'
41+
java-version: ${{ matrix.java }}
42+
43+
- name: Run build
44+
run: |
45+
chown -R 1000:1000 `pwd`
46+
su `id -un 1000` -c "./gradlew check"
47+
48+
- name: Upload Coverage Report
49+
if: ${{ !cancelled() }}
50+
uses: codecov/codecov-action@v5
51+
with:
52+
token: ${{ secrets.CODECOV_TOKEN }}
53+
54+
Check-ubi-windows:
55+
strategy:
56+
matrix:
57+
java: [21, 24]
58+
os: [windows-latest]
59+
60+
name: Gradle Check Windows
61+
runs-on: ${{ matrix.os }}
62+
63+
steps:
64+
- uses: actions/checkout@v4
65+
66+
- name: Setup Java ${{ matrix.java }}
67+
uses: actions/setup-java@v4
68+
with:
69+
distribution: 'temurin'
70+
java-version: ${{ matrix.java }}
71+
72+
- name: Run build
73+
run: |
74+
./gradlew check
75+
76+
Precommit-ubi-linux:
77+
needs: Get-CI-Image-Tag
78+
strategy:
79+
matrix:
80+
java: [21, 24]
81+
os: [ubuntu-latest]
82+
83+
name: Pre-commit Linux
84+
runs-on: ${{ matrix.os }}
85+
container:
86+
# using the same image which is used by opensearch-build team to build the OpenSearch Distribution
87+
# this image tag is subject to change as more dependencies and updates will arrive over time
88+
image: ${{ needs.Get-CI-Image-Tag.outputs.ci-image-version-linux }}
89+
# need to switch to root so that github actions can install runner binary on container without permission issues.
90+
options: ${{ needs.Get-CI-Image-Tag.outputs.ci-image-start-options }}
91+
92+
steps:
93+
- name: Run start commands
94+
run: ${{ needs.Get-CI-Image-Tag.outputs.ci-image-start-command }}
95+
96+
- uses: actions/checkout@v4
97+
98+
- name: Setup Java ${{ matrix.java }}
99+
uses: actions/setup-java@v4
100+
with:
101+
distribution: 'temurin'
102+
java-version: ${{ matrix.java }}
103+
104+
- name: Run build
105+
run: |
106+
chown -R 1000:1000 `pwd`
107+
su `id -un 1000` -c "./gradlew precommit --parallel && ./gradlew jacocoTestReport && cp -v build/reports/jacoco/test/jacocoTestReport.xml ./jacocoTestReport.xml"
108+
109+
- uses: actions/upload-artifact@v4
110+
if: ${{ matrix.os }} == "ubuntu-latest"
111+
with:
112+
name: coverage-report-${{ matrix.os }}-${{ matrix.java }}
113+
path: ./jacocoTestReport.xml
114+
115+
Precommit-codecov:
116+
needs: Precommit-ubi-linux
117+
strategy:
118+
matrix:
119+
java: [21, 24]
120+
os: [ubuntu-latest]
121+
runs-on: ${{ matrix.os }}
122+
steps:
123+
- uses: actions/download-artifact@v4
124+
with:
125+
name: coverage-report-${{ matrix.os }}-${{ matrix.java }}
126+
path: ./
127+
- name: Upload Coverage Report
128+
uses: codecov/codecov-action@v5
129+
with:
130+
token: ${{ secrets.CODECOV_TOKEN }}

.github/workflows/build.yml

Lines changed: 0 additions & 29 deletions
This file was deleted.

build.gradle

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import org.opensearch.gradle.test.RestIntegTestTask
22
import java.util.concurrent.Callable
3+
import java.nio.file.Files
34

45
apply plugin: 'java'
56
apply plugin: 'idea'
67
apply plugin: 'opensearch.opensearchplugin'
78
apply plugin: 'opensearch.pluginzip'
89
apply plugin: 'opensearch.yaml-rest-test'
910
apply plugin: 'maven-publish'
11+
apply plugin: 'jacoco'
12+
apply plugin: 'com.form.diff-coverage'
1013

1114
ext.opensearch_tmp_dir = rootProject.file('build/private/opensearch_tmp').absoluteFile
1215
opensearch_tmp_dir.mkdirs()
@@ -55,10 +58,12 @@ buildscript {
5558
maven { url "https://aws.oss.sonatype.org/content/repositories/snapshots" }
5659
mavenCentral()
5760
maven { url "https://plugins.gradle.org/m2/" }
61+
maven { url 'https://jitpack.io' }
5862
}
5963

6064
dependencies {
6165
classpath "org.opensearch.gradle:build-tools:${opensearch_version}"
66+
classpath "com.github.form-com.diff-coverage-gradle:diff-coverage:0.9.5"
6267
}
6368
}
6469

@@ -165,6 +170,19 @@ publishing {
165170

166171
def _numNodes = findProperty('numNodes') as Integer ?: 1
167172

173+
test {
174+
include '**/*Tests.class'
175+
systemProperty 'tests.security.manager', 'false'
176+
}
177+
178+
jacocoTestReport {
179+
dependsOn test
180+
reports {
181+
xml.required = true
182+
}
183+
}
184+
tasks.named("check").configure { dependsOn(jacocoTestReport) }
185+
168186
// Setting up Integration Tests
169187
task integTest(type: RestIntegTestTask) {
170188
description = "Run tests against a cluster"
@@ -249,3 +267,35 @@ testClusters.integTest {
249267
}
250268
}
251269
}
270+
271+
ext.createDiffFile = { ->
272+
def file = Files.createTempFile(URLEncoder.encode(project.name, 'UTF-8'), '.diff').toFile()
273+
def diffBase = 'refs/remotes/origin/main'
274+
// Only run locally
275+
if (!System.getenv('CI')) {
276+
file.withOutputStream { out ->
277+
exec {
278+
commandLine 'git', 'diff', '--no-color', '--minimal', diffBase
279+
standardOutput = out
280+
}
281+
}
282+
}
283+
return file
284+
}
285+
286+
diffCoverageReport {
287+
afterEvaluate {
288+
diffSource.file = createDiffFile()
289+
}
290+
291+
// View report at build/reports/jacoco/diffCoverage/html/index.html
292+
reports {
293+
html = true
294+
}
295+
296+
violationRules {
297+
minBranches = 0.00
298+
minLines = 0.00
299+
failOnViolation = true
300+
}
301+
}

0 commit comments

Comments
 (0)