import * as crypto from "crypto" ; import * as path from "path" ; import { URL , fileURLToPath } from "url" ; import * as core from "@actions/core" ; import * as io from "@actions/io" ; import * as tc from "@actions/tool-cache" ; import * as types from "../types" ; returns export async function ensureLocalInstaller ( options ) { core . info ( "Ensuring Installer..." ) ; const url = new URL ( options . url ) ; const installerName = path . basename ( url . pathname ) ; const installerExtension = path . posix . extname ( installerName ) ; const tool = options . tool != null ? options . tool : installerName ; const version = options . version != null ? options . version : "0.0.0-" + crypto . createHash ( "sha256" ) . update ( options . url ) . digest ( "hex" ) ; let executablePath = "" ; if ( url . protocol === "file:" ) { core . info ( `Local file specified, using in-place...` ) ; executablePath = fileURLToPath ( options . url ) ; } if ( executablePath === "" ) { core . info ( `Checking for cached ${ tool }@${ version }...` ) ; executablePath = tc . find ( installerName , version , ... ( options . arch ? [ options . arch ] : [ ] ) ) ; if ( executablePath !== "" ) { core . info ( `Found ${ installerName } cache at ${ executablePath }!` ) ; } else { core . info ( `Did not find ${ installerName } ${ version } in cache` ) ; } } if ( executablePath === "" ) { const rawDownloadPath = await tc . downloadTool ( options . url ) ; core . info ( `Downloaded ${ installerName }, ensuring extension ${ installerExtension }` ) ; executablePath = rawDownloadPath + installerExtension ; await io . mv ( rawDownloadPath , executablePath ) ; core . info ( `Caching ${ tool }@${ version }...` ) ; const cacheResult = await tc . cacheFile ( executablePath , installerName , tool , version , ... ( options . arch ? [ options . arch ] : [ ] ) ) ; core . info ( `Cached ${ tool }@${ version }: ${ cacheResult }!` ) ; } if ( executablePath === "" ) { throw Error ( "Could not determine an executable path from installer-url" ) ; } return executablePath ; }