From 0b5047ec4db8c11a1c1fe192f2d278f6c22f3782 Mon Sep 17 00:00:00 2001 From: Daz DeBoer Date: Sun, 5 Jun 2022 21:55:11 -0600 Subject: [PATCH] Prevent duplicate JSON being written to build-results --- src/resources/build-result-capture.init.gradle | 7 +++++-- .../gradlebuildaction/TestBuildResultRecorder.groovy | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/resources/build-result-capture.init.gradle b/src/resources/build-result-capture.init.gradle index 80dc688..4ef155a 100644 --- a/src/resources/build-result-capture.init.gradle +++ b/src/resources/build-result-capture.init.gradle @@ -84,7 +84,7 @@ def captureUsingBuildFinished(gradle, invocationId) { gradle.buildFinished { result -> def buildResults = [ rootProjectName: gradle.rootProject.name, - rootProjectDir: gradle.rootProject.rootDir.absolutePath, + rootProjectDir: gradle.rootProject.rootDir.absolutePath, requestedTasks: gradle.startParameter.taskNames.join(" "), gradleVersion: GradleVersion.current().version, gradleHomeDir: gradle.gradleHomeDir.absolutePath, @@ -95,7 +95,10 @@ def captureUsingBuildFinished(gradle, invocationId) { def buildResultsDir = new File(System.getenv("RUNNER_TEMP"), ".build-results") buildResultsDir.mkdirs() def buildResultsFile = new File(buildResultsDir, System.getenv("GITHUB_ACTION") + invocationId + ".json") - buildResultsFile << groovy.json.JsonOutput.toJson(buildResults) + // 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) + } } } diff --git a/test/test-init-scripts/src/test/groovy/com/gradle/gradlebuildaction/TestBuildResultRecorder.groovy b/test/test-init-scripts/src/test/groovy/com/gradle/gradlebuildaction/TestBuildResultRecorder.groovy index 0327800..813fbba 100644 --- a/test/test-init-scripts/src/test/groovy/com/gradle/gradlebuildaction/TestBuildResultRecorder.groovy +++ b/test/test-init-scripts/src/test/groovy/com/gradle/gradlebuildaction/TestBuildResultRecorder.groovy @@ -135,6 +135,7 @@ class TestBuildResultRecorder extends BaseInitScriptTest { assert buildResultsDir.listFiles().size() == 1 def resultsFile = buildResultsDir.listFiles()[0] assert resultsFile.name.startsWith('github-step-id') + assert resultsFile.text.count('rootProjectName') == 1 return resultsFile } }