From a72af0b6a6c6b440e6fbae544648f254eb9aff90 Mon Sep 17 00:00:00 2001 From: Daz DeBoer Date: Sat, 27 Nov 2021 16:11:15 -0700 Subject: [PATCH] Persist build-scan-capture init script into Gradle User Home Instead of writing this file to a temp directory and referencing it on the Gradle command line, the init script is now written to Gradle User Home so that it is picked up automatically. --- src/build-scan-capture.ts | 11 +---------- src/cache-gradle-user-home.ts | 5 +++++ src/execution.ts | 5 ----- 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/build-scan-capture.ts b/src/build-scan-capture.ts index 47948b6..2732b7f 100644 --- a/src/build-scan-capture.ts +++ b/src/build-scan-capture.ts @@ -1,14 +1,6 @@ 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 - } +export function writeBuildScanCaptureInitScript(initScript: string): void { fs.writeFileSync( initScript, ` @@ -46,5 +38,4 @@ def registerCallbacks(buildScanExtension, rootProjectName) { } ` ) - return initScript } diff --git a/src/cache-gradle-user-home.ts b/src/cache-gradle-user-home.ts index 74a94c7..092a479 100644 --- a/src/cache-gradle-user-home.ts +++ b/src/cache-gradle-user-home.ts @@ -7,6 +7,7 @@ import * as exec from '@actions/exec' import {AbstractCache, CacheEntryListener, CacheListener} from './cache-base' import {getCacheKeyPrefix, hashFileNames, tryDelete} from './cache-utils' +import {writeBuildScanCaptureInitScript} from './build-scan-capture' const META_FILE_DIR = '.gradle-build-action' @@ -32,6 +33,10 @@ export class GradleUserHomeCache extends AbstractCache { const propertiesFile = path.resolve(gradleUserHome, 'gradle.properties') this.debug(`Initializing gradle.properties to disable daemon: ${propertiesFile}`) fs.writeFileSync(propertiesFile, 'org.gradle.daemon=false') + + const initScript = path.resolve(gradleUserHome, 'init.gradle') + this.debug(`Adding init script to capture build scans: ${initScript}`) + writeBuildScanCaptureInitScript(initScript) } async afterRestore(listener: CacheListener): Promise { diff --git a/src/execution.ts b/src/execution.ts index fd8097d..1920763 100644 --- a/src/execution.ts +++ b/src/execution.ts @@ -1,15 +1,10 @@ import * as exec from '@actions/exec' import fs from 'fs' import path from 'path' -import {writeInitScript} from './build-scan-capture' export async function execute(executable: string, root: string, args: string[]): Promise { let buildScanUrl: string | undefined - const initScript = writeInitScript() - args.push('--init-script') - args.push(initScript) - const buildScanFile = path.resolve(root, 'gradle-build-scan.txt') if (fs.existsSync(buildScanFile)) { fs.unlinkSync(buildScanFile)