Skip to content

Feat(cli): Add Bun-based binary release workflow #713

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .github/workflows/cli_release_binaries.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# .github/workflows/cli_build_binaries.yml
name: Build and Release CLI Binaries

on:
push:
tags:
# Match the specific tag format for the CLI package
- '@e2b/cli@[0-9]+.[0-9]+.[0-9]+'
# - '@e2b/cli@[0-9]+.[0-9]+.[0-9]+-**' # Optional: for pre-releases

permissions:
contents: write

jobs:
build:
name: Build Standalone CLI Binaries
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v4

- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
run_install: false

- name: Set up Node.js 18
uses: actions/setup-node@v4
with:
node-version: '18.x'
cache: 'pnpm'
cache-dependency-path: pnpm-lock.yaml

# required to build the binaries
- name: Set up Bun
uses: oven-sh/setup-bun@v2

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Build CLI binaries and Generate Checksums
run: pnpm run --filter @e2b/cli build:compile

- name: Test Native Binary
run: pnpm run --filter @e2b/cli test:binary

- name: Upload to Tagged Release
id: upload_tagged
if: startsWith(github.ref, 'refs/tags/@e2b/cli@')
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref_name }}
files: packages/cli/release/*
fail_on_unmatched_files: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions packages/cli/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ yarn-error.log*

# generate output
dist
release

# compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@
"scripts": {
"prepublishOnly": "pnpm build",
"build": "tsc --noEmit --skipLibCheck && tsup --minify",
"build:compile": "./scripts/build-binaries.sh",
"dev": "tsup --watch",
"test": "pnpm build && cd testground/demo-basic && ../../dist/index.js template build",
"test:binary": "./scripts/test-binary.sh",
"check-deps": "knip",
"update-deps": "ncu -u && pnpm i",
"generate-ref": "./scripts/generate_sdk_ref.sh"
Expand Down
69 changes: 69 additions & 0 deletions packages/cli/scripts/build-binaries.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env bash
set -euo pipefail

# Navigate to the package root directory (one level up from scripts)
cd "$(dirname "$0")/.."

# --- Configuration ---
ENTRY_POINT="./src/index.ts"
OUTPUT_DIR="./release"
PACKAGE_JSON="./package.json"

# --- Get Version ---
if [ ! -f "$PACKAGE_JSON" ]; then
echo "Error: package.json not found at $PACKAGE_JSON!"
exit 1
fi
VERSION=$(node -p "require('$PACKAGE_JSON').version")
if [ -z "$VERSION" ]; then
echo "Error: Could not extract version from $PACKAGE_JSON!"
exit 1
fi
echo "Building binaries for version: $VERSION"

# --- Prepare Output Directory ---
echo "Preparing output directory: $OUTPUT_DIR"
rm -rf "$OUTPUT_DIR"
mkdir -p "$OUTPUT_DIR"

# --- Define Targets ---
# Format: "<desired_os>_<desired_arch>:<bun_target>:<outfile_extension>"
TARGETS=(
"linux_x64:bun-linux-x64:"
"darwin_x64:bun-darwin-x64:"
"darwin_arm64:bun-darwin-arm64:"
"windows_x64:bun-windows-x64:.exe"
"linux_arm64:bun-linux-arm64:"
)

# --- Build Logic ---
echo "Starting Bun compilation..."
for target_info in "${TARGETS[@]}"; do
IFS=':' read -r os_arch bun_target extension <<< "$target_info"
outfile="${OUTPUT_DIR}/cli_${VERSION}_${os_arch}${extension}"

echo " Compiling for ${os_arch} -> ${outfile}"
bun build "$ENTRY_POINT" --compile --target "$bun_target" --outfile "$outfile"
if [ $? -ne 0 ]; then
echo "Error: Bun build failed for target ${bun_target}!"
exit 1
fi
done

echo "Build complete. Binaries generated."

# --- Generate Checksums ---
CHECKSUM_FILE="${OUTPUT_DIR}/cli_${VERSION}_checksums.txt"
echo "Generating checksums -> ${CHECKSUM_FILE}"
# Navigate into the output directory to generate relative paths in the checksum file
cd "$OUTPUT_DIR"
# Use sha256sum to generate checksums for all files EXCEPT the checksum file itself
# The output format matches the example (hash<space><space>filename)
sha256sum * > "$(basename "$CHECKSUM_FILE")"
# Go back to the package root
cd ..

echo "Checksums generated:"
cat "$CHECKSUM_FILE"

echo "Build script finished successfully."
78 changes: 78 additions & 0 deletions packages/cli/scripts/test-binary.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/bin/env bash
set -euo pipefail

# Navigate to the package root directory (one level up from scripts)
cd "$(dirname "$0")/.."

# --- Configuration ---
OUTPUT_DIR="./release"
PACKAGE_JSON="./package.json"

# --- Get Version ---
if [ ! -f "$PACKAGE_JSON" ]; then
echo "Error: package.json not found at $PACKAGE_JSON!"
exit 1
fi
VERSION=$(node -p "require('$PACKAGE_JSON').version")
if [ -z "$VERSION" ]; then
echo "Error: Could not extract version from $PACKAGE_JSON!"
exit 1
fi

# --- Determine Native OS and Arch ---
OS_LOWER=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH_RAW=$(uname -m)
ARCH_LOWER=""

case "$ARCH_RAW" in
x86_64) ARCH_LOWER="x64" ;;
arm64|aarch64) ARCH_LOWER="arm64" ;;
*) echo "Error: Unsupported architecture for testing: $ARCH_RAW"; exit 1 ;;
esac

# Construct OS/Arch suffix for filename (only Linux supported by this script for now)
if [ "$OS_LOWER" == "linux" ]; then
OS_ARCH_SUFFIX="linux_${ARCH_LOWER}"
EXTENSION=""
elif [ "$OS_LOWER" == "darwin" ]; then
OS_ARCH_SUFFIX="darwin_${ARCH_LOWER}"
EXTENSION=""
else
echo "Error: Script currently only supports testing on Linux or Darwin, not $OS_LOWER"
exit 1
fi

echo "Attempting to test binary for native platform: ${OS_ARCH_SUFFIX}"

# --- Find and Test Binary ---
NATIVE_BINARY="${OUTPUT_DIR}/cli_${VERSION}_${OS_ARCH_SUFFIX}${EXTENSION}"

echo "Checking if binary exists: $NATIVE_BINARY"
if [ ! -f "$NATIVE_BINARY" ]; then
echo "Error: Native binary not found at $NATIVE_BINARY!"
ls -la "$OUTPUT_DIR" # List contents for debugging
exit 1
fi

echo "Making binary executable..."
chmod +x "$NATIVE_BINARY"

echo "Running: $NATIVE_BINARY --version"
OUTPUT=$("$NATIVE_BINARY" --version)
EXIT_CODE=$?

echo "Output: $OUTPUT"
echo "Exit Code: $EXIT_CODE"

if [ $EXIT_CODE -ne 0 ]; then
echo "Error: Binary execution failed with exit code $EXIT_CODE!"
exit 1
fi

echo "Checking output for version string '$VERSION'..."
if ! echo "$OUTPUT" | grep -q "$VERSION"; then
echo "Error: Version string '$VERSION' not found in output!"
exit 1
fi

echo "Native binary test passed for ${OS_ARCH_SUFFIX}!"
14 changes: 7 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.