Skip to content

Commit ddec288

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 wrapper includes: - gnd/npm/bin/gnd.js: launcher script that resolves the platform binary - gnd/npm/README.md: package documentation - publish-npm-wrapper workflow job that runs after platform packages
1 parent 58ab4e6 commit ddec288

File tree

3 files changed

+138
-0
lines changed

3 files changed

+138
-0
lines changed

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

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,73 @@ jobs:
279279
- name: Publish
280280
run: npm publish --provenance --access public --tag ${{ steps.version.outputs.tag }} ${{ inputs.dry_run && '--dry-run' || '' }}
281281
working-directory: pkg
282+
283+
publish-npm-wrapper:
284+
name: Publish @graphprotocol/gnd wrapper
285+
needs: publish-npm
286+
if: startsWith(github.ref, 'refs/tags/')
287+
runs-on: ubuntu-latest
288+
permissions:
289+
id-token: write
290+
contents: read
291+
steps:
292+
- uses: actions/checkout@v6
293+
294+
- uses: actions/setup-node@v6
295+
with:
296+
node-version: 24
297+
298+
- name: Determine version and npm tag
299+
id: version
300+
shell: bash
301+
run: |
302+
VERSION="${{ github.ref_name }}"
303+
VERSION="${VERSION#v}"
304+
echo "version=${VERSION}" >> $GITHUB_OUTPUT
305+
if [[ "$VERSION" == *-* ]]; then
306+
PRE="${VERSION#*-}"
307+
TAG="${PRE%%.*}"
308+
echo "tag=${TAG}" >> $GITHUB_OUTPUT
309+
else
310+
echo "tag=latest" >> $GITHUB_OUTPUT
311+
fi
312+
313+
- name: Create wrapper package
314+
shell: bash
315+
run: |
316+
VERSION="${{ steps.version.outputs.version }}"
317+
318+
mkdir -p pkg/bin
319+
cp gnd/npm/bin/gnd.js pkg/bin/gnd.js
320+
cp gnd/npm/README.md pkg/README.md
321+
322+
cat > pkg/package.json << EOF
323+
{
324+
"name": "@graphprotocol/gnd",
325+
"version": "${VERSION}",
326+
"description": "Graph Node Development CLI",
327+
"bin": {
328+
"gnd": "./bin/gnd.js"
329+
},
330+
"optionalDependencies": {
331+
"@graphprotocol/gnd-darwin-arm64": "${VERSION}",
332+
"@graphprotocol/gnd-darwin-x64": "${VERSION}",
333+
"@graphprotocol/gnd-linux-arm64": "${VERSION}",
334+
"@graphprotocol/gnd-linux-x64": "${VERSION}",
335+
"@graphprotocol/gnd-win32-x64": "${VERSION}"
336+
},
337+
"publishConfig": {
338+
"access": "public",
339+
"provenance": true
340+
},
341+
"license": "(Apache-2.0 OR MIT)",
342+
"repository": {
343+
"type": "git",
344+
"url": "https://github.com/graphprotocol/graph-node.git"
345+
}
346+
}
347+
EOF
348+
349+
- name: Publish
350+
run: npm publish --provenance --access public --tag ${{ steps.version.outputs.tag }} ${{ inputs.dry_run && '--dry-run' || '' }}
351+
working-directory: pkg

gnd/npm/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# The Graph CLI
2+
3+
This package installs the CLI for developing subgraphs for [The Graph
4+
Network](https://thegraph.com/subgraphs/) It supports all aspects of
5+
[developing, testing, and deploying subgraphs](https://thegraph.com/docs/en/subgraphs/quick-start/) locally and
6+
on the network.
7+
8+
This package is a complete replacement for the older
9+
[graph-cli](https://www.npmjs.com/package/@graphprotocol/graph-cli) which
10+
will over time be migrated to be a simple wrapper for `gnd`. Older
11+
documentation will reference `graph-cli` in its instructions; running
12+
`alias graph=gnd` in the shell make it possible to follow these
13+
instructions verbatim with `gnd`.
14+
15+
Besides the tools to develop subgraphs, `gnd` also contains a version of
16+
[graph-node](https://github.com/graphprotocol/graph-node) tailored to
17+
running subgraphs locally via `gnd dev`.
18+
19+
20+
## Getting started
21+
22+
Run `npm install -g @graphprotocol/gnd` to install `gnd`.
23+
24+
After installation, you can create and run an example subgraph locally with
25+
```bash
26+
gnd init --from-example ethereum-gravatar 'My new subgraph' new-subgraph
27+
cd new-subgraph
28+
gnd codegen
29+
gnd build
30+
gnd dev --ethereum-rpc 'mainnet:<RPC URL>'
31+
```
32+
33+
If you have an existing contract for which you want to write a subgraph,
34+
have a look at `gnd help init` and the `--from-contract` option. You can
35+
also simply run `gnd init` and follow the prompts to set up your subgraph.

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)