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

* ci: test windows

* ci: specify shell

* ci: we don't have >1.1.0

* fix: retry installing version three times

* [autofix.ci] apply automated fixes

* build: bump version to 1.2.1

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
Jozef Steinhübl 2024-04-02 11:24:51 +02:00 committed by GitHub
parent 9e6479509b
commit 932c3b236c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 93 additions and 59 deletions

View File

@ -22,12 +22,11 @@ jobs:
os: os:
- ubuntu-latest - ubuntu-latest
- macos-latest - macos-latest
- windows-latest
bun-version: bun-version:
- latest - latest
- canary - canary
- "0.8.1" # last version before 1.0 - "1.1.0"
- "0.x"
- "1.0.0"
- "1.x" - "1.x"
- "1" - "1"
- "> 1.0.0" - "> 1.0.0"
@ -38,10 +37,12 @@ jobs:
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Setup Bun - name: Setup Bun
uses: ./ uses: ./
with: with:
bun-version: ${{ matrix.bun-version }} bun-version: ${{ matrix.bun-version }}
- name: Run Bun - name: Run Bun
run: | run: |
bun --version bun --version
@ -52,28 +53,36 @@ jobs:
os: os:
- ubuntu-latest - ubuntu-latest
- macos-latest - macos-latest
- windows-latest
packageManager: packageManager:
- bun@1.0.0 - bun@1.1.0
- yarn@bun@1.0.0 - yarn@bun@1.1.0
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Setup package.json - name: Setup package.json
shell: bash
run: | run: |
echo "$(jq '. += {"packageManager": "${{ matrix.packageManager }}"}' package.json)" > package.json echo "$(jq '. += {"packageManager": "${{ matrix.packageManager }}"}' package.json)" > package.json
- name: Setup Bun - name: Setup Bun
uses: ./ uses: ./
- name: Run Bun - name: Run Bun
id: bun id: bun
shell: bash
run: | run: |
bun --version bun --version
echo "version=$(bun --version)" >> $GITHUB_OUTPUT echo "version=$(bun --version)" >> $GITHUB_OUTPUT
- name: Check version - name: Check version
shell: bash
run: | run: |
if [[ "${{ steps.bun.outputs.version }}" == "1.0.0" ]]; then if [[ "${{ steps.bun.outputs.version }}" == "1.1.0" ]]; then
echo "Version is 1.0.0" echo "Version is 1.1.0"
else 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 exit 1
fi fi
setup-bun-from-tool-versions: setup-bun-from-tool-versions:
@ -83,27 +92,34 @@ jobs:
os: os:
- ubuntu-latest - ubuntu-latest
- macos-latest - macos-latest
- windows-latest
content: content:
- "bun 1.0.0" - "bun 1.1.0"
- "bun1.0.0" - "bun1.1.0"
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Setup package.json - name: Setup package.json
shell: bash
run: | run: |
echo "bun ${{ matrix.content }}" > .tool-versions echo "bun ${{ matrix.content }}" > .tool-versions
- name: Setup Bun - name: Setup Bun
uses: ./ uses: ./
- name: Run Bun - name: Run Bun
id: bun id: bun
shell: bash
run: | run: |
bun --version bun --version
echo "version=$(bun --version)" >> $GITHUB_OUTPUT echo "version=$(bun --version)" >> $GITHUB_OUTPUT
- name: Check version - name: Check version
shell: bash
run: | run: |
if [[ "${{ steps.bun.outputs.version }}" == "1.0.0" ]]; then if [[ "${{ steps.bun.outputs.version }}" == "1.1.0" ]]; then
echo "Version is 1.0.0" echo "Version is 1.1.0"
else 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 exit 1
fi fi

BIN
bun.lockb

Binary file not shown.

64
dist/setup/index.js generated vendored

File diff suppressed because one or more lines are too long

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "setup-bun", "name": "setup-bun",
"version": "1.2.0", "version": "1.2.1",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "setup-bun", "name": "setup-bun",
"version": "1.2.0", "version": "1.2.1",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/cache": "^3.1.4", "@actions/cache": "^3.1.4",

View File

@ -1,7 +1,7 @@
{ {
"private": true, "private": true,
"name": "setup-bun", "name": "setup-bun",
"version": "1.2.0", "version": "1.2.1",
"description": "Setup Bun on GitHub Actions.", "description": "Setup Bun on GitHub Actions.",
"keywords": [ "keywords": [
"bun", "bun",

View File

@ -13,6 +13,7 @@ import { downloadTool, extractZip } from "@actions/tool-cache";
import { getExecOutput } from "@actions/exec"; import { getExecOutput } from "@actions/exec";
import { writeBunfig } from "./bunfig"; import { writeBunfig } from "./bunfig";
import { saveState } from "@actions/core"; import { saveState } from "@actions/core";
import { retry } from "./utils";
export type Input = { export type Input = {
customUrl?: string; customUrl?: string;
@ -86,17 +87,8 @@ export default async (options: Input): Promise<Output> => {
if (!cacheHit) { if (!cacheHit) {
info(`Downloading a new version of Bun: ${url}`); info(`Downloading a new version of Bun: ${url}`);
const zipPath = await downloadTool(url); // TODO: remove this, temporary fix for https://github.com/oven-sh/setup-bun/issues/73
const extractedZipPath = await extractZip(zipPath); revision = await retry(async () => await downloadBun(url, bunPath), 3);
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);
} }
if (!revision) { 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 { function isCacheEnabled(options: Input): boolean {
const { customUrl, version, noCache } = options; const { customUrl, version, noCache } = options;
if (noCache) { if (noCache) {

8
src/utils.ts Normal file
View File

@ -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);
});
}