mirror of
https://github.com/oven-sh/setup-bun.git
synced 2025-07-19 13:08:27 +02:00
chore: base
This commit is contained in:
parent
b04d87b14c
commit
e187173d21
425 changed files with 1080881 additions and 5 deletions
25
dist/utils/getAsset.js
vendored
Normal file
25
dist/utils/getAsset.js
vendored
Normal file
|
@ -0,0 +1,25 @@
|
|||
export default (assets) => {
|
||||
let arch;
|
||||
switch (process.arch) {
|
||||
case 'arm64':
|
||||
arch = 'aarch64';
|
||||
break;
|
||||
case 'x64':
|
||||
arch = 'x64';
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unsupported architechture ${process.arch}.`);
|
||||
}
|
||||
let platform;
|
||||
switch (process.platform) {
|
||||
case 'linux':
|
||||
platform = 'linux';
|
||||
break;
|
||||
case 'darwin':
|
||||
platform = 'darwin';
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unsupported platform ${process.platform}.`);
|
||||
}
|
||||
return assets.find(asset => asset.name === `bun-${platform}-${arch}.zip`);
|
||||
};
|
16
dist/utils/getGithubRelease.js
vendored
Normal file
16
dist/utils/getGithubRelease.js
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
import { fetch } from 'undici';
|
||||
export default async (version, token) => {
|
||||
let url;
|
||||
if (version === 'latest')
|
||||
url = 'https://api.github.com/repos/oven-sh/bun/releases/latest';
|
||||
else
|
||||
url = `https://api.github.com/repos/oven-sh/bun/releases/tags/bun-v${version}`;
|
||||
const release = await (await fetch(url, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'User-Agent': 'setup-bun-github-action',
|
||||
'Authorization': token
|
||||
}
|
||||
})).json();
|
||||
return release;
|
||||
};
|
3
dist/utils/getHomeDir.js
vendored
Normal file
3
dist/utils/getHomeDir.js
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
export default () => {
|
||||
return process.env[process.platform == 'win32' ? 'USERPROFILE' : 'HOME'];
|
||||
};
|
22
dist/utils/install.js
vendored
Normal file
22
dist/utils/install.js
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
import { cacheDir, downloadTool, extractZip, find } from '@actions/tool-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) => {
|
||||
const cache = find('bun', release.tag_name);
|
||||
if (cache) {
|
||||
info(`Using cached Bun installation from ${cache}.`);
|
||||
addPath(cache);
|
||||
return;
|
||||
}
|
||||
const asset = getAsset(release.assets);
|
||||
info(`Downloading Bun from ${asset.browser_download_url}.`);
|
||||
const zipPath = await downloadTool(asset.browser_download_url);
|
||||
const extracted = await extractZip(zipPath);
|
||||
const newCache = await cacheDir(extracted, 'bun', release.tag_name);
|
||||
info(`Cached Bun to ${newCache}.`);
|
||||
addPath(newCache);
|
||||
const bunPath = join(getHomeDir(), ".bun", "bin");
|
||||
addPath(bunPath);
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue