Do not write build-results file outside GitHub Actions context

The init-scripts added to Gradle User Home were assuming the presence of certain
GitHub Actions environment variables. With this fix, these init scripts behave
better without these env vars.

Fixes #350
This commit is contained in:
Daz DeBoer 2022-07-11 15:09:56 -06:00
parent 86da5e6c4e
commit 792a93a5e3
No known key found for this signature in database
GPG key ID: DD6B9F0B06683D5D
4 changed files with 33 additions and 10 deletions

View file

@ -200,20 +200,17 @@ task expectFailure {
File initScriptsDir = new File(testProjectDir, "initScripts")
args << '-I' << new File(initScriptsDir, initScript).absolutePath
envVars['RUNNER_TEMP'] = testProjectDir.absolutePath
envVars['GITHUB_ACTION'] = 'github-step-id'
envVars.putIfAbsent('RUNNER_TEMP', testProjectDir.absolutePath)
envVars.putIfAbsent('GITHUB_ACTION', 'github-step-id')
def runner = ((DefaultGradleRunner) GradleRunner.create())
.withJvmArguments(jvmArgs)
.withGradleVersion(gradleVersion.version)
.withProjectDir(testProjectDir)
.withArguments(args)
.withEnvironment(envVars)
.forwardOutput()
if (envVars) {
runner.withEnvironment(envVars)
}
runner
}

View file

@ -134,6 +134,20 @@ class TestBuildResultRecorder extends BaseInitScriptTest {
testGradleVersion << ALL_VERSIONS
}
def "produces no build results file when GitHub env vars not set with #testGradleVersion"() {
assumeTrue testGradleVersion.compatibleWithCurrentJvm
when:
run(['help'], initScript, testGradleVersion.gradleVersion, [], [RUNNER_TEMP: '', GITHUB_ACTION: ''])
then:
def buildResultsDir = new File(testProjectDir, '.build-results')
assert !buildResultsDir.exists()
where:
testGradleVersion << ALL_VERSIONS
}
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