mirror of
https://github.com/oven-sh/setup-bun.git
synced 2025-07-18 12:38:24 +02:00
feat: add @actions/cache
This commit is contained in:
parent
b15fb7d098
commit
16e8c96a41
1932 changed files with 261172 additions and 10 deletions
|
@ -1,31 +1,32 @@
|
|||
import { Release } from './getGithubRelease.js';
|
||||
import { cacheDir, downloadTool, extractZip, find } from '@actions/tool-cache';
|
||||
import { restoreCache, saveCache } from '@actions/cache';
|
||||
import { addPath, info } from '@actions/core';
|
||||
import getAsset from './getAsset.js';
|
||||
import getHomeDir from './getHomeDir.js';
|
||||
import { join } from 'path';
|
||||
|
||||
export default async(release: Release) => {
|
||||
const cache = find('bun', release.version);
|
||||
console.log(cache);
|
||||
const asset = getAsset(release.assets);
|
||||
const path = join(getHomeDir(), '.bun', 'bin');
|
||||
const cache = find('bun', release.version) || await restoreCache([path], `bun-${process.platform}-${asset.name}`);
|
||||
if (cache) {
|
||||
info(`Using cached Bun installation from ${cache}.`);
|
||||
addPath(cache);
|
||||
return;
|
||||
}
|
||||
|
||||
const asset = getAsset(release.assets);
|
||||
|
||||
info(`Downloading Bun from ${asset.asset.browser_download_url}.`);
|
||||
|
||||
const zipPath = await downloadTool(asset.asset.browser_download_url);
|
||||
const extracted = await extractZip(zipPath, join(getHomeDir(), '.bun', 'bin'));
|
||||
const extracted = await extractZip(zipPath, path);
|
||||
|
||||
const newCache = await cacheDir(
|
||||
extracted,
|
||||
'bun',
|
||||
release.version
|
||||
);
|
||||
await saveCache([extracted], `bun-${process.platform}-${asset.name}`);
|
||||
|
||||
info(`Cached Bun to ${newCache}.`);
|
||||
addPath(newCache);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue