diff --git a/sources/src/resources/init-scripts/gradle-actions.build-result-capture-service.plugin.groovy b/sources/src/resources/init-scripts/gradle-actions.build-result-capture-service.plugin.groovy index b0ff4c89..e1adda61 100644 --- a/sources/src/resources/init-scripts/gradle-actions.build-result-capture-service.plugin.groovy +++ b/sources/src/resources/init-scripts/gradle-actions.build-result-capture-service.plugin.groovy @@ -45,8 +45,8 @@ abstract class BuildResultsRecorder implements BuildService= GRADLE_6_X.gradleVersion + } else { + return gradleVersion >= GRADLE_3_X.gradleVersion + } + } + static final class TestGradleVersion { final GradleVersion gradleVersion diff --git a/sources/test/init-scripts/src/test/groovy/com/gradle/gradlebuildaction/TestBuildResultRecorder.groovy b/sources/test/init-scripts/src/test/groovy/com/gradle/gradlebuildaction/TestBuildResultRecorder.groovy index 8f5402ae..476a49d8 100644 --- a/sources/test/init-scripts/src/test/groovy/com/gradle/gradlebuildaction/TestBuildResultRecorder.groovy +++ b/sources/test/init-scripts/src/test/groovy/com/gradle/gradlebuildaction/TestBuildResultRecorder.groovy @@ -11,7 +11,7 @@ class TestBuildResultRecorder extends BaseInitScriptTest { assumeTrue testGradleVersion.compatibleWithCurrentJvm when: - run(['help'], initScript, testGradleVersion.gradleVersion) + run(testGradleVersion.gradleVersion) then: assertResults('help', testGradleVersion, false, false) @@ -25,7 +25,7 @@ class TestBuildResultRecorder extends BaseInitScriptTest { when: addFailingTaskToBuild() - runAndFail(['expectFailure'], initScript, testGradleVersion.gradleVersion) + runAndFail(testGradleVersion.gradleVersion) then: assertResults('expectFailure', testGradleVersion, true, false) @@ -38,14 +38,14 @@ class TestBuildResultRecorder extends BaseInitScriptTest { assumeTrue testGradleVersion.compatibleWithCurrentJvm when: - run(['help', '--configuration-cache'], initScript, testGradleVersion.gradleVersion) + run(['help', '--configuration-cache'], testGradleVersion.gradleVersion) then: assertResults('help', testGradleVersion, false, false) assert buildResultFile.delete() when: - run(['help', '--configuration-cache'], initScript, testGradleVersion.gradleVersion) + run(['help', '--configuration-cache'], testGradleVersion.gradleVersion) then: assertResults('help', testGradleVersion, false, false) @@ -59,7 +59,7 @@ class TestBuildResultRecorder extends BaseInitScriptTest { when: declareDevelocityPluginApplication(testGradleVersion.gradleVersion) - run(['help'], initScript, testGradleVersion.gradleVersion) + run(testGradleVersion.gradleVersion) then: assertResults('help', testGradleVersion, false, true) @@ -73,7 +73,7 @@ class TestBuildResultRecorder extends BaseInitScriptTest { when: declareLegacyGradleEnterprisePluginApplication(testGradleVersion.gradleVersion) - run(['help'], initScript, testGradleVersion.gradleVersion) + run(testGradleVersion.gradleVersion) then: assertResults('help', testGradleVersion, false, true) @@ -87,7 +87,7 @@ class TestBuildResultRecorder extends BaseInitScriptTest { when: declareDevelocityPluginApplication(testGradleVersion.gradleVersion) - run(['help', '--no-scan'], initScript, testGradleVersion.gradleVersion) + run(['help', '--no-scan'], testGradleVersion.gradleVersion) then: assertResults('help', testGradleVersion, false, false) @@ -102,7 +102,7 @@ class TestBuildResultRecorder extends BaseInitScriptTest { when: declareDevelocityPluginApplication(testGradleVersion.gradleVersion) addFailingTaskToBuild() - runAndFail(['expectFailure'], initScript, testGradleVersion.gradleVersion) + runAndFail(testGradleVersion.gradleVersion) then: assertResults('expectFailure', testGradleVersion, true, true) @@ -116,14 +116,14 @@ class TestBuildResultRecorder extends BaseInitScriptTest { when: declareDevelocityPluginApplication(testGradleVersion.gradleVersion) - run(['help', '--configuration-cache'], initScript, testGradleVersion.gradleVersion) + run(['help', '--configuration-cache'], testGradleVersion.gradleVersion) then: assertResults('help', testGradleVersion, false, true) assert buildResultFile.delete() when: - run(['help', '--configuration-cache'], initScript, testGradleVersion.gradleVersion) + run(['help', '--configuration-cache'], testGradleVersion.gradleVersion) then: assertResults('help', testGradleVersion, false, true) @@ -139,7 +139,7 @@ class TestBuildResultRecorder extends BaseInitScriptTest { declareDevelocityPluginApplication(testGradleVersion.gradleVersion) addFailingTaskToBuild() failScanUpload = true - runAndFail(['expectFailure'], initScript, testGradleVersion.gradleVersion) + runAndFail(testGradleVersion.gradleVersion) then: assertResults('expectFailure', testGradleVersion, true, false, true) @@ -152,7 +152,9 @@ class TestBuildResultRecorder extends BaseInitScriptTest { assumeTrue testGradleVersion.compatibleWithCurrentJvm when: - run(['help'], initScript, testGradleVersion.gradleVersion, [], [RUNNER_TEMP: '', GITHUB_ACTION: '']) + run(['help'], initScript, testGradleVersion.gradleVersion, + ["-DRUNNER_TEMP=", "-DGITHUB_ACTION="], + [RUNNER_TEMP: '', GITHUB_ACTION: '']) then: def buildResultsDir = new File(testProjectDir, '.build-results') @@ -169,7 +171,9 @@ class TestBuildResultRecorder extends BaseInitScriptTest { def invalidDir = new File(testProjectDir, 'invalid-runner-temp') invalidDir.createNewFile() - run(['help'], initScript, testGradleVersion.gradleVersion, [], [RUNNER_TEMP: invalidDir.absolutePath]) + run(['help'], initScript, testGradleVersion.gradleVersion, + ["-DRUNNER_TEMP=${invalidDir.absolutePath}".toString()], + [RUNNER_TEMP: invalidDir.absolutePath]) then: def buildResultsDir = new File(testProjectDir, '.build-results') @@ -195,7 +199,7 @@ class TestBuildResultRecorder extends BaseInitScriptTest { } """ + settingsFile.text - run(['help'], initScript, testGradleVersion.gradleVersion) + run(testGradleVersion.gradleVersion) then: assertResults('help', testGradleVersion, false, true) @@ -204,6 +208,28 @@ class TestBuildResultRecorder extends BaseInitScriptTest { testGradleVersion << SETTINGS_PLUGIN_VERSIONS } + def run(def args = ['help'], def gradleVersion) { + return run(args, initScript, gradleVersion, jvmArgs, envVars) + } + + def runAndFail(def gradleVersion) { + return runAndFail(['expectFailure'], initScript, gradleVersion, jvmArgs, envVars) + } + + def getJvmArgs() { + [ + "-DRUNNER_TEMP=${testProjectDir.absolutePath}".toString(), + "-DGITHUB_ACTION=github-step-id".toString() + ] + } + + def getEnvVars() { + [ + RUNNER_TEMP: testProjectDir.absolutePath, + GITHUB_ACTION: 'github-step-id' + ] + } + void assertResults(String task, TestGradleVersion testGradleVersion, boolean hasFailure, boolean hasBuildScan, boolean scanUploadFailed = false) { def results = new JsonSlurper().parse(buildResultFile) assert results['rootProjectName'] == ROOT_PROJECT_NAME diff --git a/sources/test/init-scripts/src/test/groovy/com/gradle/gradlebuildaction/TestDependencyGraph.groovy b/sources/test/init-scripts/src/test/groovy/com/gradle/gradlebuildaction/TestDependencyGraph.groovy index 976a169c..53384003 100644 --- a/sources/test/init-scripts/src/test/groovy/com/gradle/gradlebuildaction/TestDependencyGraph.groovy +++ b/sources/test/init-scripts/src/test/groovy/com/gradle/gradlebuildaction/TestDependencyGraph.groovy @@ -30,7 +30,7 @@ class TestDependencyGraph extends BaseInitScriptTest { assumeTrue testGradleVersion.compatibleWithCurrentJvm when: - run(['help'], initScript, testGradleVersion.gradleVersion, [], envVars) + run(['help'], initScript, testGradleVersion.gradleVersion, jvmArgs, envVars) then: assert reportFile.exists() @@ -43,7 +43,7 @@ class TestDependencyGraph extends BaseInitScriptTest { assumeTrue testGradleVersion.compatibleWithCurrentJvm when: - run(['help', '--configuration-cache'], initScript, testGradleVersion.gradleVersion, [], envVars) + run(['help', '--configuration-cache'], initScript, testGradleVersion.gradleVersion, jvmArgs, envVars) then: assert reportFile.exists() @@ -57,7 +57,7 @@ class TestDependencyGraph extends BaseInitScriptTest { assumeTrue testGradleVersion.compatibleWithCurrentJvm when: - def result = run(['help'], initScript, testGradleVersion.gradleVersion, [], envVars) + def result = run(['help'], initScript, testGradleVersion.gradleVersion, jvmArgs, envVars) then: assert !reportsDir.exists() @@ -73,7 +73,12 @@ class TestDependencyGraph extends BaseInitScriptTest { when: def vars = envVars vars.put('GITHUB_DEPENDENCY_GRAPH_CONTINUE_ON_FAILURE', 'false') - def result = runAndFail(['help'], initScript, testGradleVersion.gradleVersion, [], vars) + def args = jvmArgs + Collections.replaceAll(args, + '-DGITHUB_DEPENDENCY_GRAPH_CONTINUE_ON_FAILURE=true', + '-DGITHUB_DEPENDENCY_GRAPH_CONTINUE_ON_FAILURE=false' + ) + def result = runAndFail(['help'], initScript, testGradleVersion.gradleVersion, args, vars) then: assert !reportsDir.exists() @@ -103,20 +108,20 @@ class TestDependencyGraph extends BaseInitScriptTest { """ when: - run(['help'], initScript, testGradleVersion.gradleVersion, [], envVars) + run(['help'], initScript, testGradleVersion.gradleVersion, jvmArgs, envVars) then: assert reportFile.exists() when: - run(['first'], initScript, testGradleVersion.gradleVersion, [], envVars) + run(['first'], initScript, testGradleVersion.gradleVersion, jvmArgs, envVars) then: assert reportFile.exists() assert reportFile1.exists() when: - run(['second'], initScript, testGradleVersion.gradleVersion, [], envVars) + run(['second'], initScript, testGradleVersion.gradleVersion, jvmArgs, envVars) then: assert reportFile.exists() @@ -133,7 +138,11 @@ class TestDependencyGraph extends BaseInitScriptTest { when: def vars = envVars vars.put('GRADLE_PLUGIN_REPOSITORY_URL', 'https://plugins.grdev.net/m2') - def result = run(['help', '--info'], initScript, testGradleVersion.gradleVersion, [], vars) + // TODO:DAZ This props are set too late to control init-script plugin resolution + // This makes the tests fail on Mac with Gradle < 6 + def args = jvmArgs + args.add('-DGRADLE_PLUGIN_REPOSITORY_URL=https://plugins.grdev.net/m2') + def result = run(['help', '--info'], initScript, testGradleVersion.gradleVersion, args, vars) then: assert reportFile.exists() @@ -151,7 +160,13 @@ class TestDependencyGraph extends BaseInitScriptTest { vars.put('GRADLE_PLUGIN_REPOSITORY_URL', 'https://plugins.grdev.net/m2') vars.put('GRADLE_PLUGIN_REPOSITORY_USERNAME', 'REPO_USER') vars.put('GRADLE_PLUGIN_REPOSITORY_PASSWORD', 'REPO_PASSWORD') - def result = run(['help', '--info'], initScript, testGradleVersion.gradleVersion, [], vars) + // TODO:DAZ This props are set too late to control init-script plugin resolution + // This makes the tests fail on Mac with Gradle < 6 + def args = jvmArgs + args.add('-DGRADLE_PLUGIN_REPOSITORY_URL=https://plugins.grdev.net/m2') + args.add('-DGRADLE_PLUGIN_REPOSITORY_USERNAME=REPO_USER') + args.add('-DGRADLE_PLUGIN_REPOSITORY_PASSWORD=REPO_PASSWORD') + def result = run(['help', '--info'], initScript, testGradleVersion.gradleVersion, args, vars) then: assert reportFile.exists() @@ -175,6 +190,19 @@ class TestDependencyGraph extends BaseInitScriptTest { ] } + def getJvmArgs() { + return [ + "-DGITHUB_DEPENDENCY_GRAPH_ENABLED=true", + "-DGITHUB_DEPENDENCY_GRAPH_CONTINUE_ON_FAILURE=true", + "-DGITHUB_DEPENDENCY_GRAPH_JOB_CORRELATOR=CORRELATOR", + "-DGITHUB_DEPENDENCY_GRAPH_JOB_ID=1", + "-DGITHUB_DEPENDENCY_GRAPH_REF=main", + "-DGITHUB_DEPENDENCY_GRAPH_SHA=123456", + "-DGITHUB_DEPENDENCY_GRAPH_WORKSPACE=" + testProjectDir.absolutePath, + "-DDEPENDENCY_GRAPH_REPORT_DIR=" + reportsDir.absolutePath, + ].collect {it.toString() } // Convert from GString to String + } + def getReportsDir() { return new File(testProjectDir, 'build/reports/github-dependency-graph-snapshots') } diff --git a/sources/test/init-scripts/src/test/groovy/com/gradle/gradlebuildaction/TestDevelocityInjection.groovy b/sources/test/init-scripts/src/test/groovy/com/gradle/gradlebuildaction/TestDevelocityInjection.groovy index 6c988961..20ce467c 100644 --- a/sources/test/init-scripts/src/test/groovy/com/gradle/gradlebuildaction/TestDevelocityInjection.groovy +++ b/sources/test/init-scripts/src/test/groovy/com/gradle/gradlebuildaction/TestDevelocityInjection.groovy @@ -425,21 +425,7 @@ class TestDevelocityInjection extends BaseInitScriptTest { } private BuildResult run(TestGradleVersion testGradleVersion, TestConfig config, List args = ["help"]) { - if (testKitSupportsEnvVars(testGradleVersion.gradleVersion)) { - return run(args, initScript, testGradleVersion.gradleVersion, [], config.envVars) - } else { - return run(args, initScript, testGradleVersion.gradleVersion, config.jvmArgs, [:]) - } - } - - private boolean testKitSupportsEnvVars(GradleVersion gradleVersion) { - // TestKit supports env vars for Gradle 3.5+, except on M1 Mac where only 6.9+ is supported - def isM1Mac = System.getProperty("os.arch") == "aarch64" - if (isM1Mac) { - return gradleVersion >= GRADLE_6_X.gradleVersion - } else { - return gradleVersion >= GRADLE_3_X.gradleVersion - } + return run(args, initScript, testGradleVersion.gradleVersion, config.jvmArgs, config.envVars) } private TestConfig testConfig(String develocityPluginVersion = DEVELOCITY_PLUGIN_VERSION) {