From 8611d1045ba1488e88dd4db23e1abe62de35593c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl?= Date: Mon, 29 Jul 2024 20:43:29 +0200 Subject: [PATCH] fix: add token property to action definition & fix satisfies params --- action.yml | 4 ++++ src/action.ts | 11 ++++++++--- src/index.ts | 1 + src/utils.ts | 7 +++++-- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/action.yml b/action.yml index 5c1d85e..1f5385b 100644 --- a/action.yml +++ b/action.yml @@ -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. diff --git a/src/action.ts b/src/action.ts index c22b443..5ebd8cf 100644 --- a/src/action.ts +++ b/src/action.ts @@ -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 { } 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 { 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" : ""); diff --git a/src/index.ts b/src/index.ts index e7578d8..e11eca4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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); diff --git a/src/utils.ts b/src/utils.ts index 7afee5e..ad2342e 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -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 { - const res = await fetch(url); +export async function request( + url: string, + init?: RequestInit +): Promise { + 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}`