Skip to content

Commit 63c88cf

Browse files
committed
Improve coverage report format in GitHub pull requests.
Calculate and upload coverage reports to our own Metrics Service instead of Codecov.
1 parent 3f5146f commit 63c88cf

File tree

4 files changed

+88
-177
lines changed

4 files changed

+88
-177
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ apply plugin: com.google.firebase.gradle.plugins.publish.PublishingPlugin
5757
apply plugin: com.google.firebase.gradle.plugins.ci.ContinuousIntegrationPlugin
5858
apply plugin: com.google.firebase.gradle.plugins.ci.SmokeTestsPlugin
5959
apply plugin: com.google.firebase.gradle.plugins.ci.metrics.MetricsPlugin
60-
apply plugin: com.google.firebase.gradle.plugins.ci.CheckCoveragePlugin
60+
apply plugin: com.google.firebase.gradle.plugins.measurement.coverage.CheckCoveragePlugin
6161

6262
firebaseContinuousIntegration {
6363
ignorePaths = [

buildSrc/src/main/groovy/com/google/firebase/gradle/plugins/ci/CheckCoveragePlugin.groovy

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

buildSrc/src/main/groovy/com/google/firebase/gradle/plugins/measurement/MetricsReportUploader.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,14 @@ public static void upload(Project project, String report) {
3434

3535
String owner = System.getenv("REPO_OWNER");
3636
String repo = System.getenv("REPO_NAME");
37+
String branch = System.getenv("PULL_BASE_REF");
3738
String baseCommit = System.getenv("PULL_BASE_SHA");
3839
String headCommit = System.getenv("PULL_PULL_SHA");
3940
String pullRequest = System.getenv("PULL_NUMBER");
4041

41-
String commit = headCommit != null && !headCommit.isEmpty() ? headCommit : headCommit;
42+
String commit = headCommit != null && !headCommit.isEmpty() ? headCommit : baseCommit;
4243

43-
post(project, report, owner, repo, commit, baseCommit, pullRequest);
44+
post(project, report, owner, repo, commit, branch, baseCommit, pullRequest);
4445
}
4546

4647
private static void post(
@@ -49,17 +50,18 @@ private static void post(
4950
String owner,
5051
String repo,
5152
String commit,
53+
String branch,
5254
String baseCommit,
5355
String pullRequest) {
5456
String post = "-X POST";
5557
String headerAuth = "-H \"Authorization: Bearer $(gcloud auth print-identity-token)\"";
5658
String headerContentType = "-H \"Content-Type: application/json\"";
5759
String body = String.format("-d @%s", report);
5860

59-
String template = "%s/repos/%s/%s/commits/%s/reports";
60-
String endpoint = String.format(template, METRICS_SERVICE_URL, owner, repo, commit);
61+
String template = "%s/repos/%s/%s/commits/%s/reports/?branch=%s";
62+
String endpoint = String.format(template, METRICS_SERVICE_URL, owner, repo, commit, branch);
6163
if (pullRequest != null && !pullRequest.isEmpty()) {
62-
endpoint += String.format("?base_commit=%s&pull_request=%s", baseCommit, pullRequest);
64+
endpoint += String.format("&base_commit=%s&pull_request=%s", baseCommit, pullRequest);
6365
}
6466

6567
String request =
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Copyright 2020 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.firebase.gradle.plugins.measurement.coverage
16+
17+
import com.google.firebase.gradle.plugins.FirebaseLibraryExtension
18+
import com.google.firebase.gradle.plugins.FirebaseLibraryPlugin
19+
import org.gradle.api.Plugin
20+
import org.gradle.api.Project
21+
import org.gradle.api.tasks.testing.Test
22+
import org.gradle.testing.jacoco.tasks.JacocoReport
23+
24+
class CheckCoveragePlugin implements Plugin<Project> {
25+
26+
@Override
27+
void apply(Project project) {
28+
project.configure(project.subprojects) { sub ->
29+
apply plugin: 'jacoco'
30+
31+
def reportsDir = "${buildDir}/reports/jacoco"
32+
jacoco {
33+
toolVersion = '0.8.5'
34+
reportsDir = reportsDir
35+
}
36+
37+
plugins.withType(FirebaseLibraryPlugin.class) {
38+
39+
sub.tasks.withType(Test) {
40+
jacoco {
41+
excludes = ['jdk.internal.*']
42+
includeNoLocationClasses = true
43+
}
44+
}
45+
46+
sub.task('checkCoverage', type: JacocoReport) {
47+
dependsOn 'check'
48+
description 'Generates JaCoCo check coverage report.'
49+
group 'verification'
50+
51+
def excludes = [
52+
'**/R.class',
53+
'**/R$*.class',
54+
'**/BuildConfig.*',
55+
'**/proto/**',
56+
'**Manifest*.*'
57+
]
58+
classDirectories = files([
59+
fileTree(dir: "$buildDir/intermediates/javac/release", excludes: excludes),
60+
fileTree(dir: "$buildDir/tmp/kotlin-classes/release", excludes: excludes),
61+
])
62+
sourceDirectories = files(['src/main/java', 'src/main/kotlin'])
63+
executionData = fileTree(dir: "$buildDir", includes: ['jacoco/*.exec'])
64+
65+
def firebaseLibrary = sub.extensions.getByType(FirebaseLibraryExtension.class)
66+
def artifactId = firebaseLibrary.artifactId.get()
67+
reports {
68+
html.destination file("${reportsDir}/${artifactId}/html")
69+
xml {
70+
enabled true
71+
destination file("${reportsDir}/${artifactId}.xml")
72+
}
73+
}
74+
75+
outputs.upToDateWhen { false }
76+
}
77+
}
78+
}
79+
}
80+
}

0 commit comments

Comments
 (0)