Skip to content

Commit

Permalink
fix: add token property to action definition & fix satisfies params
Browse files Browse the repository at this point in the history
  • Loading branch information
xhyrom committed Jul 29, 2024
1 parent 1cf9dea commit 8611d10
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 8 additions & 3 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export type Input = {
scope?: string;
registryUrl?: string;
noCache?: boolean;
token: string;
};

export type Output = {
Expand Down Expand Up @@ -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(
Expand All @@ -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" : "");
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand Down

0 comments on commit 8611d10

Please sign in to comment.