Update download-url.ts
This commit is contained in:
parent
22419e8a39
commit
084e26c09a
@ -5,6 +5,8 @@ import {
|
|||||||
validateStrict,
|
validateStrict,
|
||||||
} from "compare-versions";
|
} from "compare-versions";
|
||||||
import { Input } from "./action";
|
import { Input } from "./action";
|
||||||
|
import { addGitHubApiHeaders } from "./github-api";
|
||||||
|
import { buildUrl, gitHubAssetDownloadUrl } from "./url";
|
||||||
import { getArchitecture, getAvx2, getPlatform, request } from "./utils";
|
import { getArchitecture, getAvx2, getPlatform, request } from "./utils";
|
||||||
|
|
||||||
export async function getDownloadUrl(options: Input): Promise<string> {
|
export async function getDownloadUrl(options: Input): Promise<string> {
|
||||||
@ -25,12 +27,14 @@ async function getSemverDownloadUrl(options: Input): Promise<string> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!tag) {
|
if (!tag) {
|
||||||
|
const apiUrl = buildUrl(
|
||||||
|
"api.github.com",
|
||||||
|
"repos/oven-sh/bun/git/refs/tags",
|
||||||
|
"https",
|
||||||
|
);
|
||||||
|
const headers = addGitHubApiHeaders(apiUrl, {}, options.token);
|
||||||
const res = (await (
|
const res = (await (
|
||||||
await request("https://api.github.com/repos/oven-sh/bun/git/refs/tags", {
|
await request(apiUrl, { headers: headers })
|
||||||
headers: options.token
|
|
||||||
? { "Authorization": `Bearer ${options.token}` }
|
|
||||||
: {},
|
|
||||||
})
|
|
||||||
).json()) as { ref: string }[];
|
).json()) as { ref: string }[];
|
||||||
|
|
||||||
let tags = res
|
let tags = res
|
||||||
@ -62,23 +66,17 @@ async function getSemverDownloadUrl(options: Input): Promise<string> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const resolvedTag = tag ?? version;
|
const resolvedTag = tag ?? version;
|
||||||
const eversion = encodeURIComponent(resolvedTag);
|
const inputArch = arch ?? process.arch;
|
||||||
const eos = encodeURIComponent(os ?? getPlatform());
|
const resolvedOs = os ?? getPlatform();
|
||||||
const earch = encodeURIComponent(
|
const resolvedArch = getArchitecture(resolvedOs, inputArch, resolvedTag);
|
||||||
getArchitecture(os ?? getPlatform(), arch ?? process.arch, resolvedTag),
|
const isAvx2 = getAvx2(resolvedOs, inputArch, avx2, resolvedTag);
|
||||||
);
|
const assetParts: string[] = [
|
||||||
const eavx2 = encodeURIComponent(
|
"bun",
|
||||||
getAvx2(os ?? getPlatform(), arch ?? process.arch, avx2, resolvedTag) ===
|
resolvedOs,
|
||||||
false
|
resolvedArch,
|
||||||
? "-baseline"
|
isAvx2 ? "" : "baseline",
|
||||||
: "",
|
profile ? "profile" : "",
|
||||||
);
|
];
|
||||||
const eprofile = encodeURIComponent(profile === true ? "-profile" : "");
|
const assetName = assetParts.filter((p) => "" !== p).join("-") + ".zip";
|
||||||
|
return gitHubAssetDownloadUrl("oven-sh", "bun", resolvedTag, assetName);
|
||||||
const { href } = new URL(
|
|
||||||
`${eversion}/bun-${eos}-${earch}${eavx2}${eprofile}.zip`,
|
|
||||||
"https://github.com/oven-sh/bun/releases/download/",
|
|
||||||
);
|
|
||||||
|
|
||||||
return href;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user