Add revision support

This commit is contained in:
Ashcon Partovi 2023-09-11 12:33:33 -07:00
parent 5254461333
commit dc4f4e07fd
5 changed files with 62 additions and 65 deletions

View file

@ -4,50 +4,22 @@ Download, install, and setup [Bun](https://bun.sh) in GitHub Actions.
## Usage ## Usage
### Latest release
```yaml ```yaml
- uses: oven-sh/setup-bun@v1 - uses: oven-sh/setup-bun@v1
with: with:
bun-version: latest bun-version: latest
``` ```
### Specific release ## Inputs
```yaml | Name | Description | Default | Examples |
- uses: oven-sh/setup-bun@v1 | ------------- | ------------------------------------------- | -------- | -------------------------- |
with: | `bun-version` | The version of Bun to download and install. | `latest` | `canary`, `1.0.0`, `<sha>` |
bun-version: "0.5.6"
```
### Canary release ## Outputs
```yaml | Name | Description | Example |
- uses: oven-sh/setup-bun@v1 | -------------- | ------------------------------------------ | ------------------------------------------------ |
with: | `cache-hit` | If the Bun executable was read from cache. | `true` |
bun-version: canary | `bun-version` | The output from `bun --version`. | `1.0.0` |
``` | `bun-revision` | The output from `bun --revision`. | `1.0.0+822a00c4d508b54f650933a73ca5f4a3af9a7983` |
### 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
```

40
dist/action.js generated vendored
View file

@ -70651,13 +70651,13 @@ var setup_default = async (options) => {
const dir = (0, import_node_path.join)((0, import_node_os.homedir)(), ".bun", "bin"); const dir = (0, import_node_path.join)((0, import_node_os.homedir)(), ".bun", "bin");
action.addPath(dir); action.addPath(dir);
const path = (0, import_node_path.join)(dir, "bun"); const path = (0, import_node_path.join)(dir, "bun");
let version3; let revision;
let cacheHit = false; let cacheHit = false;
if (cacheEnabled) { if (cacheEnabled) {
const cacheRestored = await (0, import_cache.restoreCache)([path], cacheKey); const cacheRestored = await (0, import_cache.restoreCache)([path], cacheKey);
if (cacheRestored) { if (cacheRestored) {
version3 = await verifyBun(path); revision = await verifyBun(path);
if (version3) { if (revision) {
cacheHit = true; cacheHit = true;
action.info("Using a cached version of Bun."); action.info("Using a cached version of Bun.");
} else { } else {
@ -70675,12 +70675,7 @@ var setup_default = async (options) => {
await (0, import_io.mkdirP)(dir); await (0, import_io.mkdirP)(dir);
await (0, import_io.cp)(exePath, path); await (0, import_io.cp)(exePath, path);
await (0, import_io.rmRF)(exePath); await (0, import_io.rmRF)(exePath);
version3 = await verifyBun(path); revision = 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."
);
} }
try { try {
await (0, import_promises.symlink)(path, (0, import_node_path.join)(dir, "bunx")); await (0, import_promises.symlink)(path, (0, import_node_path.join)(dir, "bunx"));
@ -70689,6 +70684,11 @@ var setup_default = async (options) => {
throw error; 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) { if (cacheEnabled) {
try { try {
await (0, import_cache.saveCache)([path], cacheKey); await (0, import_cache.saveCache)([path], cacheKey);
@ -70696,8 +70696,10 @@ var setup_default = async (options) => {
action.warning("Failed to save Bun to cache."); action.warning("Failed to save Bun to cache.");
} }
} }
const [version3] = revision.split("+");
return { return {
version: version3, version: version3,
revision,
cacheHit cacheHit
}; };
}; };
@ -70742,10 +70744,19 @@ async function extractBun(path) {
throw new Error("Could not find executable: bun"); throw new Error("Could not find executable: bun");
} }
async function verifyBun(path) { 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 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 // src/action.ts
@ -70753,13 +70764,14 @@ if (!process.env.RUNNER_TEMP) {
process.env.RUNNER_TEMP = (0, import_node_os2.tmpdir)(); process.env.RUNNER_TEMP = (0, import_node_os2.tmpdir)();
} }
setup_default({ 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 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-version", version3);
action2.setOutput("bun-revision", revision);
action2.setOutput("cache-hit", cacheHit); action2.setOutput("cache-hit", cacheHit);
}).catch((error) => { }).catch((error) => {
console.error(error);
action2.setFailed(error); action2.setFailed(error);
}); });
/*! Bundled license information: /*! Bundled license information:

View file

@ -17,7 +17,7 @@
"license": "MIT", "license": "MIT",
"author": "xHyroM", "author": "xHyroM",
"scripts": { "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", "build": "esbuild --target=node16 --outdir=dist --bundle --platform=node --format=cjs src/action.ts",
"start": "bun run build && node dist/action.js" "start": "bun run build && node dist/action.js"
}, },

View file

@ -10,8 +10,9 @@ setup({
version: action.getInput("bun-version") || undefined, version: action.getInput("bun-version") || undefined,
customUrl: action.getInput("bun-download-url") || undefined, customUrl: action.getInput("bun-download-url") || undefined,
}) })
.then(({ version, cacheHit }) => { .then(({ version, revision, cacheHit }) => {
action.setOutput("bun-version", version); action.setOutput("bun-version", version);
action.setOutput("bun-revision", revision);
action.setOutput("cache-hit", cacheHit); action.setOutput("cache-hit", cacheHit);
}) })
.catch((error) => { .catch((error) => {

View file

@ -13,6 +13,7 @@ export default async (options?: {
customUrl?: string; customUrl?: string;
}): Promise<{ }): Promise<{
version: string; version: string;
revision: string;
cacheHit: boolean; cacheHit: boolean;
}> => { }> => {
const { url, cacheKey } = getDownloadUrl(options); const { url, cacheKey } = getDownloadUrl(options);
@ -20,13 +21,13 @@ export default async (options?: {
const dir = join(homedir(), ".bun", "bin"); const dir = join(homedir(), ".bun", "bin");
action.addPath(dir); action.addPath(dir);
const path = join(dir, "bun"); const path = join(dir, "bun");
let version: string | undefined; let revision: string | undefined;
let cacheHit = false; let cacheHit = false;
if (cacheEnabled) { if (cacheEnabled) {
const cacheRestored = await restoreCache([path], cacheKey); const cacheRestored = await restoreCache([path], cacheKey);
if (cacheRestored) { if (cacheRestored) {
version = await verifyBun(path); revision = await verifyBun(path);
if (version) { if (revision) {
cacheHit = true; cacheHit = true;
action.info("Using a cached version of Bun."); action.info("Using a cached version of Bun.");
} else { } else {
@ -44,12 +45,7 @@ export default async (options?: {
await mkdirP(dir); await mkdirP(dir);
await cp(exePath, path); await cp(exePath, path);
await rmRF(exePath); await rmRF(exePath);
version = await verifyBun(path); revision = 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."
);
} }
try { try {
await symlink(path, join(dir, "bunx")); await symlink(path, join(dir, "bunx"));
@ -58,6 +54,11 @@ export default async (options?: {
throw error; 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) { if (cacheEnabled) {
try { try {
await saveCache([path], cacheKey); await saveCache([path], cacheKey);
@ -65,8 +66,10 @@ export default async (options?: {
action.warning("Failed to save Bun to cache."); action.warning("Failed to save Bun to cache.");
} }
} }
const [version] = revision.split("+");
return { return {
version, version,
revision,
cacheHit, cacheHit,
}; };
}; };
@ -126,8 +129,17 @@ async function extractBun(path: string): Promise<string> {
} }
async function verifyBun(path: string): Promise<string | undefined> { async function verifyBun(path: string): Promise<string | undefined> {
const { exitCode, stdout } = await getExecOutput(path, ["--version"], { const revision = await getExecOutput(path, ["--revision"], {
ignoreReturnCode: true, 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;
} }