generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use init script to capture build scan URL
Instead of parsing the log output, we instead register a buildScanPublished listener and record the build scan URL to a file. This file is subsequently read to report the build scan URL. Fixes #30
- Loading branch information
Showing
5 changed files
with
76 additions
and
19 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import fs from 'fs' | ||
import path from 'path' | ||
import * as core from '@actions/core' | ||
|
||
export function writeInitScript(): string { | ||
const tmpDir = process.env['RUNNER_TEMP'] || '' | ||
const initScript = path.resolve(tmpDir, 'build-scan-capture.init.gradle') | ||
core.info(`Writing init script: ${initScript}`) | ||
if (fs.existsSync(initScript)) { | ||
return initScript | ||
} | ||
fs.writeFileSync( | ||
initScript, | ||
` | ||
import org.gradle.util.GradleVersion | ||
// Don't run against the included builds (if the main build has any). | ||
def isTopLevelBuild = gradle.getParent() == null | ||
if (isTopLevelBuild) { | ||
def version = GradleVersion.current().baseVersion | ||
def atLeastGradle5 = version >= GradleVersion.version("5.0") | ||
def atLeastGradle6 = version >= GradleVersion.version("6.0") | ||
if (atLeastGradle6) { | ||
settingsEvaluated { settings -> | ||
if (settings.pluginManager.hasPlugin("com.gradle.enterprise")) { | ||
registerCallbacks(settings.extensions["gradleEnterprise"], settings.rootProject.name) | ||
} | ||
} | ||
} else if (atLeastGradle5) { | ||
projectsEvaluated { gradle -> | ||
if (gradle.rootProject.pluginManager.hasPlugin("com.gradle.build-scan")) { | ||
registerCallbacks(gradle.rootProject.extensions["gradleEnterprise"], gradle.rootProject.name) | ||
} | ||
} | ||
} | ||
} | ||
def registerCallbacks(gradleEnterprise, rootProjectName) { | ||
gradleEnterprise.with { | ||
buildScan { | ||
def scanFile = new File("gradle-build-scan.txt") | ||
buildScanPublished { buildScan -> | ||
scanFile.text = buildScan.buildScanUri | ||
} | ||
} | ||
} | ||
} | ||
` | ||
) | ||
return initScript | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters