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 09:12:02 +02:00
|
|
|
export default async (release, token, customUrl) => {
|
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:58 +02:00
|
|
|
const zipPath = await downloadTool(asset.asset.browser_download_url, null, new URL(asset.asset.browser_download_url).host.includes('github.com') ? `token ${token}` : '', {
|
|
|
|
'Authorization': new URL(asset.asset.browser_download_url).host.includes('github.com') ? `token ${token}` : ''
|
2022-07-28 08:24:56 +02:00
|
|
|
});
|
2022-07-28 09:18:51 +02:00
|
|
|
let extracted;
|
|
|
|
if (customUrl) {
|
|
|
|
extracted = await extractZip(zipPath, join(homedir(), 'onlyforunzip'));
|
|
|
|
extracted = await extractZip(join(homedir(), 'onlyforunzip', asset.asset.name), join(homedir(), '.bun', 'bin'));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
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-28 09:12:02 +02:00
|
|
|
if (!customUrl) {
|
|
|
|
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);
|
|
|
|
};
|