mirror of
https://github.com/gradle/gradle-build-action.git
synced 2025-05-02 12:48:36 +02:00
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:
parent
86da5e6c4e
commit
792a93a5e3
4 changed files with 33 additions and 10 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue