Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f4d14e03ff | ||
|
|
8f24390df0 | ||
|
|
932c3b236c | ||
|
|
9e6479509b | ||
|
|
194c60efc3 |
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@@ -18,7 +18,7 @@ jobs:
|
||||
permissions:
|
||||
contents: write
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/publish-action@v0.3.0
|
||||
with:
|
||||
|
||||
73
.github/workflows/test.yml
vendored
73
.github/workflows/test.yml
vendored
@@ -16,18 +16,14 @@ jobs:
|
||||
continue-on-error: true
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- os: windows-latest
|
||||
bun-version: canary
|
||||
os:
|
||||
- ubuntu-latest
|
||||
- macos-latest
|
||||
- windows-latest
|
||||
bun-version:
|
||||
- latest
|
||||
- canary
|
||||
- "0.8.1" # last version before 1.0
|
||||
- "0.x"
|
||||
- "1.0.0"
|
||||
- "1.1.0"
|
||||
- "1.x"
|
||||
- "1"
|
||||
- "> 1.0.0"
|
||||
@@ -38,13 +34,18 @@ jobs:
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Bun
|
||||
uses: ./
|
||||
id: setup_bun
|
||||
with:
|
||||
bun-version: ${{ matrix.bun-version }}
|
||||
|
||||
- name: Run Bun
|
||||
id: run_bun
|
||||
run: |
|
||||
bun --version
|
||||
|
||||
setup-bun-from-package-json-version:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
@@ -52,27 +53,73 @@ jobs:
|
||||
os:
|
||||
- ubuntu-latest
|
||||
- macos-latest
|
||||
- windows-latest
|
||||
packageManager:
|
||||
- bun@1.0.0
|
||||
- yarn@bun@1.0.0
|
||||
- bun@1.1.0
|
||||
- yarn@bun@1.1.0
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup package.json
|
||||
shell: bash
|
||||
run: |
|
||||
echo "$(jq '. += {"packageManager": "${{ matrix.packageManager }}"}' package.json)" > package.json
|
||||
|
||||
- name: Setup Bun
|
||||
uses: ./
|
||||
|
||||
- name: Run Bun
|
||||
id: bun
|
||||
shell: bash
|
||||
run: |
|
||||
bun --version
|
||||
echo "version=$(bun --version)" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Check version
|
||||
shell: bash
|
||||
run: |
|
||||
if [[ "${{ steps.bun.outputs.version }}" == "1.0.0" ]]; then
|
||||
echo "Version is 1.0.0"
|
||||
if [[ "${{ steps.bun.outputs.version }}" == "1.1.0" ]]; then
|
||||
echo "Version is 1.1.0"
|
||||
else
|
||||
echo "Expected version to be 1.0.0, got ${{ steps.bun.outputs.version }}"
|
||||
echo "Expected version to be 1.1.0, got ${{ steps.bun.outputs.version }}"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
setup-bun-from-tool-versions:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os:
|
||||
- ubuntu-latest
|
||||
- macos-latest
|
||||
- windows-latest
|
||||
content:
|
||||
- "bun 1.1.0"
|
||||
- "bun1.1.0"
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: Setup package.json
|
||||
shell: bash
|
||||
run: |
|
||||
echo "bun ${{ matrix.content }}" > .tool-versions
|
||||
|
||||
- name: Setup Bun
|
||||
uses: ./
|
||||
|
||||
- name: Run Bun
|
||||
id: bun
|
||||
shell: bash
|
||||
run: |
|
||||
bun --version
|
||||
echo "version=$(bun --version)" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Check version
|
||||
shell: bash
|
||||
run: |
|
||||
if [[ "${{ steps.bun.outputs.version }}" == "1.1.0" ]]; then
|
||||
echo "Version is 1.1.0"
|
||||
else
|
||||
echo "Expected version to be 1.1.0, got ${{ steps.bun.outputs.version }}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -5,6 +5,9 @@ branding:
|
||||
icon: play-circle
|
||||
color: white
|
||||
inputs:
|
||||
bun-download-url:
|
||||
description: "Override the URL to download Bun from. This skips version resolution and verifying AVX2 support."
|
||||
required: false
|
||||
bun-version:
|
||||
description: 'The version of Bun to install. (e.g. "latest", "canary", "1.0.0", "1.0.x", <sha>)'
|
||||
required: false
|
||||
|
||||
64
dist/setup/index.js
generated
vendored
64
dist/setup/index.js
generated
vendored
File diff suppressed because one or more lines are too long
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "setup-bun",
|
||||
"version": "1.2.0",
|
||||
"version": "1.2.1",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "setup-bun",
|
||||
"version": "1.2.0",
|
||||
"version": "1.2.1",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/cache": "^3.1.4",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"private": true,
|
||||
"name": "setup-bun",
|
||||
"version": "1.2.0",
|
||||
"version": "1.2.1",
|
||||
"description": "Setup Bun on GitHub Actions.",
|
||||
"keywords": [
|
||||
"bun",
|
||||
|
||||
@@ -13,6 +13,7 @@ import { downloadTool, extractZip } from "@actions/tool-cache";
|
||||
import { getExecOutput } from "@actions/exec";
|
||||
import { writeBunfig } from "./bunfig";
|
||||
import { saveState } from "@actions/core";
|
||||
import { retry } from "./utils";
|
||||
|
||||
export type Input = {
|
||||
customUrl?: string;
|
||||
@@ -86,17 +87,8 @@ export default async (options: Input): Promise<Output> => {
|
||||
|
||||
if (!cacheHit) {
|
||||
info(`Downloading a new version of Bun: ${url}`);
|
||||
const zipPath = await downloadTool(url);
|
||||
const extractedZipPath = await extractZip(zipPath);
|
||||
const extractedBunPath = await extractBun(extractedZipPath);
|
||||
try {
|
||||
renameSync(extractedBunPath, bunPath);
|
||||
} catch {
|
||||
// If mv does not work, try to copy the file instead.
|
||||
// For example: EXDEV: cross-device link not permitted
|
||||
copyFileSync(extractedBunPath, bunPath);
|
||||
}
|
||||
revision = await getRevision(bunPath);
|
||||
// TODO: remove this, temporary fix for https://github.com/oven-sh/setup-bun/issues/73
|
||||
revision = await retry(async () => await downloadBun(url, bunPath), 3);
|
||||
}
|
||||
|
||||
if (!revision) {
|
||||
@@ -123,6 +115,24 @@ export default async (options: Input): Promise<Output> => {
|
||||
};
|
||||
};
|
||||
|
||||
async function downloadBun(
|
||||
url: string,
|
||||
bunPath: string
|
||||
): Promise<string | undefined> {
|
||||
const zipPath = await downloadTool(url);
|
||||
const extractedZipPath = await extractZip(zipPath);
|
||||
const extractedBunPath = await extractBun(extractedZipPath);
|
||||
try {
|
||||
renameSync(extractedBunPath, bunPath);
|
||||
} catch {
|
||||
// If mv does not work, try to copy the file instead.
|
||||
// For example: EXDEV: cross-device link not permitted
|
||||
copyFileSync(extractedBunPath, bunPath);
|
||||
}
|
||||
|
||||
return await getRevision(bunPath);
|
||||
}
|
||||
|
||||
function isCacheEnabled(options: Input): boolean {
|
||||
const { customUrl, version, noCache } = options;
|
||||
if (noCache) {
|
||||
|
||||
28
src/index.ts
28
src/index.ts
@@ -36,8 +36,32 @@ function readVersionFromPackageJson(): string | undefined {
|
||||
}
|
||||
}
|
||||
|
||||
function readVersionFromToolVersions(): string | undefined {
|
||||
const cwd = process.env.GITHUB_WORKSPACE;
|
||||
if (!cwd) {
|
||||
return;
|
||||
}
|
||||
const path = join(cwd, ".tool-versions");
|
||||
try {
|
||||
if (!existsSync(path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const match = readFileSync(path, "utf8").match(/^bun\s(?<version>.*?)$/m);
|
||||
|
||||
return match?.groups?.version;
|
||||
} catch (error) {
|
||||
const { message } = error as Error;
|
||||
warning(`Failed to read .tool-versions: ${message}`);
|
||||
}
|
||||
}
|
||||
|
||||
runAction({
|
||||
version: getInput("bun-version") || readVersionFromPackageJson() || undefined,
|
||||
version:
|
||||
getInput("bun-version") ||
|
||||
readVersionFromPackageJson() ||
|
||||
readVersionFromToolVersions() ||
|
||||
undefined,
|
||||
customUrl: getInput("bun-download-url") || undefined,
|
||||
registryUrl: getInput("registry-url") || undefined,
|
||||
scope: getInput("scope") || undefined,
|
||||
@@ -47,7 +71,9 @@ runAction({
|
||||
setOutput("bun-version", version);
|
||||
setOutput("bun-revision", revision);
|
||||
setOutput("cache-hit", cacheHit);
|
||||
process.exit(0);
|
||||
})
|
||||
.catch((error) => {
|
||||
setFailed(error);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
14
src/utils.ts
Normal file
14
src/utils.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
export function retry<T>(
|
||||
fn: () => Promise<T>,
|
||||
retries: number,
|
||||
timeout = 10000
|
||||
): Promise<T> {
|
||||
return fn().catch((err) => {
|
||||
if (retries <= 0) {
|
||||
throw err;
|
||||
}
|
||||
return new Promise((resolve) => setTimeout(resolve, timeout)).then(() =>
|
||||
retry(fn, retries - 1, timeout)
|
||||
);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user