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 08:16:10 +02:00
|
|
|
import fetch from 'node-fetch';
|
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:31:07 +02:00
|
|
|
await (await fetch(asset.asset.browser_download_url, {
|
2022-07-28 08:16:10 +02:00
|
|
|
headers: {
|
|
|
|
'Authorization': `token ${token}`
|
|
|
|
}
|
2022-07-28 08:31:07 +02:00
|
|
|
})).text();
|
2022-07-28 08:26:28 +02:00
|
|
|
console.log(new URL(asset.asset.browser_download_url).host.includes('github.com'));
|
2022-07-28 08:31:07 +02:00
|
|
|
const zipPath = await downloadTool(asset.asset.browser_download_url, `token ${token}`,
|
2022-07-28 08:24:56 +02:00
|
|
|
// @ts-expect-error
|
|
|
|
{
|
2022-07-28 08:31:07 +02:00
|
|
|
'Authorization': `token ${token}`
|
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);
|
|
|
|
};
|