mirror of
				https://github.com/gradle/gradle-build-action.git
				synced 2025-11-04 09:58:56 +08:00 
			
		
		
		
	capture build scan url on failed build
This commit is contained in:
		@@ -4,10 +4,11 @@ import * as exec from "@actions/exec";
 | 
			
		||||
export async function execute(executable: string, root: string, argv: string[]): Promise<BuildResult> {
 | 
			
		||||
 | 
			
		||||
    let publishing = false;
 | 
			
		||||
    let buildScanLink: any = null;
 | 
			
		||||
    let buildScanUrl: string | undefined;
 | 
			
		||||
 | 
			
		||||
    await exec.exec(executable, argv, {
 | 
			
		||||
    const status: number = await exec.exec(executable, argv, {
 | 
			
		||||
        cwd: root,
 | 
			
		||||
        ignoreReturnCode: true,
 | 
			
		||||
        listeners: {
 | 
			
		||||
            stdline: (line: string) => {
 | 
			
		||||
                if (line.startsWith("Publishing build scan...")) {
 | 
			
		||||
@@ -17,24 +18,25 @@ export async function execute(executable: string, root: string, argv: string[]):
 | 
			
		||||
                    publishing = false
 | 
			
		||||
                }
 | 
			
		||||
                if (publishing && line.startsWith("http")) {
 | 
			
		||||
                    buildScanLink = line.trim();
 | 
			
		||||
                    buildScanUrl = line.trim();
 | 
			
		||||
                    publishing = false
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    if (buildScanLink != null) {
 | 
			
		||||
        return new BuildResultImpl(buildScanLink.toString());
 | 
			
		||||
    }
 | 
			
		||||
    return new BuildResultImpl(null as unknown as string);
 | 
			
		||||
    return new BuildResultImpl(status, buildScanUrl);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export interface BuildResult {
 | 
			
		||||
    buildScanUrl: string
 | 
			
		||||
    readonly status: number
 | 
			
		||||
    readonly buildScanUrl?: string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class BuildResultImpl implements BuildResult {
 | 
			
		||||
    constructor(readonly buildScanUrl: string) {
 | 
			
		||||
    constructor(
 | 
			
		||||
        readonly status: number,
 | 
			
		||||
        readonly buildScanUrl?: string
 | 
			
		||||
    ) {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -8,7 +8,7 @@ import * as provision from "./provision";
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// Invoked by Github Actions
 | 
			
		||||
async function run() {
 | 
			
		||||
export async function run() {
 | 
			
		||||
    try {
 | 
			
		||||
 | 
			
		||||
        const baseDirectory = process.env[`GITHUB_WORKSPACE`] || "";
 | 
			
		||||
@@ -19,10 +19,14 @@ async function run() {
 | 
			
		||||
            parseCommandLineArguments()
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        if (result.buildScanUrl != null) {
 | 
			
		||||
        if (result.buildScanUrl) {
 | 
			
		||||
            core.setOutput("build-scan-url", result.buildScanUrl);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (result.status != 0) {
 | 
			
		||||
            core.setFailed(`Gradle process exited with status ${result.status}`)
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    } catch (error) {
 | 
			
		||||
        core.setFailed(error.message);
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user