fix: add token property to action definition & fix satisfies params

This commit is contained in:
Jozef Steinhübl 2024-07-29 20:43:29 +02:00
parent 1cf9dead52
commit 8611d1045b
No known key found for this signature in database
GPG Key ID: E6BC90C91973B08F
4 changed files with 18 additions and 5 deletions

View File

@ -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.

View File

@ -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" : "");

View File

@ -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);

View File

@ -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}`