1- // Copyright (c) Microsoft Corporation.
2- // Licensed under the MIT license.
1+ import fs from 'fs'
32
43import * as core from '@actions/core'
4+ import { exec } from '@actions/exec'
55import { HttpClient } from '@actions/http-client'
6+ import * as toolCache from '@actions/tool-cache'
7+
68import {
79 binaryName ,
810 githubRepository ,
911 toolName ,
1012 defaultVersion ,
11- extractBinary
13+ extractBinary ,
14+ getVersionArguments ,
1215} from './tool.js'
13- import * as toolCache from '@actions/tool-cache'
14- import * as util from 'util'
15- import fs from 'fs'
1616
1717/**
1818 * Get the executable extension based on the OS.
@@ -108,26 +108,19 @@ async function download(version: string): Promise<string> {
108108 const runnerOs = getRunnerOS ( )
109109 const runnerArch = getRunnerArch ( )
110110 const binaryFileName = toolName + getExecutableExtension ( )
111- const url = util . format (
112- 'https://github.com/%s/releases/download/%s/%s' ,
113- githubRepository ,
114- version ,
115- binaryName ( version , runnerOs , runnerArch )
116- )
111+ const url = `https://github.com/${ githubRepository } /releases/download/${ version } /${ binaryName ( version , runnerOs , runnerArch ) } `
117112
118113 let cachedToolPath = toolCache . find ( toolName , version )
119- if ( ! cachedToolPath ) {
114+ if ( cachedToolPath ) {
115+ core . info ( `Restoring '${ version } ' from cache` )
116+ } else {
117+ core . info ( `Downloading '${ version } ' from '${ url } '` )
120118 let downloadPath
121119 try {
122120 downloadPath = await toolCache . downloadTool ( url )
123121 } catch ( exception ) {
124122 throw new Error (
125- util . format (
126- 'Failed to download %s from location %s. Error: %s' ,
127- toolName ,
128- url ,
129- exception
130- )
123+ `Failed to download ${ toolName } from location ${ url } . Error: ${ exception } `
131124 )
132125 }
133126
@@ -144,11 +137,7 @@ async function download(version: string): Promise<string> {
144137 cachedToolPath = toolCache . find ( toolName , version )
145138 if ( ! cachedToolPath ) {
146139 throw new Error (
147- util . format (
148- '%s executable not found in path %s' ,
149- binaryFileName ,
150- cachedToolPath
151- )
140+ `${ binaryFileName } executable not found in path ${ cachedToolPath } `
152141 )
153142 }
154143 }
@@ -164,7 +153,9 @@ async function download(version: string): Promise<string> {
164153export async function run ( ) : Promise < void > {
165154 try {
166155 let version = core . getInput ( 'version' , { required : true } )
167- if ( version . toLocaleLowerCase ( ) === 'latest' ) {
156+ if ( version . toLocaleLowerCase ( ) === 'stable' ) {
157+ version = defaultVersion
158+ } else if ( version . toLocaleLowerCase ( ) === 'latest' ) {
168159 version = await latestVersion ( githubRepository , toolName , defaultVersion )
169160 } else if ( ! version . toLocaleLowerCase ( ) . startsWith ( 'v' ) ) {
170161 version = 'v' + version
@@ -177,6 +168,12 @@ export async function run(): Promise<void> {
177168 `${ toolName } version: '${ version } ' has been cached at ${ cachedPath } `
178169 )
179170 core . setOutput ( 'path' , cachedPath )
171+
172+ await exec ( toolName + getExecutableExtension ( ) , getVersionArguments ( ) , {
173+ env : {
174+ PATH : `${ cachedPath } `
175+ }
176+ } )
180177 } catch ( error ) {
181178 // Fail the workflow run if an error occurs
182179 if ( error instanceof Error ) core . setFailed ( error . message )
0 commit comments