Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d3603274ac | ||
|
|
0f37bd8169 | ||
|
|
12944059f7 | ||
|
|
8642d99a51 | ||
|
|
40646b1808 | ||
|
|
94177e527c | ||
|
|
9b21598af8 | ||
|
|
c7420ae597 | ||
|
|
c0059f0222 |
25
.github/workflows/release.yml
vendored
Normal file
25
.github/workflows/release.yml
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
name: Release new action version
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [released]
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
TAG_NAME:
|
||||
description: 'Tag name that the major tag will point to'
|
||||
required: true
|
||||
|
||||
env:
|
||||
TAG_NAME: ${{ github.event.inputs.TAG_NAME || github.event.release.tag_name }}
|
||||
|
||||
jobs:
|
||||
update_tag:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- uses: actions/publish-action@v0.3.0
|
||||
with:
|
||||
source-tag: ${{ env.TAG_NAME }}
|
||||
15
.github/workflows/test.yml
vendored
15
.github/workflows/test.yml
vendored
@@ -52,14 +52,27 @@ jobs:
|
||||
os:
|
||||
- ubuntu-latest
|
||||
- macos-latest
|
||||
packageManager:
|
||||
- bun@1.0.0
|
||||
- yarn@bun@1.0.0
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: Setup package.json
|
||||
run: |
|
||||
echo "$(jq '. += {"packageManager": "bun@1.0.0"}' package.json)" > package.json
|
||||
echo "$(jq '. += {"packageManager": "${{ matrix.packageManager }}"}' package.json)" > package.json
|
||||
- name: Setup Bun
|
||||
uses: ./
|
||||
- name: Run Bun
|
||||
id: bun
|
||||
run: |
|
||||
bun --version
|
||||
echo "version=$(bun --version)" >> $GITHUB_OUTPUT
|
||||
- name: Check version
|
||||
run: |
|
||||
if [[ "${{ steps.bun.outputs.version }}" == "1.0.0" ]]; then
|
||||
echo "Version is 1.0.0"
|
||||
else
|
||||
echo "Expected version to be 1.0.0, got ${{ steps.bun.outputs.version }}"
|
||||
exit 1
|
||||
fi
|
||||
@@ -25,16 +25,21 @@ If you need to authenticate with a private registry, you can set the `BUN_AUTH_T
|
||||
- name: Install Dependencies
|
||||
env:
|
||||
BUN_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
run: bun install
|
||||
run: bun install --frozen-lockfile
|
||||
```
|
||||
|
||||
### Node.js not needed
|
||||
|
||||
In most cases, you shouldn't need to use the [setup-node](https://github.com/actions/setup-node) GitHub Action.
|
||||
|
||||
## Inputs
|
||||
|
||||
| Name | Description | Default | Examples |
|
||||
| -------------- | -------------------------------------------------- | ----------- | ------------------------------- |
|
||||
| `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/"` |
|
||||
| `scope` | Scope for private pacakages. | `undefined` | `"@foo"`, `"@orgname"` |
|
||||
| `scope` | Scope for private packages. | `undefined` | `"@foo"`, `"@orgname"` |
|
||||
| `no-cache` | Disable caching of the downloaded executable. | `false` | `true`, `false` |
|
||||
|
||||
## Outputs
|
||||
|
||||
|
||||
12
action.yml
12
action.yml
@@ -7,7 +7,6 @@ branding:
|
||||
inputs:
|
||||
bun-version:
|
||||
description: 'The version of Bun to install. (e.g. "latest", "canary", "1.0.0", "1.0.x", <sha>)'
|
||||
default: latest
|
||||
required: false
|
||||
registry-url:
|
||||
required: false
|
||||
@@ -15,6 +14,11 @@ inputs:
|
||||
scope:
|
||||
required: false
|
||||
description: "The scope for authenticating with the package registry."
|
||||
no-cache:
|
||||
required: false
|
||||
type: boolean
|
||||
default: false
|
||||
description: "Disable caching of bun executable."
|
||||
outputs:
|
||||
bun-version:
|
||||
description: The version of Bun that was installed.
|
||||
@@ -23,5 +27,7 @@ outputs:
|
||||
cache-hit:
|
||||
description: If the version of Bun was cached.
|
||||
runs:
|
||||
using: node20
|
||||
main: dist/index.js
|
||||
using: "node20"
|
||||
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
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "setup-bun",
|
||||
"version": "1.1.0",
|
||||
"version": "1.2.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "setup-bun",
|
||||
"version": "1.1.0",
|
||||
"version": "1.2.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/cache": "^3.1.4",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"private": true,
|
||||
"name": "setup-bun",
|
||||
"version": "1.1.0",
|
||||
"version": "1.2.0",
|
||||
"description": "Setup Bun on GitHub Actions.",
|
||||
"keywords": [
|
||||
"bun",
|
||||
@@ -18,8 +18,8 @@
|
||||
"author": "xHyroM",
|
||||
"scripts": {
|
||||
"format": "prettier --write src *.yml *.json *.md",
|
||||
"build": "esbuild --target=node20 --outdir=dist --bundle --minify --platform=node --format=cjs src/index.ts",
|
||||
"start": "npm run build && node dist/index.js"
|
||||
"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/setup/index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions/cache": "^3.1.4",
|
||||
|
||||
@@ -8,10 +8,11 @@ import {
|
||||
copyFileSync,
|
||||
} from "node:fs";
|
||||
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 { getExecOutput } from "@actions/exec";
|
||||
import { writeBunfig } from "./bunfig";
|
||||
import { saveState } from "@actions/core";
|
||||
|
||||
export type Input = {
|
||||
customUrl?: string;
|
||||
@@ -22,6 +23,7 @@ export type Input = {
|
||||
profile?: boolean;
|
||||
scope?: string;
|
||||
registryUrl?: string;
|
||||
noCache?: boolean;
|
||||
};
|
||||
|
||||
export type Output = {
|
||||
@@ -30,6 +32,13 @@ export type Output = {
|
||||
cacheHit: boolean;
|
||||
};
|
||||
|
||||
export type CacheState = {
|
||||
cacheEnabled: boolean;
|
||||
cacheHit: boolean;
|
||||
bunPath: string;
|
||||
url: string;
|
||||
};
|
||||
|
||||
export default async (options: Input): Promise<Output> => {
|
||||
const bunfigPath = join(process.cwd(), "bunfig.toml");
|
||||
writeBunfig(bunfigPath, options);
|
||||
@@ -96,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 cacheState: CacheState = {
|
||||
cacheEnabled,
|
||||
cacheHit,
|
||||
bunPath,
|
||||
url,
|
||||
};
|
||||
|
||||
saveState("cache", JSON.stringify(cacheState));
|
||||
|
||||
return {
|
||||
version,
|
||||
revision,
|
||||
@@ -113,7 +124,10 @@ export default async (options: Input): Promise<Output> => {
|
||||
};
|
||||
|
||||
function isCacheEnabled(options: Input): boolean {
|
||||
const { customUrl, version } = options;
|
||||
const { customUrl, version, noCache } = options;
|
||||
if (noCache) {
|
||||
return false;
|
||||
}
|
||||
if (customUrl) {
|
||||
return false;
|
||||
}
|
||||
|
||||
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.");
|
||||
}
|
||||
}
|
||||
})();
|
||||
11
src/index.ts
11
src/index.ts
@@ -1,7 +1,13 @@
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { existsSync, readFileSync } from "node:fs";
|
||||
import { getInput, setOutput, setFailed, warning } from "@actions/core";
|
||||
import {
|
||||
getInput,
|
||||
setOutput,
|
||||
setFailed,
|
||||
warning,
|
||||
getBooleanInput,
|
||||
} from "@actions/core";
|
||||
import runAction from "./action.js";
|
||||
|
||||
if (!process.env.RUNNER_TEMP) {
|
||||
@@ -19,7 +25,7 @@ function readVersionFromPackageJson(): string | undefined {
|
||||
return;
|
||||
}
|
||||
const { packageManager } = JSON.parse(readFileSync(path, "utf8"));
|
||||
if (!packageManager?.startsWith("bun@")) {
|
||||
if (!packageManager?.includes("bun@")) {
|
||||
return;
|
||||
}
|
||||
const [_, version] = packageManager.split("bun@");
|
||||
@@ -35,6 +41,7 @@ runAction({
|
||||
customUrl: getInput("bun-download-url") || undefined,
|
||||
registryUrl: getInput("registry-url") || undefined,
|
||||
scope: getInput("scope") || undefined,
|
||||
noCache: getBooleanInput("no-cache") || false,
|
||||
})
|
||||
.then(({ version, revision, cacheHit }) => {
|
||||
setOutput("bun-version", version);
|
||||
|
||||
Reference in New Issue
Block a user