Skip to content

Commit

Permalink
Coverage reports and testing changes, now running tests on different …
Browse files Browse the repository at this point in the history
…versions
  • Loading branch information
lukebemish committed Nov 18, 2023
1 parent b1d088f commit 587cc38
Show file tree
Hide file tree
Showing 9 changed files with 302 additions and 43 deletions.
33 changes: 20 additions & 13 deletions .github/workflows/build_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,38 @@ jobs:
with:
cache-read-only: ${{ !startsWith(github.ref, 'refs/heads/1.') }}
- name: Build
id: build
id: assemble
run: |
./gradlew build
./gradlew assemble
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
- name: Publish
- name: Test
run: |
./gradlew publish
./gradlew check --continue
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
- name: Archive publishable artifacts
- name: Upload Test Report
uses: actions/upload-artifact@v3
if: (success() || failure()) && steps.assemble.conclusion == 'success'
with:
name: artifacts
path: build/repo
name: junit-test-results
path: "*/build/test-results/test/TEST-*.xml"
retention-days: 1
- name: Test
- name: Upload Coverage Report
uses: actions/upload-artifact@v3
if: (success() || failure()) && steps.assemble.conclusion == 'success'
with:
name: jacoco-coverage
path: "build/reports/jacoco/testCodeCoverageReport"
- name: Publish
if: steps.assemble.conclusion == 'success'
run: |
./gradlew test
./gradlew publish
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
- name: Upload Test Report
- name: Archive publishable artifacts
uses: actions/upload-artifact@v3
if: (success() || failure()) && steps.build.conclusion == 'success'
with:
name: junit-test-results
path: "*/build/test-results/test/TEST-*.xml"
name: artifacts
path: build/repo
retention-days: 1
13 changes: 12 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,15 @@ jobs:
SONATYPE_USER: ${{ secrets.SONATYPE_USER }}
- run: |
git push
git push --tags
git push --tags
- name: Submit Dependencies
uses: mikepenz/[email protected]
with:
gradle-build-module: |-
:annotations
:runtime
:compile
:groovy
:javac
gradle-build-configuration: |-
compileClasspath
8 changes: 5 additions & 3 deletions .github/workflows/report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ jobs:
checks:
runs-on: ubuntu-latest
steps:
- uses: dorny/test-reporter@v1
- name: JUnit Test Report
uses: dorny/test-reporter@v1
with:
artifact: junit-test-results
name: Test Results
path: '**/*.xml'
reporter: java-junit
path: '**/TEST-*.xml'
reporter: java-junit
fail-on-empty: 'true'
42 changes: 30 additions & 12 deletions .github/workflows/snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,46 @@ jobs:
- uses: fregante/setup-git-user@v2
- uses: gradle/gradle-build-action@v2
name: Setup Gradle
- name: Build
id: build
- name: Assemble
id: assemble
run: |
./gradlew build
./gradlew assemble
env:
SNAPSHOT_MAVEN_URL: https://maven.lukebemish.dev/snapshots/
- name: Publish
run: |
./gradlew publish
env:
MAVEN_USER: github
MAVEN_PASSWORD: ${{ secrets.SNAPSHOT_MAVEN_PASSWORD }}
SNAPSHOT_MAVEN_URL: https://maven.lukebemish.dev/snapshots/
- name: Test
run: |
./gradlew test
./gradlew check --continue
env:
SNAPSHOT_MAVEN_URL: https://maven.lukebemish.dev/snapshots/
- name: Upload Test Report
uses: actions/upload-artifact@v3
if: (success() || failure()) && steps.build.conclusion == 'success'
if: (success() || failure()) && steps.assemble.conclusion == 'success'
with:
name: junit-test-results
path: "*/build/test-results/test/TEST-*.xml"
retention-days: 1
- name: Upload Coverage Report
uses: actions/upload-artifact@v3
if: (success() || failure()) && steps.assemble.conclusion == 'success'
with:
name: jacoco-coverage
path: "build/reports/jacoco/testCodeCoverageReport"
- name: Publish
if: steps.assemble.conclusion == 'success'
run: |
./gradlew publish
env:
MAVEN_USER: github
MAVEN_PASSWORD: ${{ secrets.SNAPSHOT_MAVEN_PASSWORD }}
SNAPSHOT_MAVEN_URL: https://maven.lukebemish.dev/snapshots/
- name: Submit Dependencies
uses: mikepenz/[email protected]
with:
gradle-build-module: |-
:annotations
:runtime
:compile
:groovy
:javac
gradle-build-configuration: |-
compileClasspath
35 changes: 35 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
plugins {
alias libs.plugins.managedversioning
alias libs.plugins.nexuspublish
id 'jacoco-report-aggregation'
id 'test-report-aggregation'
id 'jvm-test-suite'
}

managedVersioning {
Expand All @@ -14,6 +17,19 @@ managedVersioning {

managedVersioning.apply()

repositories {
mavenCentral()
}

dependencies {
subprojects.each { p ->
if (p.name.startsWith('opensesame-')) {
jacocoAggregation p
testReportAggregation p
}
}
}

println "Building: ${rootProject.version}"

if (!System.getenv('PR_NUMBER') && !System.getenv('SNAPSHOT_MAVEN_URL')) {
Expand All @@ -26,4 +42,23 @@ if (!System.getenv('PR_NUMBER') && !System.getenv('SNAPSHOT_MAVEN_URL')) {
}
}
}
}

reporting {
reports {
testCodeCoverageReport(JacocoCoverageReport) {
testType = TestSuiteType.UNIT_TEST
reportTask.configure {
reports.xml.required = true
}
}
testAggregateTestReport(AggregateTestReport) {
testType = TestSuiteType.UNIT_TEST
}
}
}

tasks.named('check').configure {
dependsOn tasks.testCodeCoverageReport
dependsOn tasks.testAggregateTestReport
}
79 changes: 69 additions & 10 deletions buildSrc/src/main/groovy/opensesame.conventions.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@ plugins {
id 'java-library'
id 'signing'
id 'maven-publish'
id 'jacoco'
}

java.toolchain.languageVersion.set JavaLanguageVersion.of(17)

group = rootProject.group
version = rootProject.version

repositories {
mavenCentral()
}
Expand All @@ -26,19 +32,72 @@ dependencies {
testModuleClasspath project(':testtargets')
}

test {
useJUnitPlatform()
testLogging {
showStandardStreams = true
exceptionFormat = 'full'
events = ['passed', 'failed', 'skipped']
testing {
suites.create('testOn21', JvmTestSuite) {
targets.configureEach {
testTask.configure {
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(21)
}
}
}
}

suites.create('testOn17', JvmTestSuite) {
targets.configureEach {
testTask.configure {
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(17)
}
}
}
}

suites.configureEach {
if (it.name == 'test') {
return
}

dependencies {
implementation sourceSets.test.output
}

targets.configureEach {
testTask.configure {
useJUnitPlatform()

testLogging {
showStandardStreams = true
exceptionFormat = 'full'
events = ['passed', 'failed', 'skipped']
}

testClassesDirs += files(
sourceSets.test.output,
configurations.testModuleClasspath
)

outputs.upToDateWhen {false}

jacoco {
excludes += 'dev/lukebemish/opensesame/test/target/*'
}
}
}
}
}

testClassesDirs += files(
configurations.testModuleClasspath
)
configurations {
testOn17RuntimeClasspath.extendsFrom testRuntimeClasspath
testOn21RuntimeClasspath.extendsFrom testRuntimeClasspath

testResultsElementsForTest.extendsFrom testResultsElementsForTestOn17
testResultsElementsForTest.extendsFrom testResultsElementsForTestOn21
}

outputs.upToDateWhen {false}
tasks.named('check') {
dependsOn(testing.suites.testOn21)
dependsOn(testing.suites.testOn17)
}

processResources {
Expand Down
63 changes: 59 additions & 4 deletions groovy/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
plugins {
id 'opensesame.conventions'
}

plugins {
id 'groovy'
id 'opensesame.conventions'
}

java.withSourcesJar()
Expand All @@ -25,6 +22,64 @@ tasks.named('compileGroovy', GroovyCompile).configure {
it.groovyOptions.optimizationOptions.indy = true
}

def testCompileOn(int v) {
var singleTest = tasks.register('testCompileOn'+v, JavaExec) {
javaLauncher.set javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(v)
}

var task = it
dependsOn configurations.testRuntimeClasspath
dependsOn sourceSets.test.groovy.sourceDirectories

var dirProvider = layout.buildDirectory.dir('testClasses')

outputs.dir(dirProvider)
inputs.files(sourceSets.test.groovy.sourceDirectories)

group = "Verification"
description = "Compile test sources with groovy"
classpath = sourceSets.main.runtimeClasspath
mainClass.set 'org.codehaus.groovy.tools.FileSystemCompiler'
argumentProviders.add(
new CommandLineArgumentProvider() {
@Override
List<String> asArguments() {
return [
'-cp', configurations.testCompileClasspath.asPath,
'--temp', task.temporaryDirFactory.create().path,
'-d', dirProvider.get().asFile.path
] +
sourceSets.test.groovy.srcDirs.collectMany { fileTree(it.path).files.collect { it.path } }
}
}
)

jacoco.applyTo(it)
extensions.configure(JacocoTaskExtension) {
it.excludes += 'dev/lukebemish/opensesame/test/target/*'
}
outputs.upToDateWhen { false }

finalizedBy tasks.named('testCompileOn'+v+'CodeCoverateReport')
}

var report = tasks.register('testCompileOn'+v+'CodeCoverateReport', JacocoReport) {
dependsOn singleTest.get()
executionData singleTest.get()
sourceSets sourceSets.main
}

artifacts {
add('coverageDataElementsForTest', report.get().executionData.singleFile) {
builtBy report.get()
}
}
}

testCompileOn(17)
testCompileOn(21)

publishing {
publications {
mavenJava(MavenPublication) {
Expand Down
Loading

0 comments on commit 587cc38

Please sign in to comment.