mirror of
https://github.com/oven-sh/setup-bun.git
synced 2025-07-19 13:08:27 +02:00
feat: custom download url, custom repository
This commit is contained in:
parent
27a94d6f80
commit
e6a8865f72
9 changed files with 135 additions and 21 deletions
|
@ -15,11 +15,13 @@ const main = async() => {
|
|||
try {
|
||||
const version = getInput('bun-version');
|
||||
const token = getInput('github-token');
|
||||
const miscTestBuilds = (getInput('misc-test-builds') === 'true');
|
||||
const repository = getInput('repository');
|
||||
const miscTestBuilds = (getInput('misc-test-builds') === 'true') || (repository.includes('oven-sh/misc-test-builds'));
|
||||
const customDownloadUrl = getInput('custom-download-url') || null;
|
||||
|
||||
if (!version) return exit('Invalid bun version.');
|
||||
|
||||
const release = await getGithubRelease(version, token, miscTestBuilds);
|
||||
const release = await getGithubRelease(version, token, repository, customDownloadUrl, miscTestBuilds);
|
||||
if (release?.message === 'Not Found') return exit('Invalid bun version.', miscTestBuilds);
|
||||
|
||||
info(`Going to install release ${release.version}`);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { exit } from '../index.js';
|
||||
import { Asset } from './getGithubRelease.js';
|
||||
|
||||
export default (assets: Asset[]) => {
|
||||
export const getArchitecture = () => {
|
||||
let arch;
|
||||
switch (process.arch) {
|
||||
case 'arm64':
|
||||
|
@ -15,8 +15,13 @@ export default (assets: Asset[]) => {
|
|||
}
|
||||
|
||||
if (!['linux', 'darwin'].some(platform => process.platform === platform))
|
||||
throw new Error(`Unsupported platform ${process.platform}.`);
|
||||
throw new Error(`Unsupported platform ${process.platform}.`);
|
||||
|
||||
return arch;
|
||||
}
|
||||
|
||||
export default (assets: Asset[]) => {
|
||||
const arch = getArchitecture();
|
||||
const assetName = `bun-${process.platform}-${arch}.zip`;
|
||||
const asset = assets.find(asset => asset.name === assetName);
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import fetch from 'node-fetch';
|
||||
import { getArchitecture } from './getAsset';
|
||||
|
||||
export interface Asset {
|
||||
name: string;
|
||||
|
@ -14,12 +15,28 @@ export interface Release {
|
|||
version: string;
|
||||
}
|
||||
|
||||
export default async(version: string, token: string, miscTestBuilds: boolean): Promise<Release> => {
|
||||
const repository = miscTestBuilds ? 'oven-sh/misc-test-builds' : 'oven-sh/bun'
|
||||
export default async(version: string, token: string, fullRepository: string, customDownloadUrl: string | null, miscTestBuilds: boolean): Promise<Release> => {
|
||||
const repository = miscTestBuilds ? 'oven-sh/misc-test-builds' : fullRepository.split('/').slice(3).join('/');
|
||||
|
||||
let url;
|
||||
if (version === 'latest' || miscTestBuilds) url = `https://api.github.com/repos/${repository}/releases/latest`;
|
||||
if (customDownloadUrl) url = customDownloadUrl;
|
||||
else if (version === 'latest' || miscTestBuilds) url = `https://api.github.com/repos/${repository}/releases/latest`;
|
||||
else url = `https://api.github.com/repos/${repository}/releases/tags/${version.includes('canary') ? version : `bun-v${version}`}`;
|
||||
|
||||
if (customDownloadUrl) {
|
||||
return {
|
||||
name: 'custom',
|
||||
version: version + Math.random().toString(36).slice(-8),
|
||||
html_url: customDownloadUrl,
|
||||
tag_name: 'custom',
|
||||
assets: [
|
||||
{
|
||||
name: `bun-${process.platform}-${getArchitecture()}`,
|
||||
browser_download_url: customDownloadUrl
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
||||
const release: any = await (await fetch(url, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue