setup-bun/dist/utils/install.js

31 lines
1.4 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';
import { join } from 'path';
2022-07-12 09:31:35 +02:00
import { homedir } from 'os';
2022-07-28 07:59:44 +02:00
export default async (release, token) => {
2022-07-12 19:56:32 +02:00
const asset = getAsset(release.assets);
2022-07-12 09:39:16 +02:00
const path = join(homedir(), '.bun', 'bin', asset.name);
2022-07-12 09:23:33 +02:00
const cache = find('bun', release.version) || await restoreCache([path], `bun-${process.platform}-${asset.name}-${release.version}`);
2022-07-11 09:45:23 +02:00
if (cache) {
info(`Using cached Bun installation from ${cache}.`);
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}.`);
2022-07-28 08:39:00 +02:00
const zipPath = await downloadTool(asset.asset.browser_download_url, null, `token ${token}`, {
'Authorization': `token ${token}`,
accept: 'application/octet-stream'
2022-07-28 08:24:56 +02:00
});
2022-07-12 09:39:16 +02:00
const extracted = await extractZip(zipPath, join(homedir(), '.bun', 'bin'));
2022-07-12 08:40:58 +02:00
const newCache = await cacheDir(extracted, 'bun', release.version);
2022-07-12 09:25:05 +02:00
await saveCache([
join(extracted, asset.name)
], `bun-${process.platform}-${asset.name}-${release.version}`);
2022-07-11 09:45:23 +02:00
info(`Cached Bun to ${newCache}.`);
addPath(newCache);
2022-07-12 09:39:16 +02:00
const bunPath = join(homedir(), '.bun', 'bin', asset.name);
2022-07-11 09:45:23 +02:00
addPath(bunPath);
};