-
Notifications
You must be signed in to change notification settings - Fork 1
249 lines (224 loc) · 9.01 KB
/
Copy pathpublish.yml
File metadata and controls
249 lines (224 loc) · 9.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
name: publish
# PILOT-203 / release fan-out: npm publish workflow.
#
# Triggers on:
# - workflow_dispatch with a `version` input — the canonical path. web4's
# release pipeline dispatches this at the daemon tag (e.g. 1.12.3) so the
# SDK publishes version-locked to the daemon, NOT to whatever stale
# version sits in package.json.
# - release published (legacy path for manual GitHub releases in this repo).
#
# The published package BUNDLES the native runtime under bin/<os>-<arch>/
# (pilot-daemon, pilotctl, pilot-gateway, pilot-updater, libpilot.{so,dylib}),
# which src/ffi.ts resolves at load time. The binaries are built from source:
# libpilot (the CGO shared lib) lives in pilot-protocol/libpilot and builds
# against a set of sibling Go modules — the same checkout set libpilot CI uses.
# Each platform job uploads its bin/<os>-<arch>/ subtree; the publish job
# merges all platforms into one multi-platform package and publishes once.
#
# Required secret:
# NPM_TOKEN — npmjs.org automation token with publish rights on the
# pilotprotocol package.
on:
workflow_dispatch:
inputs:
version:
description: 'Version to publish (with or without leading v, e.g. 1.12.3)'
required: true
type: string
release:
types: [published]
permissions:
contents: read
env:
PILOT_VERSION_RAW: ${{ inputs.version || github.event.release.tag_name }}
jobs:
# Normalize the version once. `version` is bare (X.Y.Z) for package
# metadata; `ref` is the web4 git tag (always vX.Y.Z) for source checkout.
prep:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.v.outputs.version }}
ref: ${{ steps.v.outputs.ref }}
steps:
- id: v
shell: bash
run: |
RAW="${PILOT_VERSION_RAW}"
if [ -z "$RAW" ]; then
echo "::error::no version supplied (inputs.version / release tag both empty)"
exit 1
fi
BARE="${RAW#v}"
echo "version=$BARE" >> "$GITHUB_OUTPUT"
echo "ref=v$BARE" >> "$GITHUB_OUTPUT"
echo "version=$BARE ref=v$BARE"
build-binaries:
needs: prep
name: Build binaries (${{ matrix.platform }}/${{ matrix.goarch }})
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
platform: linux
goarch: amd64
subdir: linux-amd64
- os: macos-latest
platform: darwin
goarch: arm64
subdir: darwin-arm64
runs-on: ${{ matrix.os }}
steps:
- name: Checkout sdk-node
uses: actions/checkout@v4
with:
path: sdk-node
- name: Checkout libpilot
uses: actions/checkout@v4
with: { repository: pilot-protocol/libpilot, path: libpilot }
- name: Checkout web4
uses: actions/checkout@v4
with: { repository: pilot-protocol/pilotprotocol, path: web4, ref: "${{ needs.prep.outputs.ref }}" }
- name: Checkout common
uses: actions/checkout@v4
with: { repository: pilot-protocol/common, path: common }
- name: Checkout trustedagents
uses: actions/checkout@v4
with: { repository: pilot-protocol/trustedagents, path: trustedagents }
- name: Checkout handshake
uses: actions/checkout@v4
with: { repository: pilot-protocol/handshake, path: handshake }
- name: Checkout policy
uses: actions/checkout@v4
with: { repository: pilot-protocol/policy, path: policy }
- name: Checkout runtime
uses: actions/checkout@v4
with: { repository: pilot-protocol/runtime, path: runtime }
- name: Checkout skillinject
uses: actions/checkout@v4
with: { repository: pilot-protocol/skillinject, path: skillinject }
- name: Checkout webhook
uses: actions/checkout@v4
with: { repository: pilot-protocol/webhook, path: webhook }
- name: Checkout eventstream
uses: actions/checkout@v4
with: { repository: pilot-protocol/eventstream, path: eventstream }
- name: Checkout dataexchange
uses: actions/checkout@v4
with: { repository: pilot-protocol/dataexchange, path: dataexchange }
- name: Checkout updater
uses: actions/checkout@v4
with: { repository: pilot-protocol/updater, path: updater }
- name: Checkout gateway
uses: actions/checkout@v4
with: { repository: pilot-protocol/gateway, path: gateway }
- name: Checkout nameserver
uses: actions/checkout@v4
with: { repository: pilot-protocol/nameserver, path: nameserver }
- name: Checkout rendezvous
uses: actions/checkout@v4
with: { repository: pilot-protocol/rendezvous, path: rendezvous }
- name: Checkout beacon
uses: actions/checkout@v4
with: { repository: pilot-protocol/beacon, path: beacon }
- name: Checkout app-store
uses: actions/checkout@v4
with: { repository: pilot-protocol/app-store, path: app-store }
- uses: actions/setup-go@v5
with:
go-version-file: web4/go.mod
- name: Build native binaries
shell: bash
run: |
set -euo pipefail
( cd libpilot && go mod tidy )
OS=${{ matrix.platform }}
case "$OS" in
linux) EXT=so ;;
darwin) EXT=dylib ;;
*) echo "::error::unsupported os $OS"; exit 1 ;;
esac
OUT="$GITHUB_WORKSPACE/sdk-node/bin/${{ matrix.subdir }}"
mkdir -p "$OUT"
LDFLAGS="-s -w -X main.version=${{ needs.prep.outputs.version }}"
( cd web4 && CGO_ENABLED=0 go build -ldflags "$LDFLAGS" -o "$OUT/pilot-daemon" ./cmd/daemon )
( cd web4 && CGO_ENABLED=0 go build -ldflags "$LDFLAGS" -o "$OUT/pilotctl" ./cmd/pilotctl )
( cd web4 && CGO_ENABLED=0 go build -ldflags "$LDFLAGS" -o "$OUT/pilot-updater" ./cmd/updater )
( cd gateway && go mod tidy && CGO_ENABLED=0 go build -ldflags "$LDFLAGS" -o "$OUT/pilot-gateway" ./cmd/gateway ) \
|| ( cd gateway && CGO_ENABLED=0 go build -ldflags "$LDFLAGS" -o "$OUT/pilot-gateway" . )
( cd libpilot && CGO_ENABLED=1 go build -buildmode=c-shared -ldflags "-s -w" -o "$OUT/libpilot.$EXT" . )
if [ "$OS" = "darwin" ]; then
for b in "$OUT"/*; do codesign --force --deep --sign - "$b" || true; xattr -cr "$b" || true; done
fi
ls -lh "$OUT"
- name: Write .pilot-version marker (Linux only)
if: matrix.platform == 'linux'
run: echo "${{ needs.prep.outputs.version }}" > "$GITHUB_WORKSPACE/sdk-node/bin/.pilot-version"
- name: Upload bin subtree
uses: actions/upload-artifact@v4
with:
name: node-bin-${{ matrix.subdir }}
path: sdk-node/bin/
retention-days: 7
publish:
name: Publish to npm
needs: [prep, build-binaries]
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write # npm provenance
steps:
- name: Checkout sdk-node
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '22'
registry-url: 'https://registry.npmjs.org'
- name: Download all bin subtrees
uses: actions/download-artifact@v4
with:
path: bin-artifacts
- name: Merge platform binaries into bin/
run: |
set -euo pipefail
mkdir -p bin
# Each artifact dir contains a bin/ subtree; merge them all.
for art in bin-artifacts/node-bin-*; do
cp -R "$art"/* bin/
done
echo "Merged bin/ layout:"
find bin -maxdepth 2 | sort
- name: Pin package.json version
run: |
VERSION="${{ needs.prep.outputs.version }}"
node -e "const fs=require('fs');const p=JSON.parse(fs.readFileSync('package.json','utf8'));p.version='$VERSION';fs.writeFileSync('package.json',JSON.stringify(p,null,2)+'\n');"
echo "package.json version -> $VERSION"
- name: Build TypeScript
run: |
npm ci
npm run build
- name: Check if version exists on npm
id: check
run: |
if npm view pilotprotocol@${{ needs.prep.outputs.version }} version >/dev/null 2>&1; then
echo "exists=true" >> "$GITHUB_OUTPUT"
echo "::notice::pilotprotocol ${{ needs.prep.outputs.version }} already on npm — skipping publish"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Verify package contents
run: npm pack --dry-run
- name: Publish to npm
if: steps.check.outputs.exists == 'false'
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npm publish --provenance --access public
- name: Summary
run: |
{
echo "## Node SDK"
echo "- Version: \`${{ needs.prep.outputs.version }}\`"
echo "- Already present: \`${{ steps.check.outputs.exists }}\`"
echo "- Install: \`npm install pilotprotocol\`"
} >> "$GITHUB_STEP_SUMMARY"