Skip to content

Commit

Permalink
Use cached path if available
Browse files Browse the repository at this point in the history
  • Loading branch information
tfausak committed Feb 16, 2024
1 parent bb2b1eb commit 65c34d0
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions action/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 65c34d0

Please sign in to comment.