import * as core from '@actions/core' ; import * as exec from '@actions/exec' ; import * as toolCache from '@actions/tool-cache' ; import * as path from 'path' ; import * as os from 'os' ; import { chmodSync , renameSync , existsSync , appendFileSync } from 'fs' ; let tempDirectory = process . env [ 'RUNNER_TEMPDIRECTORY' ] || '' ; export async function install ( ) { if ( os . platform ( ) == 'darwin' ) { let toolPath = await installOnUnix ( ) ; core . debug ( 'rustup is located under: ' + toolPath ) ; core . addPath ( path . join ( toolPath , 'bin' ) ) ; } else { await exec . exec ( 'rustup' , [ 'self' , 'update' ] ) ; await exec . exec ( 'rustup' , [ 'set' , 'profile' , 'minimal' ] ) ; if ( os . platform ( ) == 'win32' ) { let cargoPath = '' ; { const options = { listeners : { stdout : ( data ) => { cargoPath += data . toString ( ) ; } } } ; await exec . exec ( 'where' , [ 'rustup.exe' ] , options ) ; } let rustupPath = cargoPath . split ( '\\' ) . slice ( 0 , - 3 ) . concat ( [ ".rustup" ] ) . join ( "\\" ) ; let defaultClearedFilePath = `${ rustupPath }\\default_cleared` ; if ( ! existsSync ( defaultClearedFilePath ) ) { renameSync ( `${ rustupPath }\\toolchains` , `${ rustupPath }\\_toolchains` ) ; appendFileSync ( defaultClearedFilePath , '' ) ; } } } } async function installOnUnix ( ) { let script = await toolCache . downloadTool ( "https://sh.rustup.rs" ) ; chmodSync ( script , '777' ) ; await exec . exec ( `"${ script }"` , [ '-y' , '--default-toolchain' , 'none' , '--profile=minimal' ] ) ; return path . join ( process . env [ 'HOME' ] || '' , '.cargo' ) ; }