mirror of
https://github.com/oven-sh/setup-bun.git
synced 2025-07-18 04:28:28 +02:00
Merge remote-tracking branch 'upstream/main' into mfs-no-cache-bun
This commit is contained in:
commit
ebffcc41ce
7 changed files with 140 additions and 45 deletions
|
@ -38,7 +38,7 @@ In most cases, you shouldn't need to use the [setup-node](https://github.com/act
|
||||||
| -------------- | -------------------------------------------------- | ----------- | ------------------------------- |
|
| -------------- | -------------------------------------------------- | ----------- | ------------------------------- |
|
||||||
| `bun-version` | The version of Bun to download and install. | `latest` | `canary`, `1.0.0`, `1.0.x` |
|
| `bun-version` | The version of Bun to download and install. | `latest` | `canary`, `1.0.0`, `1.0.x` |
|
||||||
| `registry-url` | Registry URL where some private package is stored. | `undefined` | `"https://npm.pkg.github.com/"` |
|
| `registry-url` | Registry URL where some private package is stored. | `undefined` | `"https://npm.pkg.github.com/"` |
|
||||||
| `scope` | Scope for private pacakages. | `undefined` | `"@foo"`, `"@orgname"` |
|
| `scope` | Scope for private packages. | `undefined` | `"@foo"`, `"@orgname"` |
|
||||||
|
|
||||||
## Outputs
|
## Outputs
|
||||||
|
|
||||||
|
|
|
@ -26,5 +26,7 @@ outputs:
|
||||||
cache-hit:
|
cache-hit:
|
||||||
description: If the version of Bun was cached.
|
description: If the version of Bun was cached.
|
||||||
runs:
|
runs:
|
||||||
using: node20
|
using: "node20"
|
||||||
main: dist/index.js
|
main: "dist/setup/index.js"
|
||||||
|
post: "dist/cache-save/index.js"
|
||||||
|
post-if: success()
|
||||||
|
|
68
dist/cache-save/index.js
generated
vendored
Normal file
68
dist/cache-save/index.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
62
dist/index.js → dist/setup/index.js
generated
vendored
62
dist/index.js → dist/setup/index.js
generated
vendored
File diff suppressed because one or more lines are too long
|
@ -18,8 +18,8 @@
|
||||||
"author": "xHyroM",
|
"author": "xHyroM",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"format": "prettier --write src *.yml *.json *.md",
|
"format": "prettier --write src *.yml *.json *.md",
|
||||||
"build": "esbuild --target=node20 --outdir=dist --bundle --minify --platform=node --format=cjs src/index.ts",
|
"build": "esbuild --target=node20 --outfile=dist/setup/index.js --bundle --minify --platform=node --format=cjs src/index.ts && esbuild --target=node20 --outfile=dist/cache-save/index.js --bundle --minify --platform=node --format=cjs src/cache-save.ts",
|
||||||
"start": "npm run build && node dist/index.js"
|
"start": "npm run build && node dist/setup/index.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/cache": "^3.1.4",
|
"@actions/cache": "^3.1.4",
|
||||||
|
|
|
@ -8,10 +8,11 @@ import {
|
||||||
copyFileSync,
|
copyFileSync,
|
||||||
} from "node:fs";
|
} from "node:fs";
|
||||||
import { addPath, info, warning } from "@actions/core";
|
import { addPath, info, warning } from "@actions/core";
|
||||||
import { isFeatureAvailable, restoreCache, saveCache } from "@actions/cache";
|
import { isFeatureAvailable, restoreCache } from "@actions/cache";
|
||||||
import { downloadTool, extractZip } from "@actions/tool-cache";
|
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";
|
||||||
|
|
||||||
export type Input = {
|
export type Input = {
|
||||||
customUrl?: string;
|
customUrl?: string;
|
||||||
|
@ -31,6 +32,13 @@ export type Output = {
|
||||||
cacheHit: boolean;
|
cacheHit: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type CacheState = {
|
||||||
|
cacheEnabled: boolean;
|
||||||
|
cacheHit: boolean;
|
||||||
|
bunPath: string;
|
||||||
|
url: string;
|
||||||
|
};
|
||||||
|
|
||||||
export default async (options: Input): Promise<Output> => {
|
export default async (options: Input): Promise<Output> => {
|
||||||
const bunfigPath = join(process.cwd(), "bunfig.toml");
|
const bunfigPath = join(process.cwd(), "bunfig.toml");
|
||||||
writeBunfig(bunfigPath, options);
|
writeBunfig(bunfigPath, options);
|
||||||
|
@ -97,15 +105,17 @@ export default async (options: Input): Promise<Output> => {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cacheEnabled && !cacheHit) {
|
|
||||||
try {
|
|
||||||
await saveCache([bunPath], url);
|
|
||||||
} catch (error) {
|
|
||||||
warning("Failed to save Bun to cache.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const [version] = revision.split("+");
|
const [version] = revision.split("+");
|
||||||
|
|
||||||
|
const cacheState: CacheState = {
|
||||||
|
cacheEnabled,
|
||||||
|
cacheHit,
|
||||||
|
bunPath,
|
||||||
|
url,
|
||||||
|
};
|
||||||
|
|
||||||
|
saveState("cache", JSON.stringify(cacheState));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
version,
|
version,
|
||||||
revision,
|
revision,
|
||||||
|
|
15
src/cache-save.ts
Normal file
15
src/cache-save.ts
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
import { saveCache } from "@actions/cache";
|
||||||
|
import { getState, warning } from "@actions/core";
|
||||||
|
import { CacheState } from "./action";
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
const state: CacheState = JSON.parse(getState("cache"));
|
||||||
|
if (state.cacheEnabled && !state.cacheHit) {
|
||||||
|
try {
|
||||||
|
await saveCache([state.bunPath], state.url);
|
||||||
|
process.exit(0);
|
||||||
|
} catch (error) {
|
||||||
|
warning("Failed to save Bun to cache.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})();
|
Loading…
Add table
Add a link
Reference in a new issue