Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0c5077e514 | ||
|
|
1255e43b02 | ||
|
|
61861d1f6a | ||
|
|
6f5bd063f5 | ||
|
|
e3914758a4 | ||
|
|
ecf28ddc73 | ||
|
|
95edc153a3 | ||
|
|
4c32875876 | ||
|
|
0ff83bfc51 | ||
|
|
ab8cb4e8f8 | ||
|
|
196aaa2bd2 | ||
|
|
3d267786b1 |
@@ -15,7 +15,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: 📥 Checkout
|
||||
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
|
||||
- name: 🛠️ Setup Bun
|
||||
uses: ./
|
||||
@@ -29,4 +29,4 @@ jobs:
|
||||
bun run build
|
||||
|
||||
- name: 💾 Commit
|
||||
uses: autofix-ci/action@551dded8c6cc8a1054039c8bc0b8b48c51dfc6ef
|
||||
uses: autofix-ci/action@635ffb0c9798bd160680f18fd73371e355b85f27 # v1.3.2
|
||||
|
||||
@@ -18,9 +18,9 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
|
||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
|
||||
- uses: actions/publish-action@f784495ce78a41bac4ed7e34a73f0034015764bb # v0.3.0
|
||||
- uses: actions/publish-action@23f4c6f12633a2da8f44938b71fde9afec138fb4 # v0.4.0
|
||||
env:
|
||||
TAG_NAME: ${{ github.event.inputs.TAG_NAME || github.event.release.tag_name }}
|
||||
with:
|
||||
|
||||
@@ -16,7 +16,7 @@ jobs:
|
||||
permissions: write-all
|
||||
steps:
|
||||
- name: 📥 Checkout
|
||||
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
|
||||
- name: 🗑️ Remove cache
|
||||
run: gh cache delete --all || true
|
||||
@@ -28,7 +28,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
|
||||
- name: Setup Bun
|
||||
uses: ./
|
||||
@@ -57,6 +57,7 @@ jobs:
|
||||
- latest
|
||||
- canary
|
||||
- "1.1.0"
|
||||
- "1.3.10"
|
||||
- "1.x"
|
||||
- "1"
|
||||
- "> 1.0.0"
|
||||
@@ -72,7 +73,7 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: 📥 Checkout
|
||||
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
|
||||
- name: 🛠️ Setup Bun
|
||||
uses: ./
|
||||
@@ -148,7 +149,7 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: 📥 Checkout
|
||||
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
|
||||
- name: 📄 Setup file
|
||||
run: ${{ matrix.file.run }}
|
||||
@@ -195,7 +196,7 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: 📥 Checkout
|
||||
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
|
||||
- name: 📄 Setup file
|
||||
run: ${{ matrix.file.run }}
|
||||
@@ -225,7 +226,7 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: 📥 Checkout
|
||||
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
|
||||
- name: 🛠️ Setup Bun
|
||||
uses: ./
|
||||
@@ -250,7 +251,7 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: 📥 Checkout
|
||||
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
|
||||
- name: 🛠️ Setup Bun
|
||||
uses: ./
|
||||
|
||||
+3
-3
@@ -41,8 +41,8 @@ inputs:
|
||||
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. Recommended for resolving wildcard/range versions to avoid GitHub API rate limiting.
|
||||
default: ${{ github.server_url == 'https://github.com' && github.token || '' }}
|
||||
description: Personal access token (PAT) used to fetch tags from oven-sh/bun repository. Recommended for resolving wildcard/range versions to avoid GitHub API rate limiting. When running this action on github.com, the default value is sufficient. When running on GHES, you can pass a personal access token for github.com if you are experiencing rate limiting.
|
||||
|
||||
outputs:
|
||||
bun-version:
|
||||
@@ -57,7 +57,7 @@ outputs:
|
||||
description: If the version of Bun was cached.
|
||||
|
||||
runs:
|
||||
using: "node20"
|
||||
using: "node24"
|
||||
main: "dist/setup/index.js"
|
||||
post: "dist/cache-save/index.js"
|
||||
post-if: success()
|
||||
|
||||
+115
-65
File diff suppressed because one or more lines are too long
+132
-82
File diff suppressed because one or more lines are too long
Generated
-1214
File diff suppressed because it is too large
Load Diff
+12
-12
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"private": true,
|
||||
"name": "setup-bun",
|
||||
"version": "2.1.0",
|
||||
"version": "2.2.0",
|
||||
"description": "Setup Bun on GitHub Actions.",
|
||||
"keywords": [
|
||||
"bun",
|
||||
@@ -18,24 +18,24 @@
|
||||
"author": "xHyroM",
|
||||
"scripts": {
|
||||
"format": "prettier --write src *.yml *.json *.md",
|
||||
"build": "esbuild --target=node20 --outfile=dist/setup/index.js --bundle --keep-names --minify --platform=node --format=cjs src/index.ts && esbuild --target=node20 --outfile=dist/cache-save/index.js --bundle --keep-names --minify --platform=node --format=cjs src/cache-save.ts",
|
||||
"build": "esbuild --target=node24 --outfile=dist/setup/index.js --bundle --keep-names --minify --platform=node --format=cjs src/index.ts && esbuild --target=node24 --outfile=dist/cache-save/index.js --bundle --keep-names --minify --platform=node --format=cjs src/cache-save.ts",
|
||||
"start": "npm run build && node dist/setup/index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions/cache": "^4.0.0",
|
||||
"@actions/core": "^1.11.0",
|
||||
"@actions/exec": "^1.1.1",
|
||||
"@actions/glob": "^0.4.0",
|
||||
"@actions/io": "^1.1.2",
|
||||
"@actions/tool-cache": "^2.0.1",
|
||||
"@actions/cache": "^5.0.5",
|
||||
"@actions/core": "^2.0.3",
|
||||
"@actions/exec": "^2.0.0",
|
||||
"@actions/glob": "^0.5.0",
|
||||
"@actions/io": "^2.0.0",
|
||||
"@actions/tool-cache": "^3.0.0",
|
||||
"@iarna/toml": "^2.2.5",
|
||||
"compare-versions": "^6.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/bun": "^1.1.13",
|
||||
"@types/node": "^20.8.2",
|
||||
"esbuild": "^0.19.2",
|
||||
"prettier": "^3.4.2",
|
||||
"@types/bun": "^1.3.10",
|
||||
"@types/node": "^24.0.0",
|
||||
"esbuild": "^0.19.12",
|
||||
"prettier": "^3.8.1",
|
||||
"typescript": "^4.9.5"
|
||||
},
|
||||
"patchedDependencies": {
|
||||
|
||||
+18
-5
@@ -1,4 +1,3 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { homedir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import {
|
||||
@@ -16,7 +15,7 @@ import { getExecOutput } from "@actions/exec";
|
||||
import { Registry } from "./registry";
|
||||
import { writeBunfig } from "./bunfig";
|
||||
import { saveState } from "@actions/core";
|
||||
import { addExtension } from "./utils";
|
||||
import { addExtension, extractVersionFromUrl, getCacheKey } from "./utils";
|
||||
import { getDownloadUrl } from "./download-url";
|
||||
import { cwd } from "node:process";
|
||||
|
||||
@@ -90,14 +89,28 @@ export default async (options: Input): Promise<Output> => {
|
||||
|
||||
if (!revision) {
|
||||
if (cacheEnabled) {
|
||||
const cacheKey = createHash("sha1").update(url).digest("base64");
|
||||
const cacheKey = getCacheKey(url);
|
||||
|
||||
const cacheRestored = await restoreCache([bunPath], cacheKey);
|
||||
if (cacheRestored) {
|
||||
revision = await getRevision(bunPath);
|
||||
if (revision) {
|
||||
cacheHit = true;
|
||||
info(`Using a cached version of Bun: ${revision}`);
|
||||
const expectedVersion = extractVersionFromUrl(url);
|
||||
const [actualVersion] = revision.split("+");
|
||||
if (!expectedVersion) {
|
||||
warning(
|
||||
`Could not parse expected version from URL: ${url}. Ignoring cache.`,
|
||||
);
|
||||
revision = undefined;
|
||||
} else if (actualVersion !== expectedVersion) {
|
||||
warning(
|
||||
`Cached Bun version ${revision} does not match expected version ${expectedVersion}. Re-downloading.`,
|
||||
);
|
||||
revision = undefined;
|
||||
} else {
|
||||
cacheHit = true;
|
||||
info(`Using a cached version of Bun: ${revision}`);
|
||||
}
|
||||
} else {
|
||||
warning(
|
||||
`Found a cached version of Bun: ${revision} (but it appears to be corrupted?)`,
|
||||
|
||||
+2
-2
@@ -1,11 +1,11 @@
|
||||
import { saveCache } from "@actions/cache";
|
||||
import { getState, warning } from "@actions/core";
|
||||
import { CacheState } from "./action";
|
||||
import { createHash } from "node:crypto";
|
||||
import { getCacheKey } from "./utils";
|
||||
(async () => {
|
||||
const state: CacheState = JSON.parse(getState("cache"));
|
||||
if (state.cacheEnabled && !state.cacheHit) {
|
||||
const cacheKey = createHash("sha1").update(state.url).digest("base64");
|
||||
const cacheKey = getCacheKey(state.url);
|
||||
|
||||
try {
|
||||
await saveCache([state.bunPath], cacheKey);
|
||||
|
||||
+51
-36
@@ -1,4 +1,9 @@
|
||||
import { compareVersions, satisfies, validate } from "compare-versions";
|
||||
import {
|
||||
compareVersions,
|
||||
satisfies,
|
||||
validate,
|
||||
validateStrict,
|
||||
} from "compare-versions";
|
||||
import { Input } from "./action";
|
||||
import { getArchitecture, getAvx2, getPlatform, request } from "./utils";
|
||||
|
||||
@@ -12,49 +17,59 @@ export async function getDownloadUrl(options: Input): Promise<string> {
|
||||
}
|
||||
|
||||
async function getSemverDownloadUrl(options: Input): Promise<string> {
|
||||
const res = (await (
|
||||
await request("https://api.github.com/repos/oven-sh/bun/git/refs/tags", {
|
||||
headers: options.token
|
||||
? { "Authorization": `Bearer ${options.token}` }
|
||||
: {},
|
||||
})
|
||||
).json()) as { ref: string }[];
|
||||
|
||||
let tags = res
|
||||
.filter(
|
||||
(tag) =>
|
||||
tag.ref.startsWith("refs/tags/bun-v") || tag.ref === "refs/tags/canary",
|
||||
)
|
||||
.map((item) => item.ref.replace(/refs\/tags\/(bun-v)?/g, ""))
|
||||
.filter(Boolean);
|
||||
|
||||
const { version, os, arch, avx2, profile } = options;
|
||||
let tag: string | undefined;
|
||||
|
||||
let tag = tags.find((t) => t === version);
|
||||
if (!tag) {
|
||||
tags = tags.filter((t) => validate(t)).sort(compareVersions);
|
||||
|
||||
const matchedTag =
|
||||
version === "latest" || !version
|
||||
? tags.at(-1)
|
||||
: tags.filter((t) => satisfies(t, version)).at(-1);
|
||||
|
||||
if (!matchedTag) {
|
||||
throw new Error(`No Bun release found matching version '${version}'`);
|
||||
}
|
||||
|
||||
tag = `bun-v${matchedTag}`;
|
||||
} else if (validate(tag)) {
|
||||
tag = `bun-v${tag}`;
|
||||
if (validateStrict(version)) {
|
||||
tag = `bun-v${version}`;
|
||||
}
|
||||
|
||||
const eversion = encodeURIComponent(tag ?? version);
|
||||
if (!tag) {
|
||||
const res = (await (
|
||||
await request("https://api.github.com/repos/oven-sh/bun/git/refs/tags", {
|
||||
headers: options.token
|
||||
? { "Authorization": `Bearer ${options.token}` }
|
||||
: {},
|
||||
})
|
||||
).json()) as { ref: string }[];
|
||||
|
||||
let tags = res
|
||||
.filter(
|
||||
(tag) =>
|
||||
tag.ref.startsWith("refs/tags/bun-v") ||
|
||||
tag.ref === "refs/tags/canary",
|
||||
)
|
||||
.map((item) => item.ref.replace(/refs\/tags\/(bun-v)?/g, ""))
|
||||
.filter(Boolean);
|
||||
|
||||
tag = tags.find((t) => t === version);
|
||||
if (!tag) {
|
||||
tags = tags.filter((t) => validate(t)).sort(compareVersions);
|
||||
|
||||
const matchedTag =
|
||||
version === "latest" || !version
|
||||
? tags.at(-1)
|
||||
: tags.filter((t) => satisfies(t, version)).at(-1);
|
||||
|
||||
if (!matchedTag) {
|
||||
throw new Error(`No Bun release found matching version '${version}'`);
|
||||
}
|
||||
|
||||
tag = `bun-v${matchedTag}`;
|
||||
} else if (validate(tag)) {
|
||||
tag = `bun-v${tag}`;
|
||||
}
|
||||
}
|
||||
|
||||
const resolvedTag = tag ?? version;
|
||||
const eversion = encodeURIComponent(resolvedTag);
|
||||
const eos = encodeURIComponent(os ?? getPlatform());
|
||||
const earch = encodeURIComponent(
|
||||
getArchitecture(os ?? getPlatform(), arch ?? process.arch),
|
||||
getArchitecture(os ?? getPlatform(), arch ?? process.arch, resolvedTag),
|
||||
);
|
||||
const eavx2 = encodeURIComponent(
|
||||
getAvx2(os ?? getPlatform(), arch ?? process.arch, avx2) === false
|
||||
getAvx2(os ?? getPlatform(), arch ?? process.arch, avx2, resolvedTag) ===
|
||||
false
|
||||
? "-baseline"
|
||||
: "",
|
||||
);
|
||||
|
||||
+63
-14
@@ -1,7 +1,21 @@
|
||||
import { debug, warning } from "@actions/core";
|
||||
import { info } from "node:console";
|
||||
import { createHash } from "node:crypto";
|
||||
import { existsSync, readFileSync, renameSync } from "node:fs";
|
||||
import { resolve, basename } from "node:path";
|
||||
import { compareVersions, validate } from "compare-versions";
|
||||
|
||||
// First Bun version that ships native Windows ARM64 binaries.
|
||||
const WINDOWS_ARM64_MIN_VERSION = "1.3.10";
|
||||
|
||||
export function getCacheKey(url: string): string {
|
||||
return `bun-${createHash("sha1").update(url).digest("base64")}`;
|
||||
}
|
||||
|
||||
export function extractVersionFromUrl(url: string): string | undefined {
|
||||
const match = url.match(/\/bun-v([^/]+)\//);
|
||||
return match?.[1];
|
||||
}
|
||||
|
||||
export async function request(
|
||||
url: string,
|
||||
@@ -42,28 +56,63 @@ export function getPlatform(): string {
|
||||
return platform;
|
||||
}
|
||||
|
||||
export function getArchitecture(os: string, arch: string): string {
|
||||
if (os === "windows" && (arch === "aarch64" || arch === "arm64")) {
|
||||
warning(
|
||||
[
|
||||
"⚠️ Bun does not provide native arm64 builds for Windows.",
|
||||
"Using x64 baseline build which will run through Microsoft's x64 emulation layer.",
|
||||
"This may result in reduced performance and potential compatibility issues.",
|
||||
"💡 For best performance, consider using x64 Windows runners or other platforms with native support.",
|
||||
].join("\n"),
|
||||
);
|
||||
export function hasNativeWindowsArm64(version?: string): boolean {
|
||||
if (!version) return false;
|
||||
const cleaned = version.replace(/^bun-v/, "");
|
||||
// Non-semver versions like "canary" represent latest builds which ship ARM64.
|
||||
if (!validate(cleaned)) return true;
|
||||
return compareVersions(cleaned, WINDOWS_ARM64_MIN_VERSION) >= 0;
|
||||
}
|
||||
|
||||
return "x64";
|
||||
export function getArchitecture(
|
||||
os: string,
|
||||
arch: string,
|
||||
version?: string,
|
||||
): string {
|
||||
if (os === "windows" && (arch === "aarch64" || arch === "arm64")) {
|
||||
if (!hasNativeWindowsArm64(version)) {
|
||||
warning(
|
||||
[
|
||||
"⚠️ This version of Bun does not provide native arm64 builds for Windows.",
|
||||
"Using x64 baseline build which will run through Microsoft's x64 emulation layer.",
|
||||
"This may result in reduced performance and potential compatibility issues.",
|
||||
"💡 For best performance, consider using Bun >= 1.3.10, x64 Windows runners, or other platforms with native support.",
|
||||
].join("\n"),
|
||||
);
|
||||
|
||||
return "x64";
|
||||
}
|
||||
}
|
||||
|
||||
if (arch === "arm64") return "aarch64";
|
||||
return arch;
|
||||
}
|
||||
|
||||
export function getAvx2(os: string, arch: string, avx2?: boolean): boolean {
|
||||
// Temporary workaround for absence of arm64 builds on Windows (#130)
|
||||
export function getAvx2(
|
||||
os: string,
|
||||
arch: string,
|
||||
avx2?: boolean,
|
||||
version?: string,
|
||||
): boolean {
|
||||
// Workaround for absence of arm64 builds on Windows before 1.3.10 (#130)
|
||||
if (os === "windows" && (arch === "aarch64" || arch === "arm64")) {
|
||||
return false;
|
||||
if (!hasNativeWindowsArm64(version)) {
|
||||
return false;
|
||||
}
|
||||
// Native ARM64 builds don't use AVX2 suffix
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check AVX2 support on x64 Linux
|
||||
if (os === "linux" && arch === "x64" && avx2 === undefined) {
|
||||
try {
|
||||
const cpuInfo = readFileSync("/proc/cpuinfo", "utf8");
|
||||
const hasAvx2 = cpuInfo.includes("avx2");
|
||||
return hasAvx2;
|
||||
} catch (error) {
|
||||
warning(`Failed to detect AVX2 support.`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return avx2 ?? true;
|
||||
|
||||
@@ -0,0 +1,244 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, spyOn } from "bun:test";
|
||||
import { getDownloadUrl } from "../src/download-url";
|
||||
import * as utils from "../src/utils";
|
||||
|
||||
const MOCK_TAGS = [
|
||||
{ ref: "refs/tags/bun-v0.5.0" },
|
||||
{ ref: "refs/tags/bun-v1.0.0" },
|
||||
{ ref: "refs/tags/bun-v1.0.1" },
|
||||
{ ref: "refs/tags/bun-v1.1.0" },
|
||||
{ ref: "refs/tags/bun-v1.3.9" },
|
||||
{ ref: "refs/tags/bun-v1.3.10" },
|
||||
{ ref: "refs/tags/bun-v1.4.0" },
|
||||
{ ref: "refs/tags/canary" },
|
||||
];
|
||||
|
||||
describe("getDownloadUrl", () => {
|
||||
let requestSpy: ReturnType<typeof spyOn>;
|
||||
|
||||
beforeEach(() => {
|
||||
requestSpy = spyOn(utils, "request").mockResolvedValue({
|
||||
json: async () => MOCK_TAGS,
|
||||
} as Response);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
requestSpy.mockRestore();
|
||||
});
|
||||
|
||||
describe("Custom URL", () => {
|
||||
it("should return customUrl if provided", async () => {
|
||||
const url = await getDownloadUrl({
|
||||
customUrl: "https://example.com/bun.zip",
|
||||
});
|
||||
expect(url).toBe("https://example.com/bun.zip");
|
||||
expect(requestSpy).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Optimization (No API Call)", () => {
|
||||
it("should construct URL directly for specific version 1.0.0", async () => {
|
||||
const url = await getDownloadUrl({
|
||||
version: "1.0.0",
|
||||
os: "linux",
|
||||
arch: "x64",
|
||||
});
|
||||
|
||||
expect(url).toBe(
|
||||
"https://github.com/oven-sh/bun/releases/download/bun-v1.0.0/bun-linux-x64.zip",
|
||||
);
|
||||
expect(requestSpy).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
it("should construct URL directly for specific version 0.5.0", async () => {
|
||||
const url = await getDownloadUrl({
|
||||
version: "0.5.0",
|
||||
os: "darwin",
|
||||
arch: "aarch64",
|
||||
});
|
||||
|
||||
expect(url).toBe(
|
||||
"https://github.com/oven-sh/bun/releases/download/bun-v0.5.0/bun-darwin-aarch64.zip",
|
||||
);
|
||||
expect(requestSpy).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
it("should handle avx2=false (baseline) without API call", async () => {
|
||||
const url = await getDownloadUrl({
|
||||
version: "1.1.0",
|
||||
os: "linux",
|
||||
arch: "x64",
|
||||
avx2: false,
|
||||
});
|
||||
|
||||
expect(url).toBe(
|
||||
"https://github.com/oven-sh/bun/releases/download/bun-v1.1.0/bun-linux-x64-baseline.zip",
|
||||
);
|
||||
expect(requestSpy).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
it("should handle profile=true without API call", async () => {
|
||||
const url = await getDownloadUrl({
|
||||
version: "1.1.0",
|
||||
os: "linux",
|
||||
arch: "x64",
|
||||
profile: true,
|
||||
});
|
||||
|
||||
expect(url).toBe(
|
||||
"https://github.com/oven-sh/bun/releases/download/bun-v1.1.0/bun-linux-x64-profile.zip",
|
||||
);
|
||||
expect(requestSpy).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("API Lookup (Dynamic Versions)", () => {
|
||||
it("should call API and resolve 'latest' to the newest version", async () => {
|
||||
const url = await getDownloadUrl({
|
||||
version: "latest",
|
||||
os: "linux",
|
||||
arch: "x64",
|
||||
});
|
||||
|
||||
expect(url).toBe(
|
||||
"https://github.com/oven-sh/bun/releases/download/bun-v1.4.0/bun-linux-x64.zip",
|
||||
);
|
||||
expect(requestSpy).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("should call API and resolve semver range '^1.0.0'", async () => {
|
||||
const url = await getDownloadUrl({
|
||||
version: "^1.0.0",
|
||||
os: "linux",
|
||||
arch: "x64",
|
||||
});
|
||||
|
||||
expect(url).toBe(
|
||||
"https://github.com/oven-sh/bun/releases/download/bun-v1.4.0/bun-linux-x64.zip",
|
||||
);
|
||||
expect(requestSpy).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("should call API and resolve 'canary'", async () => {
|
||||
const url = await getDownloadUrl({
|
||||
version: "canary",
|
||||
os: "linux",
|
||||
arch: "x64",
|
||||
});
|
||||
|
||||
expect(url).toBe(
|
||||
"https://github.com/oven-sh/bun/releases/download/canary/bun-linux-x64.zip",
|
||||
);
|
||||
expect(requestSpy).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("should throw error if semver range matches nothing", async () => {
|
||||
expect(
|
||||
getDownloadUrl({
|
||||
version: "^2.0.0",
|
||||
os: "linux",
|
||||
arch: "x64",
|
||||
}),
|
||||
).rejects.toThrow("No Bun release found matching version '^2.0.0'");
|
||||
expect(requestSpy).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Windows ARM64", () => {
|
||||
it("should use native aarch64 binary for Bun >= 1.3.10", async () => {
|
||||
const url = await getDownloadUrl({
|
||||
version: "1.3.10",
|
||||
os: "windows",
|
||||
arch: "arm64",
|
||||
});
|
||||
|
||||
expect(url).toBe(
|
||||
"https://github.com/oven-sh/bun/releases/download/bun-v1.3.10/bun-windows-aarch64.zip",
|
||||
);
|
||||
expect(requestSpy).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
it("should use native aarch64 binary for Bun 1.4.0", async () => {
|
||||
const url = await getDownloadUrl({
|
||||
version: "1.4.0",
|
||||
os: "windows",
|
||||
arch: "arm64",
|
||||
});
|
||||
|
||||
expect(url).toBe(
|
||||
"https://github.com/oven-sh/bun/releases/download/bun-v1.4.0/bun-windows-aarch64.zip",
|
||||
);
|
||||
expect(requestSpy).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
it("should fall back to x64-baseline for Bun < 1.3.10", async () => {
|
||||
const url = await getDownloadUrl({
|
||||
version: "1.1.0",
|
||||
os: "windows",
|
||||
arch: "arm64",
|
||||
});
|
||||
|
||||
expect(url).toBe(
|
||||
"https://github.com/oven-sh/bun/releases/download/bun-v1.1.0/bun-windows-x64-baseline.zip",
|
||||
);
|
||||
expect(requestSpy).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
it("should fall back to x64-baseline for Bun 1.3.9", async () => {
|
||||
const url = await getDownloadUrl({
|
||||
version: "1.3.9",
|
||||
os: "windows",
|
||||
arch: "arm64",
|
||||
});
|
||||
|
||||
expect(url).toBe(
|
||||
"https://github.com/oven-sh/bun/releases/download/bun-v1.3.9/bun-windows-x64-baseline.zip",
|
||||
);
|
||||
expect(requestSpy).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
it("should use native aarch64 for dynamic version resolving to >= 1.3.10", async () => {
|
||||
const url = await getDownloadUrl({
|
||||
version: "^1.3.0",
|
||||
os: "windows",
|
||||
arch: "arm64",
|
||||
});
|
||||
|
||||
expect(url).toBe(
|
||||
"https://github.com/oven-sh/bun/releases/download/bun-v1.4.0/bun-windows-aarch64.zip",
|
||||
);
|
||||
expect(requestSpy).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("should use native aarch64 for canary on Windows ARM64", async () => {
|
||||
const url = await getDownloadUrl({
|
||||
version: "canary",
|
||||
os: "windows",
|
||||
arch: "arm64",
|
||||
});
|
||||
|
||||
expect(url).toBe(
|
||||
"https://github.com/oven-sh/bun/releases/download/canary/bun-windows-aarch64.zip",
|
||||
);
|
||||
expect(requestSpy).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Token Handling", () => {
|
||||
it("should pass token to API request when resolving dynamic versions", async () => {
|
||||
await getDownloadUrl({
|
||||
version: "latest",
|
||||
token: "my-secret-token",
|
||||
os: "linux",
|
||||
arch: "x64",
|
||||
});
|
||||
|
||||
expect(requestSpy).toHaveBeenCalledWith(
|
||||
expect.stringContaining("api.github.com"),
|
||||
expect.objectContaining({
|
||||
headers: { Authorization: "Bearer my-secret-token" },
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
+105
-32
@@ -1,7 +1,52 @@
|
||||
import { afterEach, describe, expect, it, spyOn } from "bun:test";
|
||||
import { getArchitecture, getAvx2 } from "../src/utils";
|
||||
import { extractVersionFromUrl, getArchitecture, getAvx2, hasNativeWindowsArm64 } from "../src/utils";
|
||||
import * as core from "@actions/core";
|
||||
|
||||
describe("extractVersionFromUrl", () => {
|
||||
it("should extract version from standard download URL", () => {
|
||||
expect(extractVersionFromUrl("https://github.com/oven-sh/bun/releases/download/bun-v1.3.1/bun-linux-x64.zip")).toBe("1.3.1");
|
||||
expect(extractVersionFromUrl("https://github.com/oven-sh/bun/releases/download/bun-v1.0.0/bun-darwin-aarch64.zip")).toBe("1.0.0");
|
||||
expect(extractVersionFromUrl("https://github.com/oven-sh/bun/releases/download/bun-v0.5.0/bun-linux-x64-baseline.zip")).toBe("0.5.0");
|
||||
});
|
||||
|
||||
it("should extract version from URL with profile suffix", () => {
|
||||
expect(extractVersionFromUrl("https://github.com/oven-sh/bun/releases/download/bun-v1.1.0/bun-linux-x64-profile.zip")).toBe("1.1.0");
|
||||
});
|
||||
|
||||
it("should return undefined for canary URL", () => {
|
||||
expect(extractVersionFromUrl("https://github.com/oven-sh/bun/releases/download/canary/bun-linux-x64.zip")).toBeUndefined();
|
||||
});
|
||||
|
||||
it("should return undefined for custom/non-standard URL", () => {
|
||||
expect(extractVersionFromUrl("https://example.com/bun.zip")).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("hasNativeWindowsArm64", () => {
|
||||
it("should return true for version >= 1.3.10", () => {
|
||||
expect(hasNativeWindowsArm64("bun-v1.3.10")).toBe(true);
|
||||
expect(hasNativeWindowsArm64("bun-v1.3.11")).toBe(true);
|
||||
expect(hasNativeWindowsArm64("bun-v1.4.0")).toBe(true);
|
||||
expect(hasNativeWindowsArm64("bun-v2.0.0")).toBe(true);
|
||||
});
|
||||
|
||||
it("should return false for version < 1.3.10", () => {
|
||||
expect(hasNativeWindowsArm64("bun-v1.3.9")).toBe(false);
|
||||
expect(hasNativeWindowsArm64("bun-v1.2.0")).toBe(false);
|
||||
expect(hasNativeWindowsArm64("bun-v1.0.0")).toBe(false);
|
||||
expect(hasNativeWindowsArm64("bun-v0.5.0")).toBe(false);
|
||||
});
|
||||
|
||||
it("should return true for non-semver versions like canary", () => {
|
||||
expect(hasNativeWindowsArm64("canary")).toBe(true);
|
||||
expect(hasNativeWindowsArm64("latest")).toBe(true);
|
||||
});
|
||||
|
||||
it("should return false for undefined version", () => {
|
||||
expect(hasNativeWindowsArm64(undefined)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("getArchitecture", () => {
|
||||
let warningSpy: ReturnType<typeof spyOn>;
|
||||
|
||||
@@ -9,30 +54,54 @@ describe("getArchitecture", () => {
|
||||
warningSpy?.mockRestore();
|
||||
});
|
||||
|
||||
it("should return x64 for Windows with arm64 architecture", () => {
|
||||
it("should return aarch64 for Windows arm64 with Bun >= 1.3.10", () => {
|
||||
warningSpy = spyOn(core, "warning");
|
||||
const result = getArchitecture("windows", "arm64", "bun-v1.3.10");
|
||||
|
||||
expect(result).toBe("aarch64");
|
||||
expect(warningSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should return aarch64 for Windows aarch64 with Bun >= 1.3.10", () => {
|
||||
warningSpy = spyOn(core, "warning");
|
||||
const result = getArchitecture("windows", "aarch64", "bun-v1.4.0");
|
||||
|
||||
expect(result).toBe("aarch64");
|
||||
expect(warningSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should return x64 for Windows arm64 with Bun < 1.3.10", () => {
|
||||
warningSpy = spyOn(core, "warning");
|
||||
const result = getArchitecture("windows", "arm64", "bun-v1.2.0");
|
||||
|
||||
expect(result).toBe("x64");
|
||||
expect(warningSpy).toHaveBeenCalledTimes(1);
|
||||
expect(warningSpy).toHaveBeenCalledWith(
|
||||
expect.stringContaining(
|
||||
"⚠️ This version of Bun does not provide native arm64 builds for Windows."
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
it("should return x64 for Windows aarch64 with Bun < 1.3.10", () => {
|
||||
warningSpy = spyOn(core, "warning");
|
||||
const result = getArchitecture("windows", "aarch64", "bun-v1.0.0");
|
||||
|
||||
expect(result).toBe("x64");
|
||||
expect(warningSpy).toHaveBeenCalledTimes(1);
|
||||
expect(warningSpy).toHaveBeenCalledWith(
|
||||
expect.stringContaining(
|
||||
"⚠️ This version of Bun does not provide native arm64 builds for Windows."
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
it("should return x64 for Windows arm64 with no version (fallback)", () => {
|
||||
warningSpy = spyOn(core, "warning");
|
||||
const result = getArchitecture("windows", "arm64");
|
||||
|
||||
expect(result).toBe("x64");
|
||||
expect(warningSpy).toHaveBeenCalledTimes(1);
|
||||
expect(warningSpy).toHaveBeenCalledWith(
|
||||
expect.stringContaining(
|
||||
"⚠️ Bun does not provide native arm64 builds for Windows."
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
it("should return x64 for Windows with aarch64 architecture", () => {
|
||||
warningSpy = spyOn(core, "warning");
|
||||
const result = getArchitecture("windows", "aarch64");
|
||||
|
||||
expect(result).toBe("x64");
|
||||
expect(warningSpy).toHaveBeenCalledTimes(1);
|
||||
expect(warningSpy).toHaveBeenCalledWith(
|
||||
expect.stringContaining(
|
||||
"⚠️ Bun does not provide native arm64 builds for Windows."
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
it("should return aarch64 for non-Windows platforms with arm64", () => {
|
||||
@@ -77,24 +146,28 @@ describe("getArchitecture", () => {
|
||||
});
|
||||
|
||||
describe("getAvx2", () => {
|
||||
it("should return false when called with os: 'windows' and arch: 'arm64'", () => {
|
||||
const result = getAvx2("windows", "arm64");
|
||||
expect(result).toBe(false);
|
||||
it("should return false for Windows arm64 with Bun < 1.3.10", () => {
|
||||
expect(getAvx2("windows", "arm64", undefined, "bun-v1.2.0")).toBe(false);
|
||||
});
|
||||
|
||||
it("should return false when called with os: 'windows' and arch: 'aarch64'", () => {
|
||||
const result = getAvx2("windows", "aarch64");
|
||||
expect(result).toBe(false);
|
||||
it("should return false for Windows aarch64 with Bun < 1.3.10", () => {
|
||||
expect(getAvx2("windows", "aarch64", undefined, "bun-v1.0.0")).toBe(false);
|
||||
});
|
||||
|
||||
it("should return false when called with os: 'windows', arch: 'arm64', and avx2: true", () => {
|
||||
const result = getAvx2("windows", "arm64", true);
|
||||
expect(result).toBe(false);
|
||||
it("should return false for Windows arm64 with no version (fallback)", () => {
|
||||
expect(getAvx2("windows", "arm64")).toBe(false);
|
||||
});
|
||||
|
||||
it("should return false when called with os: 'windows', arch: 'aarch64', and avx2: false", () => {
|
||||
const result = getAvx2("windows", "aarch64", false);
|
||||
expect(result).toBe(false);
|
||||
it("should return false for Windows aarch64 with no version (fallback)", () => {
|
||||
expect(getAvx2("windows", "aarch64")).toBe(false);
|
||||
});
|
||||
|
||||
it("should return true for Windows arm64 with Bun >= 1.3.10", () => {
|
||||
expect(getAvx2("windows", "arm64", undefined, "bun-v1.3.10")).toBe(true);
|
||||
});
|
||||
|
||||
it("should return true for Windows aarch64 with Bun >= 1.3.10", () => {
|
||||
expect(getAvx2("windows", "aarch64", undefined, "bun-v1.4.0")).toBe(true);
|
||||
});
|
||||
|
||||
it("should return the provided avx2 value (true) when specified and not on Windows ARM64", () => {
|
||||
|
||||
Reference in New Issue
Block a user