Prevent duplicate JSON being written to build-results

This commit is contained in:
Daz DeBoer 2022-06-05 21:55:11 -06:00
parent a4a9a30e86
commit 0b5047ec4d
No known key found for this signature in database
GPG Key ID: DD6B9F0B06683D5D
2 changed files with 6 additions and 2 deletions

View File

@ -95,9 +95,12 @@ def captureUsingBuildFinished(gradle, invocationId) {
def buildResultsDir = new File(System.getenv("RUNNER_TEMP"), ".build-results") def buildResultsDir = new File(System.getenv("RUNNER_TEMP"), ".build-results")
buildResultsDir.mkdirs() buildResultsDir.mkdirs()
def buildResultsFile = new File(buildResultsDir, System.getenv("GITHUB_ACTION") + invocationId + ".json") def buildResultsFile = new File(buildResultsDir, System.getenv("GITHUB_ACTION") + invocationId + ".json")
// Don't overwrite file generated by build-scan plugin if present (which has build-scan-uri)
if (!buildResultsFile.exists()) {
buildResultsFile << groovy.json.JsonOutput.toJson(buildResults) buildResultsFile << groovy.json.JsonOutput.toJson(buildResults)
} }
} }
}
def captureUsingBuildService(settings, invocationId) { def captureUsingBuildService(settings, invocationId) {
gradle.ext.invocationId = invocationId gradle.ext.invocationId = invocationId

View File

@ -135,6 +135,7 @@ class TestBuildResultRecorder extends BaseInitScriptTest {
assert buildResultsDir.listFiles().size() == 1 assert buildResultsDir.listFiles().size() == 1
def resultsFile = buildResultsDir.listFiles()[0] def resultsFile = buildResultsDir.listFiles()[0]
assert resultsFile.name.startsWith('github-step-id') assert resultsFile.name.startsWith('github-step-id')
assert resultsFile.text.count('rootProjectName') == 1
return resultsFile return resultsFile
} }
} }