-
-
Notifications
You must be signed in to change notification settings - Fork 974
Step 1 (PR-H): Add grails-jacoco convention plugin + Codecov coverage (depends on PR-G) #15687
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
Open
jamesfredley
wants to merge
14
commits into
feat/grails-code-analysis-plugin
Choose a base branch
from
feat/grails-jacoco-plugin
base: feat/grails-code-analysis-plugin
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+530
−2
Open
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f8cf4fa
Add grails-jacoco convention plugin and Codecov coverage workflow
jdaugherty 58a12d5
Address Copilot review feedback: restrict coverage matrix to ubuntu-2…
jdaugherty 9074284
Merge branch 'feat/grails-code-analysis-plugin' into feat/grails-jaco…
jamesfredley 5c91e3b
Merge branch 'feat/grails-code-analysis-plugin' into feat/grails-jaco…
jamesfredley b0e6cf8
fix(ci): pin Coverage workflow actions to ASF-approved SHAs
jamesfredley 236d8a9
Merge remote-tracking branch 'origin/feat/grails-code-analysis-plugin…
jamesfredley 6f6f6dd
Add grails-jacoco convention plugin and Codecov coverage workflow
jdaugherty ef127f7
Address Copilot review feedback: restrict coverage matrix to ubuntu-2…
jdaugherty 73814c9
fix(ci): pin Coverage workflow actions to ASF-approved SHAs
jamesfredley 1933bf7
Merge branch 'feat/grails-jacoco-plugin' of github.com:apache/grails-…
borinquenkid cea9799
test: stabilize scaffolding Geb tests with longer login and logout waits
borinquenkid aead128
build(refactor): update JaCoCo plugin
matrei da989a2
build(style): update JaCoCo plugin
matrei 97fa523
Merge branch 'feat/grails-code-analysis-plugin' into feat/grails-jaco…
jamesfredley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one or more | ||
| # contributor license agreements. See the NOTICE file distributed with | ||
| # this work for additional information regarding copyright ownership. | ||
| # The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| # (the "License"); you may not use this file except in compliance with | ||
| # the License. You may obtain a copy of the License at | ||
| # | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| name: "Coverage" | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - '[0-9]+.[0-9]+.x' | ||
| - '8.0.x-hibernate7.*' | ||
| pull_request: | ||
| workflow_dispatch: | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: ${{ github.event_name == 'pull_request' }} | ||
|
|
||
| jobs: | ||
| coverage-core: | ||
| name: "Coverage - grails-core (${{ matrix.os }})" | ||
| if: ${{ !contains(github.event.head_commit.message, '[skip tests]') }} | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| os: [ubuntu-24.04, macos-latest, windows-latest] | ||
| runs-on: ${{ matrix.os }} | ||
| steps: | ||
| - name: "📥 Checkout repository" | ||
| uses: actions/checkout@v6 | ||
| - name: "☕️ Setup JDK" | ||
| uses: actions/setup-java@v4 | ||
| with: | ||
| distribution: liberica | ||
| java-version: 21 | ||
| - name: "🐘 Setup Gradle" | ||
| uses: gradle/actions/setup-gradle@4d9f0ba0025fe599b4ebab900eb7f3a1d93ef4c2 # v5.0.0 | ||
| with: | ||
| develocity-access-key: ${{ secrets.DEVELOCITY_ACCESS_KEY }} | ||
| - name: "🌡️ Run tests with coverage" | ||
| run: > | ||
| ./gradlew jacocoAggregateReport | ||
| --continue | ||
| --stacktrace | ||
| -PskipCodeStyle | ||
| - name: "📤 Upload coverage artifact" | ||
| uses: actions/upload-artifact@v7.0.1 | ||
| with: | ||
| name: coverage-core-${{ matrix.os }} | ||
| path: build/reports/jacoco/aggregate/jacocoAggregateReport.xml | ||
| if-no-files-found: warn | ||
|
|
||
| coverage-gradle: | ||
| name: "Coverage - grails-gradle (${{ matrix.os }})" | ||
| if: ${{ !contains(github.event.head_commit.message, '[skip tests]') }} | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| os: [ubuntu-24.04, macos-latest, windows-latest] | ||
| runs-on: ${{ matrix.os }} | ||
| steps: | ||
| - name: "📥 Checkout repository" | ||
| uses: actions/checkout@v6 | ||
| - name: "☕️ Setup JDK" | ||
| uses: actions/setup-java@v4 | ||
| with: | ||
| distribution: liberica | ||
| java-version: 21 | ||
| - name: "🐘 Setup Gradle" | ||
| uses: gradle/actions/setup-gradle@4d9f0ba0025fe599b4ebab900eb7f3a1d93ef4c2 # v5.0.0 | ||
| with: | ||
| develocity-access-key: ${{ secrets.DEVELOCITY_ACCESS_KEY }} | ||
| - name: "🌡️ Run tests with coverage" | ||
| working-directory: grails-gradle | ||
| run: > | ||
| ./gradlew jacocoAggregateReport | ||
| --continue | ||
| --stacktrace | ||
| -PskipCodeStyle | ||
| - name: "📤 Upload coverage artifact" | ||
| uses: actions/upload-artifact@v7.0.1 | ||
| with: | ||
| name: coverage-gradle-${{ matrix.os }} | ||
| path: grails-gradle/build/reports/jacoco/aggregate/jacocoAggregateReport.xml | ||
| if-no-files-found: warn | ||
|
|
||
| upload-coverage: | ||
| name: "Upload Coverage to Codecov" | ||
| needs: [coverage-core, coverage-gradle] | ||
| # Run even if some matrix legs fail so partial coverage is still uploaded | ||
| if: always() | ||
| runs-on: ubuntu-24.04 | ||
| steps: | ||
| - name: "📥 Checkout repository" | ||
| uses: actions/checkout@v6 | ||
| - name: "📥 Download all coverage artifacts" | ||
| uses: actions/download-artifact@v7.0.0 | ||
| with: | ||
| path: coverage-reports | ||
| - name: "📊 Upload coverage to Codecov" | ||
| continue-on-error: true | ||
| uses: codecov/codecov-action@57e3a136b779b570ffcdbf80b3bdc90e7fab3de2 # v6.0.0 | ||
| with: | ||
| token: ${{ secrets.CODECOV_TOKEN }} | ||
| directory: coverage-reports | ||
| verbose: true | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
build-logic/plugins/src/main/groovy/org/apache/grails/buildsrc/GrailsJacocoPlugin.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.grails.buildsrc | ||
|
|
||
| import groovy.transform.CompileDynamic | ||
|
|
||
| import org.gradle.api.Plugin | ||
| import org.gradle.api.Project | ||
| import org.gradle.api.plugins.JavaPlugin | ||
| import org.gradle.api.tasks.testing.Test | ||
| import org.gradle.testing.jacoco.plugins.JacocoPlugin | ||
| import org.gradle.testing.jacoco.plugins.JacocoPluginExtension | ||
| import org.gradle.testing.jacoco.tasks.JacocoReport | ||
|
|
||
| /** | ||
| * Convention plugin for JaCoCo code coverage. Apply to each subproject that compiles code. | ||
| * | ||
| * In addition to configuring per-subproject coverage, this plugin lazily registers a | ||
| * jacocoAggregateReport task on the root project the first time it is applied, then wires | ||
| * each subproject's exec data into that task. The aggregate produces a single XML report | ||
| * at build/reports/jacoco/aggregate/jacocoAggregateReport.xml suitable for Codecov upload. | ||
| */ | ||
| @CompileDynamic | ||
| class GrailsJacocoPlugin implements Plugin<Project> { | ||
|
|
||
| static final String AGGREGATE_TASK_NAME = 'jacocoAggregateReport' | ||
|
|
||
| @Override | ||
| void apply(Project project) { | ||
| project.logger.info("Configuring JaCoCo for project: ${project.name}") | ||
| project.pluginManager.apply(JacocoPlugin) | ||
|
|
||
| project.extensions.configure(JacocoPluginExtension) { | ||
| it.toolVersion = '0.8.14' | ||
| } | ||
|
|
||
| project.tasks.withType(Test).configureEach { | ||
| it.finalizedBy 'jacocoTestReport' | ||
| } | ||
|
|
||
| project.tasks.withType(JacocoReport).configureEach { | ||
| it.dependsOn project.tasks.withType(Test) | ||
| it.reports { | ||
| it.xml.required = true | ||
| it.html.required = true | ||
| it.csv.required = true | ||
| } | ||
| } | ||
|
|
||
| contributeToRootAggregateReport(project) | ||
| } | ||
|
|
||
| private static void contributeToRootAggregateReport(Project project) { | ||
| Project root = project.rootProject | ||
|
|
||
| // Ensure JacocoPlugin is on the root so its JacocoReport task has tooling available. | ||
| // pluginManager.apply is idempotent — safe to call from every subproject. | ||
| root.pluginManager.apply(JacocoPlugin) | ||
|
|
||
| // Register the aggregate task once on the first apply; subsequent subprojects find it by name. | ||
| def aggregateTask | ||
| if (root.tasks.names.contains(AGGREGATE_TASK_NAME)) { | ||
| aggregateTask = root.tasks.named(AGGREGATE_TASK_NAME, JacocoReport) | ||
| } else { | ||
| aggregateTask = root.tasks.register(AGGREGATE_TASK_NAME, JacocoReport) { JacocoReport task -> | ||
| task.group = 'verification' | ||
| task.description = 'Aggregates JaCoCo coverage from all subprojects into a single XML report for Codecov.' | ||
| task.reports { | ||
| it.xml.required = true | ||
| it.xml.outputLocation = root.layout.buildDirectory.file( | ||
| 'reports/jacoco/aggregate/jacocoAggregateReport.xml' | ||
| ) | ||
| it.html.required = false | ||
| it.csv.required = false | ||
| } | ||
| task.onlyIf { JacocoReport t -> !t.executionData.files.isEmpty() } | ||
| } | ||
| } | ||
|
|
||
| // Wire this subproject's test exec data into the aggregate. | ||
| aggregateTask.configure { JacocoReport task -> | ||
| task.dependsOn project.tasks.withType(Test) | ||
| task.executionData.from( | ||
| project.fileTree(project.file('build/jacoco')) { include '*.exec' } | ||
| ) | ||
| } | ||
|
|
||
| // Add source and class directories once the Java plugin is confirmed present. | ||
| // Hibernate 7 variant subprojects compile identical class names to their Hibernate 5 | ||
| // counterparts; including both causes JaCoCo to throw "Can't add different class with | ||
| // same name". Exec data from H7 test runs is still included above so their coverage | ||
| // is attributed to the H5 class definitions. | ||
| if (!project.path.contains('hibernate7')) { | ||
| project.plugins.withType(JavaPlugin) { | ||
| aggregateTask.configure { JacocoReport task -> | ||
| task.sourceDirectories.from(project.sourceSets.main.allSource.srcDirs) | ||
| task.classDirectories.from(project.sourceSets.main.output.classesDirs) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.