Skip to content

Commit ec1fe69

Browse files
committed
chore: move CLI publish workflow into packages/cli, remove from monorepo
1 parent 8364625 commit ec1fe69

1 file changed

Lines changed: 107 additions & 17 deletions

File tree

.github/workflows/publish.yml

Lines changed: 107 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Publish @indexnetwork/cli to npm on every push to main.
2-
# Reads version from package.json — skips silently if already published.
2+
# Builds native binaries for all platforms, then publishes.
3+
# Skips if the version in package.json is already on npm.
34
#
45
# Requires: GitHub repo secret INDEX_REPO_TOKEN (npm automation token).
56
name: Publish
@@ -14,9 +15,84 @@ concurrency:
1415
cancel-in-progress: false
1516

1617
jobs:
18+
# ── Check version ─────────────────────────────────────────────────────
19+
check:
20+
runs-on: ubuntu-latest
21+
name: Check if version needs publishing
22+
outputs:
23+
skip: ${{ steps.check.outputs.skip }}
24+
version: ${{ steps.check.outputs.version }}
25+
steps:
26+
- uses: actions/checkout@v4
27+
- name: Check if version already published
28+
id: check
29+
run: |
30+
VERSION=$(node -p "require('./package.json').version")
31+
NAME=$(node -p "require('./package.json').name")
32+
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
33+
if npm view "${NAME}@${VERSION}" version &>/dev/null; then
34+
echo "skip=true" >> "$GITHUB_OUTPUT"
35+
echo "Version ${VERSION} already published — skipping."
36+
else
37+
echo "skip=false" >> "$GITHUB_OUTPUT"
38+
fi
39+
40+
# ── Build platform binaries ───────────────────────────────────────────
41+
build:
42+
needs: check
43+
if: needs.check.outputs.skip == 'false'
44+
strategy:
45+
fail-fast: true
46+
matrix:
47+
include:
48+
- os: ubuntu-latest
49+
target: bun-linux-x64
50+
npm-dir: linux-x64
51+
binary-name: index-linux-x64
52+
- os: ubuntu-24.04-arm
53+
target: bun-linux-arm64
54+
npm-dir: linux-arm64
55+
binary-name: index-linux-arm64
56+
- os: macos-latest
57+
target: bun-darwin-x64
58+
npm-dir: darwin-x64
59+
binary-name: index-darwin-x64
60+
- os: macos-latest
61+
target: bun-darwin-arm64
62+
npm-dir: darwin-arm64
63+
binary-name: index-darwin-arm64
64+
65+
runs-on: ${{ matrix.os }}
66+
name: Build ${{ matrix.npm-dir }}
67+
68+
steps:
69+
- uses: actions/checkout@v4
70+
71+
- uses: oven-sh/setup-bun@v2
72+
with:
73+
bun-version: latest
74+
75+
- name: Install dependencies
76+
run: bun install --frozen-lockfile
77+
78+
- name: Compile binary
79+
run: |
80+
mkdir -p dist
81+
bun build src/main.ts --compile --target=${{ matrix.target }} --outfile dist/${{ matrix.binary-name }}
82+
83+
- name: Upload binary artifact
84+
uses: actions/upload-artifact@v4
85+
with:
86+
name: ${{ matrix.npm-dir }}
87+
path: dist/${{ matrix.binary-name }}
88+
retention-days: 1
89+
90+
# ── Publish all packages to npm ───────────────────────────────────────
1791
publish:
92+
needs: [check, build]
93+
if: needs.check.outputs.skip == 'false'
1894
runs-on: ubuntu-latest
19-
name: Build and publish to npm
95+
name: Publish to npm
2096

2197
steps:
2298
- uses: actions/checkout@v4
@@ -33,23 +109,37 @@ jobs:
33109
- name: Install dependencies
34110
run: bun install --frozen-lockfile
35111

36-
- name: Build
37-
run: bun run build
112+
- name: Build JS fallback bundle
113+
run: |
114+
mkdir -p dist
115+
bun build src/main.ts --outdir dist --target node --format esm --entry-naming index.js
38116
39-
- name: Check if version already published
40-
id: check
117+
- name: Download all platform binaries
118+
uses: actions/download-artifact@v4
119+
with:
120+
path: artifacts
121+
122+
- name: Place binaries into platform packages
41123
run: |
42-
VERSION=$(node -p "require('./package.json').version")
43-
NAME=$(node -p "require('./package.json').name")
44-
if npm view "${NAME}@${VERSION}" version &>/dev/null; then
45-
echo "skip=true" >> "$GITHUB_OUTPUT"
46-
echo "Version ${VERSION} already published — skipping."
47-
else
48-
echo "skip=false" >> "$GITHUB_OUTPUT"
49-
fi
124+
for dir in linux-x64 linux-arm64 darwin-x64 darwin-arm64; do
125+
mkdir -p "npm/$dir/bin"
126+
cp "artifacts/$dir/index-$dir" "npm/$dir/bin/index"
127+
chmod +x "npm/$dir/bin/index"
128+
done
50129
51-
- name: Publish
52-
if: steps.check.outputs.skip == 'false'
53-
run: npm publish --access public
130+
- name: Publish platform packages
131+
env:
132+
NODE_AUTH_TOKEN: ${{ secrets.INDEX_REPO_TOKEN }}
133+
run: |
134+
VERSION="${{ needs.check.outputs.version }}"
135+
for dir in linux-x64 linux-arm64 darwin-x64 darwin-arm64; do
136+
jq --arg v "$VERSION" '.version = $v' "npm/$dir/package.json" > "npm/$dir/package.json.tmp" \
137+
&& mv "npm/$dir/package.json.tmp" "npm/$dir/package.json"
138+
echo "Publishing @indexnetwork/cli-$dir..."
139+
npm publish --access public "./npm/$dir"
140+
done
141+
142+
- name: Publish main package
54143
env:
55144
NODE_AUTH_TOKEN: ${{ secrets.INDEX_REPO_TOKEN }}
145+
run: npm publish --access public

0 commit comments

Comments
 (0)