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 type: boolean
default: false default: false
description: "Disable caching of bun executable." 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: outputs:
bun-version: bun-version:
description: The version of Bun that was installed. description: The version of Bun that was installed.

View File

@ -26,6 +26,7 @@ export type Input = {
scope?: string; scope?: string;
registryUrl?: string; registryUrl?: string;
noCache?: boolean; noCache?: boolean;
token: string;
}; };
export type Output = { export type Output = {
@ -159,7 +160,11 @@ async function getDownloadUrl(options: Input): Promise<string> {
} }
const res = (await ( 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 }[]; ).json()) as { ref: string }[];
let tags = res let tags = res
.filter( .filter(
@ -175,10 +180,10 @@ async function getDownloadUrl(options: Input): Promise<string> {
tags = tags.filter((t) => validate(t)).sort(compareVersions); tags = tags.filter((t) => validate(t)).sort(compareVersions);
if (version === "latest") tag = tags.at(-1); 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 eos = encodeURIComponent(os ?? process.platform);
const earch = encodeURIComponent(arch ?? process.arch); const earch = encodeURIComponent(arch ?? process.arch);
const eavx2 = encodeURIComponent(avx2 ? "-baseline" : ""); const eavx2 = encodeURIComponent(avx2 ? "-baseline" : "");

View File

@ -16,6 +16,7 @@ runAction({
registryUrl: getInput("registry-url") || undefined, registryUrl: getInput("registry-url") || undefined,
scope: getInput("scope") || undefined, scope: getInput("scope") || undefined,
noCache: getBooleanInput("no-cache") || false, noCache: getBooleanInput("no-cache") || false,
token: getInput("token"),
}) })
.then(({ version, revision, bunPath, url, cacheHit }) => { .then(({ version, revision, bunPath, url, cacheHit }) => {
setOutput("bun-version", version); setOutput("bun-version", version);

View File

@ -3,8 +3,11 @@ import { info } from "node:console";
import { existsSync, readFileSync, renameSync } from "node:fs"; import { existsSync, readFileSync, renameSync } from "node:fs";
import { join, basename } from "node:path"; import { join, basename } from "node:path";
export async function request(url: string): Promise<Response> { export async function request(
const res = await fetch(url); url: string,
init?: RequestInit
): Promise<Response> {
const res = await fetch(url, init);
if (!res.ok) { if (!res.ok) {
throw new Error( throw new Error(
`Failed to fetch url ${url}. (status code: ${res.status}, status text: ${res.statusText})\n${res}` `Failed to fetch url ${url}. (status code: ${res.status}, status text: ${res.statusText})\n${res}`