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
### 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`, `<sha>` |
### 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` |

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");
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:

View file

@ -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"
},

View file

@ -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) => {

View file

@ -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<string> {
}
async function verifyBun(path: string): Promise<string | undefined> {
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;
}