setup-bun/dist/utils/install.js

29 lines
1.3 KiB
JavaScript
Raw Normal View History

2022-07-11 09:45:23 +02:00
import { cacheDir, downloadTool, extractZip, find } from '@actions/tool-cache';
2022-07-12 09:00:22 +02:00
import { restoreCache, saveCache } from '@actions/cache';
2022-07-11 09:45:23 +02:00
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-12 09:11:55 +02:00
import { readdirSync } from 'fs';
2022-07-11 09:45:23 +02:00
export default async (release) => {
2022-07-12 09:00:22 +02:00
const asset = getAsset(release.assets);
2022-07-12 09:13:40 +02:00
const path = join(getHomeDir(), '.bun', 'bin', asset.name);
2022-07-12 09:00:22 +02:00
const cache = find('bun', release.version) || await restoreCache([path], `bun-${process.platform}-${asset.name}`);
2022-07-11 09:45:23 +02:00
if (cache) {
info(`Using cached Bun installation from ${cache}.`);
2022-07-12 09:11:55 +02:00
console.log(path);
console.log(readdirSync(path));
2022-07-12 09:10:45 +02:00
addPath(path);
2022-07-11 09:45:23 +02:00
return;
}
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-12 09:16:35 +02:00
const extracted = await extractZip(zipPath, join(getHomeDir(), '.bun', 'bin'));
2022-07-12 08:40:58 +02:00
const newCache = await cacheDir(extracted, 'bun', release.version);
2022-07-12 09:00:22 +02:00
await saveCache([extracted], `bun-${process.platform}-${asset.name}`);
2022-07-11 09:45:23 +02:00
info(`Cached Bun to ${newCache}.`);
addPath(newCache);
2022-07-12 09:13:40 +02:00
const bunPath = join(getHomeDir(), '.bun', 'bin', asset.name);
2022-07-11 09:45:23 +02:00
addPath(bunPath);
};