Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add Code Cov Integration for Jacoco test #532

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# GitHub Actions workflow for Codecov integration
# This workflow builds the project, generates a coverage report, and uploads it to Codecov

name: Codecov

# Define when this workflow should run
on:
push:
branches: ['master'] # Run on every push to the master branch
pull_request:
branches: ['**'] # Run on every pull request, regardless of target branch

# Define the jobs to run
jobs:
codecov:
runs-on: ubuntu-latest # Use the latest Ubuntu runner
steps:
# Check out the repository code
- name: Checkout code
uses: actions/checkout@v2 # Use v2 of the checkout action
with:
fetch-depth: '0' # Fetch all history for all branches and tags

# Set up Java Development Kit
- name: Set up JDK
uses: actions/setup-java@v1 # Use v1 of the setup-java action
with:
java-version: 1.8 # Use Java 8 (adjust if your project uses a different version)

# Build the project and generate coverage report
- name: Build and generate coverage report
run: ./gradlew -i build

# TODO remove, debugging-only
- name: List jacoco directory
run: ls -R ${{ github.workspace }}/build/reports/jacoco

# TODO remove, debugging-only
- uses: actions/upload-artifact@v4
with:
name: build-reports
path: ${{ github.workspace }}/build/reports

# Upload the coverage report to Codecov
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3 # Use v3 of the Codecov GitHub Action
with:
file: ${{ github.workspace }}/build/reports/jacoco/jacocoRootReport/jacocoRootReport.xml # Path to the coverage report
flags: unittests # Label these results as coming from unit tests
fail_ci_if_error: true # Fail the workflow if there's an error uploading to Codecov

# Note: No token is required for public repositories
# Codecov will automatically detect that this is a public repo and process the report
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ ligradle
.DS_Store
*.patch
*/metastore_db
.pyc
.pyc
.vscode
79 changes: 77 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ buildscript {

plugins {
id "com.diffplug.spotless" version "5.9.0"
id "jacoco"
}

apply from: "gradle/shipkit.gradle"
Expand All @@ -30,6 +31,7 @@ configurations {
allprojects {
group = "com.linkedin.coral"
apply plugin: "com.diffplug.spotless"
apply plugin: "jacoco"

repositories {
mavenCentral()
Expand All @@ -52,20 +54,69 @@ allprojects {
target '**/*.md'
targetExclude 'docs/release-notes.md'
endWithNewline()
// Disabling Prettier since it causes TravisCI to barf
// prettier()
}
}

jacoco {
toolVersion = "0.8.7"
}
}

ext.moduleCoverageThresholds = [
// Default coverage applied unless overridden
'coral-dbt': 0.95,
'coral-incremental': 0.95,
'coral-pig': 0.85,
'coral-schema': 0.80,
'coral-service': 0.95,
'coral-spark': 0.90,
'coral-spark-plan': 0.74,
'coral-trino': 0.80,
'coral-visualization': 0.75,
// Explicit exclusions
'coral-common': 0.00,
'coral-hive': 0.00,
]

subprojects {
plugins.withType(JavaPlugin) {
dependencies {
testCompile deps.'testing'
}
test {
useTestNG()
finalizedBy jacocoTestReport
}
jacocoTestReport {
reports {
xml.enabled true
csv.enabled false
html.destination file("${buildDir}/jacocoHtml")
}
executionData.from = files(fileTree(dir: project.buildDir, includes: ['jacoco/*.exec']).files.findAll { it.exists() })
}

def moduleName = project.name
def threshold = moduleCoverageThresholds.containsKey(moduleName)
? moduleCoverageThresholds[moduleName]
: 0.95 // Default to 100% if not specified

jacocoTestCoverageVerification {
violationRules {
rule {
element = 'BUNDLE'
limit {
counter = 'INSTRUCTION'
value = 'COVEREDRATIO'
minimum = threshold
}
excludes = [
'com.linkedin.coral.hive.hive2rel.parsetree.parser.*', // org.jacoco.agent.rt.internal_3570298.asm.MethodTooLargeException: Method too large: com/linkedin/coral/hive/hive2rel/parsetree/parser/*
]
}
}
}
check.dependsOn jacocoTestCoverageVerification
spotless {
java {
importOrder('java', 'javax', 'com', 'org', 'com.linkedin.coral', '\\#')
Expand All @@ -79,3 +130,27 @@ subprojects {
apply from: "${rootDir}/gradle/dependencies.gradle"
apply from: "${rootDir}/gradle/java-publication.gradle"
}

task jacocoRootReport(type: JacocoReport) {
dependsOn = subprojects.test
additionalSourceDirs.from = subprojects.sourceSets.main.allSource.srcDirs
sourceDirectories.from = subprojects.sourceSets.main.allSource.srcDirs
classDirectories.from = subprojects.sourceSets.main.output

executionData.from = files(subprojects.findAll { p ->
p.plugins.hasPlugin(JavaPlugin)
}.collect { p ->
p.file("${p.buildDir}/jacoco/test.exec")
}.findAll { file ->
file.exists()
})

reports {
html.enabled = true
xml.enabled = true
csv.enabled = false
html.destination file("${buildDir}/reports/jacoco")
}
}

check.dependsOn jacocoRootReport
47 changes: 47 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Codecov configuration file
# This file controls how Codecov behaves when processing coverage reports

codecov:
# Require all other CI tasks to pass before considering Codecov status
require_ci_to_pass: yes

coverage:
status:
# Settings for overall project coverage
project:
default:
# 'auto' sets the target to the coverage of the base commit
target: auto
# Coverage can drop up to 1% without failing
threshold: 1%
# Compare coverage to the base branch (usually master)
base: auto

# Settings for coverage of new/changed code in PRs
patch:
default:
# 'auto' requires new/changed code to match the base branch coverage
target: auto
# New/changed code coverage can be up to 1% lower without failing
threshold: 1%
# Compare to the base branch of the PR
base: auto

# Configuration for Codecov comments on PRs
comment:
# Elements to include in the comment
# reach: overall coverage
# diff: coverage diff to base
# flags: coverage for specific flags
# files: file-level coverage
# footer: links to more details
layout: "reach,diff,flags,files,footer"
# Use default comment behavior
behavior: default
# Comment even if coverage hasn't changed
require_changes: no

# Ignore these directories/files when calculating coverage
ignore:
- "coral-common"
- "coral-hive"
Loading