Do not attempt dependency graph on unsupported Gradle versions

This commit is contained in:
daz 2023-07-07 16:22:07 -06:00
parent 1e71bceb3f
commit f01b48d89d
No known key found for this signature in database
2 changed files with 28 additions and 4 deletions

View File

@ -1,13 +1,20 @@
import org.gradle.util.GradleVersion
if (System.env.GITHUB_DEPENDENCY_GRAPH_ENABLED != "true") { if (System.env.GITHUB_DEPENDENCY_GRAPH_ENABLED != "true") {
return return
} }
if (GradleVersion.current().baseVersion < GradleVersion.version("5.0")) {
println "::warning::Dependency Graph is not supported for Gradle versions < 5.0. No dependency snapshot will be generated."
return
}
def reportDir = System.env.GITHUB_DEPENDENCY_GRAPH_REPORT_DIR def reportDir = System.env.GITHUB_DEPENDENCY_GRAPH_REPORT_DIR
def jobCorrelator = System.env.GITHUB_DEPENDENCY_GRAPH_JOB_CORRELATOR def jobCorrelator = System.env.GITHUB_DEPENDENCY_GRAPH_JOB_CORRELATOR
def reportFile = new File(reportDir, jobCorrelator + ".json") def reportFile = new File(reportDir, jobCorrelator + ".json")
if (reportFile.exists()) { if (reportFile.exists()) {
println "::warning::No dependency report generated for step: report file for '${jobCorrelator}' created in earlier step. Each build invocation requires a unique job correlator: specify GITHUB_DEPENDENCY_GRAPH_JOB_CORRELATOR var for this step." println "::warning::No dependency snapshot generated for step: report file for '${jobCorrelator}' created in earlier step. Each build invocation requires a unique job correlator: specify GITHUB_DEPENDENCY_GRAPH_JOB_CORRELATOR var for this step."
return return
} }

View File

@ -5,6 +5,9 @@ import static org.junit.Assume.assumeTrue
class TestDependencyGraph extends BaseInitScriptTest { class TestDependencyGraph extends BaseInitScriptTest {
def initScript = 'github-dependency-graph.init.gradle' def initScript = 'github-dependency-graph.init.gradle'
static final List<TestGradleVersion> NO_DEPENDENCY_GRAPH_VERSIONS = [GRADLE_3_X, GRADLE_4_X]
static final List<TestGradleVersion> DEPENDENCY_GRAPH_VERSIONS = ALL_VERSIONS - NO_DEPENDENCY_GRAPH_VERSIONS
def "does not produce dependency graph when not enabled"() { def "does not produce dependency graph when not enabled"() {
assumeTrue testGradleVersion.compatibleWithCurrentJvm assumeTrue testGradleVersion.compatibleWithCurrentJvm
@ -29,7 +32,21 @@ class TestDependencyGraph extends BaseInitScriptTest {
assert reportFile.exists() assert reportFile.exists()
where: where:
testGradleVersion << ALL_VERSIONS testGradleVersion << DEPENDENCY_GRAPH_VERSIONS
}
def "warns and produces no dependency graph when enabled for older Gradle versions"() {
assumeTrue testGradleVersion.compatibleWithCurrentJvm
when:
def result = run(['help'], initScript, testGradleVersion.gradleVersion, [], envVars)
then:
assert !reportsDir.exists()
assert result.output.contains("::warning::Dependency Graph is not supported")
where:
testGradleVersion << NO_DEPENDENCY_GRAPH_VERSIONS
} }
def "warns and does not overwrite existing report file"() { def "warns and does not overwrite existing report file"() {
@ -42,10 +59,10 @@ class TestDependencyGraph extends BaseInitScriptTest {
then: then:
assert reportFile.text == "DUMMY CONTENT" assert reportFile.text == "DUMMY CONTENT"
assert result.output.contains("::warning::No dependency report generated for step") assert result.output.contains("::warning::No dependency snapshot generated for step")
where: where:
testGradleVersion << ALL_VERSIONS testGradleVersion << DEPENDENCY_GRAPH_VERSIONS
} }
def getEnvVars() { def getEnvVars() {