Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: retry installing three times, add windows for testing #72

Merged
merged 7 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 29 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ jobs:
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"
Expand All @@ -38,10 +37,12 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Bun
uses: ./
with:
bun-version: ${{ matrix.bun-version }}

- name: Run Bun
run: |
bun --version
Expand All @@ -52,28 +53,36 @@ 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@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
setup-bun-from-tool-versions:
Expand All @@ -83,27 +92,34 @@ jobs:
os:
- ubuntu-latest
- macos-latest
- windows-latest
content:
- "bun 1.0.0"
- "bun1.0.0"
- "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.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
Binary file modified bun.lockb
Binary file not shown.
64 changes: 32 additions & 32 deletions dist/setup/index.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
32 changes: 21 additions & 11 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
8 changes: 8 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export function retry<T>(fn: () => Promise<T>, retries: number): Promise<T> {
return fn().catch((err) => {
if (retries <= 0) {
throw err;
}
return retry(fn, retries - 1);
});
}