Skip to content

Commit 647e125

Browse files
committed
ci: Add @graphprotocol/gnd npm wrapper package
Add a wrapper package that installs the correct platform-specific gnd binary via optionalDependencies. This enables `npm install -g @graphprotocol/gnd` and `npx @graphprotocol/gnd`. The workflow now has a publish-npm-wrapper job that runs after the platform packages are published.
1 parent 226c34f commit 647e125

3 files changed

Lines changed: 121 additions & 0 deletions

File tree

.github/workflows/gnd-binary-build.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,64 @@ jobs:
260260
}
261261
EOF
262262
263+
- name: Publish
264+
run: npm publish --provenance --access public ${{ inputs.dry_run && '--dry-run' || '' }}
265+
working-directory: pkg
266+
env:
267+
NODE_AUTH_TOKEN: ${{ secrets.GRAPHPROTOCOL_NPM_TOKEN }}
268+
269+
publish-npm-wrapper:
270+
name: Publish @graphprotocol/gnd wrapper
271+
needs: publish-npm
272+
if: startsWith(github.ref, 'refs/tags/')
273+
runs-on: ubuntu-latest
274+
permissions:
275+
id-token: write
276+
contents: read
277+
steps:
278+
- uses: actions/checkout@v6
279+
280+
- uses: actions/setup-node@v6
281+
with:
282+
node-version: 22
283+
registry-url: https://registry.npmjs.org
284+
285+
- name: Create wrapper package
286+
shell: bash
287+
run: |
288+
VERSION="${{ github.ref_name }}"
289+
VERSION="${VERSION#v}"
290+
291+
mkdir -p pkg/bin
292+
cp gnd/npm/bin/gnd.js pkg/bin/gnd.js
293+
294+
cat > pkg/package.json << EOF
295+
{
296+
"name": "@graphprotocol/gnd",
297+
"version": "${VERSION}",
298+
"description": "Graph Node Development CLI",
299+
"bin": {
300+
"gnd": "./bin/gnd.js"
301+
},
302+
"optionalDependencies": {
303+
"@graphprotocol/gnd-darwin-arm64": "${VERSION}",
304+
"@graphprotocol/gnd-darwin-x64": "${VERSION}",
305+
"@graphprotocol/gnd-linux-arm64": "${VERSION}",
306+
"@graphprotocol/gnd-linux-x64": "${VERSION}",
307+
"@graphprotocol/gnd-win32-x64": "${VERSION}"
308+
},
309+
"publishConfig": {
310+
"access": "public",
311+
"provenance": true
312+
},
313+
"license": "(Apache-2.0 OR MIT)",
314+
"repository": {
315+
"type": "git",
316+
"url": "https://github.com/graphprotocol/graph-node.git"
317+
}
318+
}
319+
EOF
320+
263321
- name: Publish
264322
run: npm publish --provenance --access public ${{ inputs.dry_run && '--dry-run' || '' }}
265323
working-directory: pkg

gnd/npm/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# gnd npm wrapper
2+
3+
This directory contains the files used to publish the `@graphprotocol/gnd`
4+
npm wrapper package. The wrapper package enables installing gnd via npm:
5+
6+
```bash
7+
npm install -g @graphprotocol/gnd
8+
npx @graphprotocol/gnd
9+
```
10+
11+
## How it works
12+
13+
The wrapper declares platform-specific packages as `optionalDependencies`.
14+
npm only installs the one matching the user's OS and architecture. The
15+
`bin/gnd.js` script resolves and executes the correct platform binary.
16+
17+
Platform packages:
18+
19+
- `@graphprotocol/gnd-linux-x64`
20+
- `@graphprotocol/gnd-linux-arm64`
21+
- `@graphprotocol/gnd-darwin-x64`
22+
- `@graphprotocol/gnd-darwin-arm64`
23+
- `@graphprotocol/gnd-win32-x64`
24+
25+
## Publishing
26+
27+
All packages are published automatically by the `Build gnd Binaries`
28+
GitHub Actions workflow (`.github/workflows/gnd-binary-build.yml`) when
29+
dispatched on a tag. Platform packages are published first, then the
30+
wrapper.

gnd/npm/bin/gnd.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env node
2+
3+
const { execFileSync } = require("child_process");
4+
const path = require("path");
5+
6+
const PLATFORMS = {
7+
"darwin-arm64": "@graphprotocol/gnd-darwin-arm64",
8+
"darwin-x64": "@graphprotocol/gnd-darwin-x64",
9+
"linux-arm64": "@graphprotocol/gnd-linux-arm64",
10+
"linux-x64": "@graphprotocol/gnd-linux-x64",
11+
"win32-x64": "@graphprotocol/gnd-win32-x64",
12+
};
13+
14+
const key = `${process.platform}-${process.arch}`;
15+
const pkg = PLATFORMS[key];
16+
if (!pkg) {
17+
console.error(`Unsupported platform: ${key}`);
18+
process.exit(1);
19+
}
20+
21+
const bin = process.platform === "win32" ? "gnd.exe" : "gnd";
22+
const binPath = path.join(
23+
require.resolve(`${pkg}/package.json`),
24+
"..",
25+
"bin",
26+
bin
27+
);
28+
29+
try {
30+
execFileSync(binPath, process.argv.slice(2), { stdio: "inherit" });
31+
} catch (e) {
32+
process.exit(e.status ?? 1);
33+
}

0 commit comments

Comments
 (0)