setup-bun/dist/utils/install.js

23 lines
967 B
JavaScript
Raw Permalink Normal View History

2022-07-11 09:45:23 +02:00
import { cacheDir, downloadTool, extractZip, find } from '@actions/tool-cache';
import { addPath, info } from '@actions/core';
import getAsset from './getAsset.js';
2022-07-11 10:10:16 +02:00
import getHomeDir from './getHomeDir.js';
2022-07-11 09:45:23 +02:00
import { join } from 'path';
export default async (release) => {
const cache = find('bun', release.tag_name);
if (cache) {
info(`Using cached Bun installation from ${cache}.`);
addPath(cache);
return;
}
const asset = getAsset(release.assets);
2022-07-11 10:13:50 +02:00
info(`Downloading Bun from ${asset.asset.browser_download_url}.`);
const zipPath = await downloadTool(asset.asset.browser_download_url);
2022-07-11 10:16:10 +02:00
const extracted = await extractZip(zipPath, join(getHomeDir(), '.bun', 'bin'));
2022-07-11 09:45:23 +02:00
const newCache = await cacheDir(extracted, 'bun', release.tag_name);
info(`Cached Bun to ${newCache}.`);
addPath(newCache);
2022-07-11 10:16:10 +02:00
const bunPath = join(getHomeDir(), '.bun', 'bin', asset.name.replace('.zip', ''));
2022-07-11 09:45:23 +02:00
addPath(bunPath);
};