-
Notifications
You must be signed in to change notification settings - Fork 9
170 lines (149 loc) · 4.74 KB
/
publish-node-sdk.yml
File metadata and controls
170 lines (149 loc) · 4.74 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
name: Publish Node SDK
on:
release:
types: [published]
permissions:
contents: write
id-token: write
jobs:
test-sdk:
if: "!github.event.release.prerelease"
runs-on: ubuntu-latest
defaults:
run:
working-directory: sdk/node
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- run: npm ci
- run: npm run build
- run: npm test
build-packages:
needs: test-sdk
strategy:
matrix:
include:
- os: ubuntu-latest
platform: linux
- os: macos-latest
platform: macos
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set version from release tag
shell: bash
run: |
VERSION="${{ github.event.release.tag_name }}"
VERSION="${VERSION#v}"
echo "version=$VERSION" >> $GITHUB_ENV
cd sdk/node
node -e "
const pkg = JSON.parse(require('fs').readFileSync('package.json', 'utf8'));
pkg.version = '$VERSION';
require('fs').writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
"
echo "SDK version: $VERSION"
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22
registry-url: 'https://registry.npmjs.org'
- name: Build binaries
shell: bash
run: |
cd sdk/node
chmod +x scripts/build-binaries.sh
./scripts/build-binaries.sh
- name: Install and build TypeScript
working-directory: sdk/node
run: |
npm ci
npm run build
- name: Verify package contents
working-directory: sdk/node
run: |
echo "Package contents:"
npm pack --dry-run
echo ""
echo "Binary sizes:"
ls -lh bin/
- name: Upload package artifact
uses: actions/upload-artifact@v4
with:
name: npm-package-${{ matrix.platform }}
path: sdk/node/
retention-days: 7
publish:
needs: build-packages
runs-on: ubuntu-latest
steps:
- name: Download Linux package
uses: actions/download-artifact@v4
with:
name: npm-package-linux
path: sdk/node-linux
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22
registry-url: 'https://registry.npmjs.org'
- name: Extract version
id: extract-version
run: |
VERSION=$(node -e "console.log(JSON.parse(require('fs').readFileSync('sdk/node-linux/package.json', 'utf8')).version)")
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Version: $VERSION"
- name: Check if version exists on npm
id: check-npm
run: |
VERSION=${{ steps.extract-version.outputs.version }}
if npm view pilotprotocol@$VERSION version 2>/dev/null; then
echo "exists=true" >> $GITHUB_OUTPUT
echo "Version $VERSION already exists on npm"
else
echo "exists=false" >> $GITHUB_OUTPUT
echo "Version $VERSION does not exist on npm"
fi
- name: Publish to npm
if: steps.check-npm.outputs.exists == 'false'
working-directory: sdk/node-linux
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
npm ci
npm publish --access public
- name: Skip publish - version exists
if: steps.check-npm.outputs.exists == 'true'
run: echo "Skipping publish - version already exists on npm"
- name: Create summary
run: |
echo "## Node SDK Published" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Version:** ${{ steps.extract-version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "**Install:** \`npm install pilotprotocol\`" >> $GITHUB_STEP_SUMMARY
echo "**npm:** https://www.npmjs.com/package/pilotprotocol" >> $GITHUB_STEP_SUMMARY
test-install:
needs: publish
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22
- name: Wait for npm propagation
run: sleep 60
- name: Install and verify
run: |
npm install pilotprotocol
npx pilotctl info 2>&1 | head -1 || true
node -e "import('pilotprotocol').then(m => console.log('SDK installed, exports:', Object.keys(m)))"