Skip to content

Commit

Permalink
Restrict Gradle integration tests locally
Browse files Browse the repository at this point in the history
The full set of integration tests with several
Gradle versions will only be executed in CI (GH Action).
Locally only the latest version is checked
to improve test throughput
while still checking that
the test cases are working.
  • Loading branch information
ascheman committed Sep 18, 2024
1 parent 3de2351 commit 78b110f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 11 deletions.
14 changes: 13 additions & 1 deletion htmlSanityCheck-gradle-plugin/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,24 @@ htmlSanityCheck {

The Plugin has been tested with the following Gradle versions:

[source]
[source,groovy]
.Tested Gradle versions
----
include::src/test/groovy/org/aim42/htmlsanitycheck/gradle/HtmlSanityCheckTaskFunctionalSpec.groovy[tag=tested-gradle-versions,indent=0]
----

[NOTE]
====
The full range of Gradle versions is only tested in CI (GitHub action).
The local test only tests the latest Gradle version:
[source,groovy]
.Restricting versions to the latest versions locally
----
include::src/test/groovy/org/aim42/htmlsanitycheck/gradle/HtmlSanityCheckTaskFunctionalSpec.groovy[tag=restrict-gradle-versions-locally,indent=0]
----
====

[[sec:development-versions]]
== Development versions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,37 @@ package org.aim42.htmlsanitycheck.gradle
import org.gradle.testkit.runner.GradleRunner
import org.jsoup.Jsoup
import org.jsoup.nodes.Element
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import spock.lang.Unroll

import static org.gradle.testkit.runner.TaskOutcome.FAILED
import static org.gradle.testkit.runner.TaskOutcome.SUCCESS

class HtmlSanityCheckTaskFunctionalSpec extends HtmlSanityCheckBaseSpec {
private final static GRADLE_VERSIONS = [ // 6.x or older does not work!
'7.6.3', // latest 7.x
'8.0.2', '8.1.1', '8.2.1', '8.3', '8.4',
'8.5', '8.6', '8.7', '8.8', '8.9',
'8.10.1' // all 8.x (latest patches)
]

// @Slf4j does not initialize logger for static initializer
private static final Logger log = LoggerFactory.getLogger(HtmlSanityCheckTaskFunctionalSpec)

private final static List<String> getVersions(List<String> versions) {
// tag::restrict-gradle-versions-locally[]
def result = System.getenv("GITHUB_ACTION") ? versions : [versions[-1]]
// end::restrict-gradle-versions-locally[]
log.warn("Testing HSC Gradle plugin with versions '{}'", result)
return result
}

private final static String[] GRADLE_VERSIONS = getVersions([
// tag::tested-gradle-versions[]
// Test execution in CI will execute all versions.
// Local test is restricted to latest version
// 6.x or older does not work!
'7.6.3', // latest 7.x
'8.0.2', '8.1.1', '8.2.1', '8.3', '8.4',
'8.5', '8.6', '8.7', '8.8', '8.9',
'8.10.1' // all 8.x minor versions (latest patch release)
// end::tested-gradle-versions[]
])

@Unroll
def "can execute htmlSanityCheck task with Gradle version #gradleVersion"() {
Expand All @@ -24,7 +43,7 @@ class HtmlSanityCheckTaskFunctionalSpec extends HtmlSanityCheckBaseSpec {
createBuildFile()

when:
def result = runnerForHtmlSanityCheckTask(gradleVersion).build()
def result = runnerForHtmlSanityCheckTask(gradleVersion as String).build()

then:
result.task(":htmlSanityCheck").outcome == SUCCESS
Expand All @@ -43,7 +62,7 @@ class HtmlSanityCheckTaskFunctionalSpec extends HtmlSanityCheckBaseSpec {

when:

def result = runnerForHtmlSanityCheckTask(gradleVersion).buildAndFail()
def result = runnerForHtmlSanityCheckTask(gradleVersion as String).buildAndFail()

then:
result.task(":htmlSanityCheck").outcome == FAILED
Expand All @@ -66,7 +85,7 @@ class HtmlSanityCheckTaskFunctionalSpec extends HtmlSanityCheckBaseSpec {
""")

when:
def result = runnerForHtmlSanityCheckTask(gradleVersion).build()
def result = runnerForHtmlSanityCheckTask(gradleVersion as String).build()

then:
result.task(":htmlSanityCheck").outcome == SUCCESS
Expand All @@ -84,7 +103,7 @@ class HtmlSanityCheckTaskFunctionalSpec extends HtmlSanityCheckBaseSpec {
""")

when:
runnerForHtmlSanityCheckTask(gradleVersion).build()
runnerForHtmlSanityCheckTask(gradleVersion as String).build()
def htmlReportFile = new File(testProjectDir.root, "build/index.html")

then:
Expand Down

0 comments on commit 78b110f

Please sign in to comment.