From dc4f4e07fd26992da93532f1bed6998cde7402e7 Mon Sep 17 00:00:00 2001 From: Ashcon Partovi Date: Mon, 11 Sep 2023 12:33:33 -0700 Subject: [PATCH] Add revision support --- README.md | 48 ++++++++++-------------------------------------- dist/action.js | 40 ++++++++++++++++++++++++++-------------- package.json | 2 +- src/action.ts | 3 ++- src/setup.ts | 34 +++++++++++++++++++++++----------- 5 files changed, 62 insertions(+), 65 deletions(-) diff --git a/README.md b/README.md index 6bb6b35..0be4db2 100644 --- a/README.md +++ b/README.md @@ -4,50 +4,22 @@ Download, install, and setup [Bun](https://bun.sh) in GitHub Actions. ## Usage -### Latest release - ```yaml - uses: oven-sh/setup-bun@v1 with: bun-version: latest ``` -### Specific release +## Inputs -```yaml -- uses: oven-sh/setup-bun@v1 - with: - bun-version: "0.5.6" -``` +| Name | Description | Default | Examples | +| ------------- | ------------------------------------------- | -------- | -------------------------- | +| `bun-version` | The version of Bun to download and install. | `latest` | `canary`, `1.0.0`, `` | -### Canary release +## Outputs -```yaml -- uses: oven-sh/setup-bun@v1 - with: - bun-version: canary -``` - -### Specific canary release - -```yaml -- uses: oven-sh/setup-bun@v1 - with: - bun-version: 9be68ac2350b965037f408ce4d47c3b9d9a76b63 -``` - -### Action run - -```yaml -- uses: oven-sh/setup-bun@v1 - with: - bun-version: "action:4308768069" -``` - -### Custom download URL - -```yaml -- uses: oven-sh/setup-bun@v1 - with: - bun-download-url: https://example.com/path/to/bun.zip -``` +| Name | Description | Example | +| -------------- | ------------------------------------------ | ------------------------------------------------ | +| `cache-hit` | If the Bun executable was read from cache. | `true` | +| `bun-version` | The output from `bun --version`. | `1.0.0` | +| `bun-revision` | The output from `bun --revision`. | `1.0.0+822a00c4d508b54f650933a73ca5f4a3af9a7983` | diff --git a/dist/action.js b/dist/action.js index c63e172..53c1876 100644 --- a/dist/action.js +++ b/dist/action.js @@ -70651,13 +70651,13 @@ var setup_default = async (options) => { const dir = (0, import_node_path.join)((0, import_node_os.homedir)(), ".bun", "bin"); action.addPath(dir); const path = (0, import_node_path.join)(dir, "bun"); - let version3; + let revision; let cacheHit = false; if (cacheEnabled) { const cacheRestored = await (0, import_cache.restoreCache)([path], cacheKey); if (cacheRestored) { - version3 = await verifyBun(path); - if (version3) { + revision = await verifyBun(path); + if (revision) { cacheHit = true; action.info("Using a cached version of Bun."); } else { @@ -70675,12 +70675,7 @@ var setup_default = async (options) => { await (0, import_io.mkdirP)(dir); await (0, import_io.cp)(exePath, path); await (0, import_io.rmRF)(exePath); - version3 = await verifyBun(path); - } - if (!version3) { - throw new Error( - "Downloaded a new version of Bun, but failed to check its version? Try again in debug mode." - ); + revision = await verifyBun(path); } try { await (0, import_promises.symlink)(path, (0, import_node_path.join)(dir, "bunx")); @@ -70689,6 +70684,11 @@ var setup_default = async (options) => { throw error; } } + if (!revision) { + throw new Error( + "Downloaded a new version of Bun, but failed to check its version? Try again in debug mode." + ); + } if (cacheEnabled) { try { await (0, import_cache.saveCache)([path], cacheKey); @@ -70696,8 +70696,10 @@ var setup_default = async (options) => { action.warning("Failed to save Bun to cache."); } } + const [version3] = revision.split("+"); return { version: version3, + revision, cacheHit }; }; @@ -70742,10 +70744,19 @@ async function extractBun(path) { throw new Error("Could not find executable: bun"); } async function verifyBun(path) { - const { exitCode, stdout } = await (0, import_exec.getExecOutput)(path, ["--version"], { + const revision = await (0, import_exec.getExecOutput)(path, ["--revision"], { ignoreReturnCode: true }); - return exitCode === 0 ? stdout.trim() : void 0; + if (revision.exitCode === 0 && /^\d+\.\d+\.\d+/.test(revision.stdout)) { + return revision.stdout.trim(); + } + const version3 = await (0, import_exec.getExecOutput)(path, ["--version"], { + ignoreReturnCode: true + }); + if (version3.exitCode === 0 && /^\d+\.\d+\.\d+/.test(version3.stdout)) { + return version3.stdout.trim(); + } + return void 0; } // src/action.ts @@ -70753,13 +70764,14 @@ if (!process.env.RUNNER_TEMP) { process.env.RUNNER_TEMP = (0, import_node_os2.tmpdir)(); } setup_default({ - version: action2.getInput("bun-version") || void 0, + version: "0.5.6", + ///action.getInput("bun-version") || undefined, customUrl: action2.getInput("bun-download-url") || void 0 -}).then(({ version: version3, cacheHit }) => { +}).then(({ version: version3, revision, cacheHit }) => { action2.setOutput("bun-version", version3); + action2.setOutput("bun-revision", revision); action2.setOutput("cache-hit", cacheHit); }).catch((error) => { - console.error(error); action2.setFailed(error); }); /*! Bundled license information: diff --git a/package.json b/package.json index ac4bf66..d10f51a 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "license": "MIT", "author": "xHyroM", "scripts": { - "format": "prettier --write src", + "format": "prettier --write src *.yml *.json *.md", "build": "esbuild --target=node16 --outdir=dist --bundle --platform=node --format=cjs src/action.ts", "start": "bun run build && node dist/action.js" }, diff --git a/src/action.ts b/src/action.ts index 8164cc9..d0358b2 100644 --- a/src/action.ts +++ b/src/action.ts @@ -10,8 +10,9 @@ setup({ version: action.getInput("bun-version") || undefined, customUrl: action.getInput("bun-download-url") || undefined, }) - .then(({ version, cacheHit }) => { + .then(({ version, revision, cacheHit }) => { action.setOutput("bun-version", version); + action.setOutput("bun-revision", revision); action.setOutput("cache-hit", cacheHit); }) .catch((error) => { diff --git a/src/setup.ts b/src/setup.ts index 087f8f9..569ca56 100644 --- a/src/setup.ts +++ b/src/setup.ts @@ -13,6 +13,7 @@ export default async (options?: { customUrl?: string; }): Promise<{ version: string; + revision: string; cacheHit: boolean; }> => { const { url, cacheKey } = getDownloadUrl(options); @@ -20,13 +21,13 @@ export default async (options?: { const dir = join(homedir(), ".bun", "bin"); action.addPath(dir); const path = join(dir, "bun"); - let version: string | undefined; + let revision: string | undefined; let cacheHit = false; if (cacheEnabled) { const cacheRestored = await restoreCache([path], cacheKey); if (cacheRestored) { - version = await verifyBun(path); - if (version) { + revision = await verifyBun(path); + if (revision) { cacheHit = true; action.info("Using a cached version of Bun."); } else { @@ -44,12 +45,7 @@ export default async (options?: { await mkdirP(dir); await cp(exePath, path); await rmRF(exePath); - version = await verifyBun(path); - } - if (!version) { - throw new Error( - "Downloaded a new version of Bun, but failed to check its version? Try again in debug mode." - ); + revision = await verifyBun(path); } try { await symlink(path, join(dir, "bunx")); @@ -58,6 +54,11 @@ export default async (options?: { throw error; } } + if (!revision) { + throw new Error( + "Downloaded a new version of Bun, but failed to check its version? Try again in debug mode." + ); + } if (cacheEnabled) { try { await saveCache([path], cacheKey); @@ -65,8 +66,10 @@ export default async (options?: { action.warning("Failed to save Bun to cache."); } } + const [version] = revision.split("+"); return { version, + revision, cacheHit, }; }; @@ -126,8 +129,17 @@ async function extractBun(path: string): Promise { } async function verifyBun(path: string): Promise { - const { exitCode, stdout } = await getExecOutput(path, ["--version"], { + const revision = await getExecOutput(path, ["--revision"], { ignoreReturnCode: true, }); - return exitCode === 0 ? stdout.trim() : undefined; + if (revision.exitCode === 0 && /^\d+\.\d+\.\d+/.test(revision.stdout)) { + return revision.stdout.trim(); + } + const version = await getExecOutput(path, ["--version"], { + ignoreReturnCode: true, + }); + if (version.exitCode === 0 && /^\d+\.\d+\.\d+/.test(version.stdout)) { + return version.stdout.trim(); + } + return undefined; }