Skip to content

chore: align subtree sync and package release branches #8

chore: align subtree sync and package release branches

chore: align subtree sync and package release branches #8

Workflow file for this run

# Build @indexnetwork/cli on dev pushes.
# Publish to npm only on pushes to main.
# Builds native binaries for all platforms before publishing.
# Skips if the version in package.json is already on npm.
#
# Requires: GitHub repo secret INDEX_REPO_TOKEN (npm automation token).
name: Publish
on:
push:
branches:
- dev
- main
concurrency:
group: publish-${{ github.ref }}
cancel-in-progress: false
jobs:
validate:
if: github.ref_name == 'dev'
runs-on: ubuntu-latest
name: Build
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Install dependencies
run: bun install
- name: Build
run: bun run build
# ── Check version ─────────────────────────────────────────────────────
check:
if: github.ref_name == 'main'
runs-on: ubuntu-latest
name: Check if version needs publishing
outputs:
skip: ${{ steps.check.outputs.skip }}
version: ${{ steps.check.outputs.version }}
steps:
- uses: actions/checkout@v4
- name: Check if version already published
id: check
run: |
VERSION=$(node -p "require('./package.json').version")
NAME=$(node -p "require('./package.json').name")
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
if npm view "${NAME}@${VERSION}" version &>/dev/null; then
echo "skip=true" >> "$GITHUB_OUTPUT"
echo "Version ${VERSION} already published — skipping."
else
echo "skip=false" >> "$GITHUB_OUTPUT"
fi
# ── Build platform binaries ───────────────────────────────────────────
build:
needs: check
if: github.ref_name == 'main' && needs.check.outputs.skip == 'false'
strategy:
fail-fast: true
matrix:
include:
- os: ubuntu-latest
target: bun-linux-x64
npm-dir: linux-x64
binary-name: index-linux-x64
- os: ubuntu-24.04-arm
target: bun-linux-arm64
npm-dir: linux-arm64
binary-name: index-linux-arm64
- os: macos-latest
target: bun-darwin-x64
npm-dir: darwin-x64
binary-name: index-darwin-x64
- os: macos-latest
target: bun-darwin-arm64
npm-dir: darwin-arm64
binary-name: index-darwin-arm64
runs-on: ${{ matrix.os }}
name: Build ${{ matrix.npm-dir }}
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Install dependencies
run: bun install
- name: Compile binary
run: |
mkdir -p dist
bun build src/main.ts --compile --target=${{ matrix.target }} --outfile dist/${{ matrix.binary-name }}
- name: Upload binary artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.npm-dir }}
path: dist/${{ matrix.binary-name }}
retention-days: 1
# ── Publish all packages to npm ───────────────────────────────────────
publish:
needs: [check, build]
if: github.ref_name == 'main' && needs.check.outputs.skip == 'false'
runs-on: ubuntu-latest
name: Publish to npm
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- uses: actions/setup-node@v4
with:
node-version: 24
registry-url: https://registry.npmjs.org
- name: Install dependencies
run: bun install
- name: Build JS fallback bundle
run: |
mkdir -p dist
bun build src/main.ts --outdir dist --target node --format esm --entry-naming index.js
- name: Download all platform binaries
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Place binaries into platform packages
run: |
for dir in linux-x64 linux-arm64 darwin-x64 darwin-arm64; do
mkdir -p "npm/$dir/bin"
cp "artifacts/$dir/index-$dir" "npm/$dir/bin/index"
chmod +x "npm/$dir/bin/index"
done
- name: Publish platform packages
env:
NODE_AUTH_TOKEN: ${{ secrets.INDEX_REPO_TOKEN }}
run: |
VERSION="${{ needs.check.outputs.version }}"
for dir in linux-x64 linux-arm64 darwin-x64 darwin-arm64; do
jq --arg v "$VERSION" '.version = $v' "npm/$dir/package.json" > "npm/$dir/package.json.tmp" \
&& mv "npm/$dir/package.json.tmp" "npm/$dir/package.json"
echo "Publishing @indexnetwork/cli-$dir..."
npm publish --access public "./npm/$dir"
done
- name: Publish main package
env:
NODE_AUTH_TOKEN: ${{ secrets.INDEX_REPO_TOKEN }}
run: npm publish --access public