aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Ashcon Partovi <ashcon@partovi.net> 2023-01-23 22:53:01 -0800
committerGravatar Ashcon Partovi <ashcon@partovi.net> 2023-01-23 22:53:01 -0800
commitee7fe5892c2d20690827b29977166440c147f200 (patch)
tree042440f6bcf7898638d39f248adbba7058718412
parent028b3f0aff3b2beba2b9d29324d38ec1a9373d8c (diff)
downloadbun-ee7fe5892c2d20690827b29977166440c147f200.tar.gz
bun-ee7fe5892c2d20690827b29977166440c147f200.tar.zst
bun-ee7fe5892c2d20690827b29977166440c147f200.zip
Use GITHUB_TOKEN
-rw-r--r--.github/workflows/bun-npm-release.yml47
-rwxr-xr-xpackages/bun-npm/bun.lockbbin14600 -> 14600 bytes
-rw-r--r--packages/bun-npm/scripts/npm-build.ts77
3 files changed, 93 insertions, 31 deletions
diff --git a/.github/workflows/bun-npm-release.yml b/.github/workflows/bun-npm-release.yml
new file mode 100644
index 000000000..7fde74464
--- /dev/null
+++ b/.github/workflows/bun-npm-release.yml
@@ -0,0 +1,47 @@
+name: Release bun to npm
+on:
+ release:
+ types:
+ - published
+ - edited # canary only
+ workflow_dispatch:
+ inputs:
+ tag:
+ type: string
+ description: The tag to publish, defaults to 'canary' if empty
+ default: canary
+jobs:
+ release:
+ name: Release
+ runs-on: ubuntu-latest
+ if: github.repository_owner == 'oven-sh'
+ defaults:
+ run:
+ working-directory: packages/bun-npm
+ steps:
+ - id: checkout
+ name: Checkout
+ uses: actions/checkout@v3
+ - id: setup-env
+ name: Setup Environment
+ run: |
+ TAG="${{ github.event.inputs.tag }}"
+ TAG="${TAG:-"${{ github.event.release.tag_name }}"}"
+ TAG="${TAG:-"canary"}"
+ echo "Setup tag: ${TAG}"
+ echo "TAG=${TAG}" >> ${GITHUB_ENV}
+ - id: setup-bun
+ name: Setup Bun
+ uses: oven-sh/setup-bun@v0.1.8
+ with:
+ bun-version: canary
+ github-token: ${{ secrets.GITHUB_TOKEN }}
+ - id: bun-install
+ name: Install Dependencies
+ run: bun install
+ - id: bun-run
+ name: Release
+ run: bun run npm -- publish "${{ env.TAG }}"
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
diff --git a/packages/bun-npm/bun.lockb b/packages/bun-npm/bun.lockb
index c87d1c9cf..41a60a1ec 100755
--- a/packages/bun-npm/bun.lockb
+++ b/packages/bun-npm/bun.lockb
Binary files differ
diff --git a/packages/bun-npm/scripts/npm-build.ts b/packages/bun-npm/scripts/npm-build.ts
index 5f7673642..c8fcb7d86 100644
--- a/packages/bun-npm/scripts/npm-build.ts
+++ b/packages/bun-npm/scripts/npm-build.ts
@@ -9,26 +9,40 @@ import { buildSync, formatMessagesSync } from "esbuild";
import type { Platform } from "../src/platform";
import { platforms } from "../src/platform";
-const tag = process.argv[2];
+type Release =
+ Endpoints["GET /repos/{owner}/{repo}/releases/latest"]["response"]["data"];
+
const npmPackage = "bun";
const npmOwner = "@oven";
let npmVersion: string;
-const release = await getRelease(tag);
-if (release.tag_name === "canary") {
- const { tag_name } = await getRelease();
- const sha = await getSha(tag_name);
- npmVersion = `${tag_name.replace("bun-v", "")}+canary.${sha}`;
-} else {
- npmVersion = release.tag_name.replace("bun-v", "");
+
+const [tag, action] = process.argv.slice(2);
+
+await build(tag);
+if (action === "publish") {
+ await publish();
+} else if (action === "dry-run") {
+ await publish(true);
+} else if (action) {
+ throw new Error(`Unknown action: ${action}`);
}
-await buildBasePackage();
-for (const platform of platforms) {
- await buildPackage(platform);
+async function build(version: string): Promise<void> {
+ const release = await getRelease(version);
+ if (release.tag_name === "canary") {
+ const { tag_name } = await getRelease();
+ const sha = await getSha(tag_name);
+ npmVersion = `${tag_name.replace("bun-v", "")}+canary.${sha}`;
+ } else {
+ npmVersion = release.tag_name.replace("bun-v", "");
+ }
+ await buildBasePackage();
+ for (const platform of platforms) {
+ await buildPackage(release, platform);
+ }
}
-const publish = process.argv[3] === "publish";
-const dryRun = process.argv[3] === "dry-run";
-if (publish || dryRun) {
+
+async function publish(dryRun?: boolean): Promise<void> {
const npmPackages = platforms.map(({ bin }) => `${npmOwner}/${bin}`);
npmPackages.push(npmPackage);
for (const npmPackage of npmPackages) {
@@ -73,7 +87,10 @@ async function buildBasePackage() {
done();
}
-async function buildPackage({ bin, exe, os, arch }: Platform): Promise<void> {
+async function buildPackage(
+ release: Release,
+ { bin, exe, os, arch }: Platform,
+): Promise<void> {
const npmPackage = `${npmOwner}/${bin}`;
const done = log("Building:", `${npmPackage}@${npmVersion}`);
const asset = release.assets.find(({ name }) => name === `${bin}.zip`);
@@ -133,27 +150,15 @@ async function extractFromZip(
throw new Error(`File not found: ${filename}`);
}
-async function getRelease(
- version?: string | null,
-): Promise<
- Endpoints["GET /repos/{owner}/{repo}/releases/latest"]["response"]["data"]
-> {
- const response = await fetch(
- version
- ? `https://api.github.com/repos/oven-sh/bun/releases/tags/${formatTag(
- version,
- )}`
- : `https://api.github.com/repos/oven-sh/bun/releases/latest`,
+async function getRelease(version?: string | null): Promise<Release> {
+ const response = await fetchGithub(
+ version ? `releases/tags/${formatTag(version)}` : `releases/latest`,
);
return response.json();
}
async function getSha(version: string): Promise<string> {
- const response = await fetch(
- `https://api.github.com/repos/oven-sh/bun/git/ref/tags/${formatTag(
- version,
- )}`,
- );
+ const response = await fetchGithub(`git/ref/tags/${formatTag(version)}`);
const {
object,
}: Endpoints["GET /repos/{owner}/{repo}/git/ref/{ref}"]["response"]["data"] =
@@ -161,6 +166,16 @@ async function getSha(version: string): Promise<string> {
return object.sha.substring(0, 7);
}
+async function fetchGithub(path: string) {
+ const headers = new Headers();
+ const token = process.env.GITHUB_TOKEN;
+ if (token) {
+ headers.set("Authorization", `Bearer ${token}`);
+ }
+ const url = new URL(path, "https://api.github.com/repos/oven-sh/bun/");
+ return fetch(url.toString());
+}
+
function formatTag(version: string): string {
if (version.startsWith("canary") || version.startsWith("bun-v")) {
return version;