mirror of
https://github.com/oven-sh/setup-bun.git
synced 2025-02-23 10:40:10 +08:00
fix: add token property to action definition & fix satisfies params
This commit is contained in:
parent
1cf9dead52
commit
8611d1045b
@ -26,6 +26,10 @@ inputs:
|
||||
type: boolean
|
||||
default: false
|
||||
description: "Disable caching of bun executable."
|
||||
token:
|
||||
required: false
|
||||
default: ${{ github.token }}
|
||||
description: "Personal access token (PAT) used to fetch tags from oven-sh/bun repository"
|
||||
outputs:
|
||||
bun-version:
|
||||
description: The version of Bun that was installed.
|
||||
|
@ -26,6 +26,7 @@ export type Input = {
|
||||
scope?: string;
|
||||
registryUrl?: string;
|
||||
noCache?: boolean;
|
||||
token: string;
|
||||
};
|
||||
|
||||
export type Output = {
|
||||
@ -159,7 +160,11 @@ async function getDownloadUrl(options: Input): Promise<string> {
|
||||
}
|
||||
|
||||
const res = (await (
|
||||
await request("https://api.github.com/repos/oven-sh/bun/git/refs/tags")
|
||||
await request("https://api.github.com/repos/oven-sh/bun/git/refs/tags", {
|
||||
headers: {
|
||||
"Authorization": `Bearer ${options.token}`,
|
||||
},
|
||||
})
|
||||
).json()) as { ref: string }[];
|
||||
let tags = res
|
||||
.filter(
|
||||
@ -175,10 +180,10 @@ async function getDownloadUrl(options: Input): Promise<string> {
|
||||
tags = tags.filter((t) => validate(t)).sort(compareVersions);
|
||||
|
||||
if (version === "latest") tag = tags.at(-1);
|
||||
else tag = tags.filter((t) => satisfies(version, t)).at(-1);
|
||||
else tag = tags.filter((t) => satisfies(t, version)).at(-1);
|
||||
}
|
||||
|
||||
const eversion = encodeURIComponent(tag);
|
||||
const eversion = encodeURIComponent(tag ?? version);
|
||||
const eos = encodeURIComponent(os ?? process.platform);
|
||||
const earch = encodeURIComponent(arch ?? process.arch);
|
||||
const eavx2 = encodeURIComponent(avx2 ? "-baseline" : "");
|
||||
|
@ -16,6 +16,7 @@ runAction({
|
||||
registryUrl: getInput("registry-url") || undefined,
|
||||
scope: getInput("scope") || undefined,
|
||||
noCache: getBooleanInput("no-cache") || false,
|
||||
token: getInput("token"),
|
||||
})
|
||||
.then(({ version, revision, bunPath, url, cacheHit }) => {
|
||||
setOutput("bun-version", version);
|
||||
|
@ -3,8 +3,11 @@ import { info } from "node:console";
|
||||
import { existsSync, readFileSync, renameSync } from "node:fs";
|
||||
import { join, basename } from "node:path";
|
||||
|
||||
export async function request(url: string): Promise<Response> {
|
||||
const res = await fetch(url);
|
||||
export async function request(
|
||||
url: string,
|
||||
init?: RequestInit
|
||||
): Promise<Response> {
|
||||
const res = await fetch(url, init);
|
||||
if (!res.ok) {
|
||||
throw new Error(
|
||||
`Failed to fetch url ${url}. (status code: ${res.status}, status text: ${res.statusText})\n${res}`
|
||||
|
Loading…
x
Reference in New Issue
Block a user