From 65c34d0a798cb32b3075c851b39258dcc39cb0f0 Mon Sep 17 00:00:00 2001 From: Taylor Fausak <taylor@fausak.me> Date: Fri, 16 Feb 2024 09:39:57 -0600 Subject: [PATCH] Use cached path if available --- action/index.js | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/action/index.js b/action/index.js index 7a213fa..e4e50d7 100644 --- a/action/index.js +++ b/action/index.js @@ -4,29 +4,25 @@ const os = require('os'); const process = require('process'); const tc = require('@actions/tool-cache'); +const TOOL_NAME = 'cabal-gild'; +const LATEST_VERSION = '0.3.0.1'; + (async () => { try { let version = core.getInput('version'); - core.info(`version: ${version}`); if (!version || version === 'latest') { - version = '0.3.0.1'; + version = LATEST_VERSION; } core.setOutput('version', version); - const tool = 'cabal-gild'; - core.info(`tool: ${tool}`); - const platform = process.platform; - core.info(`platform: ${platform}`); - const architecture = os.arch(); - core.info(`architecture: ${architecture}`); - const extension = platform === 'win32' ? '.exe' : ''; - core.info(`extension: ${extension}`); - const existing = tc.find(tool, version); - core.info(`existing: ${existing}`); - const path = await tc.downloadTool(`https://github.com/tfausak/${tool}/releases/download/${version}/${tool}-${version}-${platform}-${architecture}${extension}`); - core.info(`path: ${path}`); - const cached = await tc.cacheFile(path, `${tool}${extension}`, tool, version); - core.info(`cached: ${cached}`); + let path = tc.find(TOOL_NAME, version); + if (!path) { + const platform = process.platform; + const architecture = os.arch(); + const extension = platform === 'win32' ? '.exe' : ''; + const file = await tc.downloadTool(`https://github.com/tfausak/${TOOL_NAME}/releases/download/${version}/${TOOL_NAME}-${version}-${platform}-${architecture}${extension}`); + path = await tc.cacheFile(file, `${TOOL_NAME}${extension}`, TOOL_NAME, version); + } await fs.chmod(path, 0o755); core.setOutput('path', path);