setup-bun/dist/utils/install.js

26 lines
1.0 KiB
JavaScript
Raw 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';
2022-07-11 10:12:03 +02:00
import { readdirSync } from 'fs';
2022-07-11 09:45:23 +02:00
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:10:16 +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:10:16 +02:00
console.log(extracted);
2022-07-11 10:13:50 +02:00
const bunPath = join(getHomeDir(), ".bun", "bin", asset.name.replaceAll('.zip', ''));
2022-07-11 10:12:03 +02:00
console.log(readdirSync(bunPath));
2022-07-11 09:45:23 +02:00
addPath(bunPath);
};