Skip to content

Commit 17b90d7

Browse files
authored
Bundle CLI as binary (#1257)
* update lockfile * ignore tmp * oclif pack * cli ci * install.sh * bump pnpm * patch oclif * upload artifact * ci adjustments * steps * rename tarballs * test * use bin run * use bin run in scripts * also bin run in cli tests * basename for renaming log * no cli in pr ci * changeset
1 parent e44c3f8 commit 17b90d7

File tree

15 files changed

+279
-33
lines changed

15 files changed

+279
-33
lines changed

.changeset/calm-pillows-shop.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphprotocol/graph-cli': minor
3+
---
4+
5+
Bundle CLI as binary

.github/workflows/release.yml

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,38 @@ permissions: write-all
88

99
jobs:
1010
stable:
11-
uses: the-guild-org/shared-config/.github/workflows/release-stable.yml@main
12-
with:
13-
releaseScript: release
14-
nodeVersion: 16
15-
packageManager: pnpm
16-
secrets:
17-
githubToken: ${{ secrets.GITHUB_TOKEN }}
18-
npmToken: ${{ secrets.NPM_TOKEN }}
11+
name: Stable
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v3
16+
with:
17+
fetch-depth: 0
18+
token: ${{ secrets.GITHUB_TOKEN }}
19+
- name: Setup environment
20+
uses: the-guild-org/shared-config/setup@main
21+
with:
22+
nodeVersion: 16
23+
packageManager: pnpm
24+
- name: Set variables
25+
id: vars
26+
run: |
27+
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
28+
echo "date=$(date +"%B %d, %Y")" >> $GITHUB_OUTPUT
29+
- name: Build
30+
run: pnpm --filter=@graphprotocol/graph-cli build
31+
- name: Pack binaries
32+
run: pnpm --filter=@graphprotocol/graph-cli oclif:pack
33+
- name: Release / pull_request
34+
uses: dotansimha/[email protected]
35+
with:
36+
publish: pnpm release
37+
version: pnpm changeset version
38+
commit: 'chore(release): update monorepo packages versions'
39+
title: Upcoming Release Changes
40+
createGithubReleases: true
41+
githubReleaseName: ${{ steps.vars.outputs.date }}
42+
githubReleaseAssets: packages/cli/dist/*.tar.gz
43+
env:
44+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
45+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,6 @@ dist
7676

7777
# Oclif manifest
7878
oclif.manifest.json
79+
80+
# Oclif pack
81+
tmp

examples/basic-event-handlers/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
"version": "0.1.0",
44
"private": true,
55
"scripts": {
6-
"build": "../../packages/cli/dist/bin.js build",
7-
"codegen": "../../packages/cli/dist/bin.js codegen",
8-
"create-test": "../../packages/cli/dist/bin.js create test/basic-event-handlers --node http://127.0.0.1:18020",
9-
"deploy-test": "../../packages/cli/dist/bin.js deploy test/basic-event-handlers --version-label v0.0.1 --ipfs http://localhost:15001 --node http://127.0.0.1:18020",
6+
"build": "../../packages/cli/bin/run build",
7+
"codegen": "../../packages/cli/bin/run codegen",
8+
"create-test": "../../packages/cli/bin/run create test/basic-event-handlers --node http://127.0.0.1:18020",
9+
"deploy-test": "../../packages/cli/bin/run deploy test/basic-event-handlers --version-label v0.0.1 --ipfs http://localhost:15001 --node http://127.0.0.1:18020",
1010
"test": "docker compose up -d && sleep 30 && truffle test --network test && docker compose down"
1111
},
1212
"dependencies": {

examples/example-subgraph/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
"name": "example-event-handler",
33
"private": true,
44
"scripts": {
5-
"build": "../../packages/cli/dist/bin.js build subgraph.yaml",
6-
"build-ipfs": "../../packages/cli/dist/bin.js build --ipfs /ip4/127.0.0.1/tcp/5001 subgraph.yaml",
7-
"build-wast": "../../packages/cli/dist/bin.js build -t wast subgraph.yaml",
8-
"codegen": "../../packages/cli/dist/bin.js codegen --output-dir src/types/ subgraph.yaml"
5+
"build": "../../packages/cli/bin/run build subgraph.yaml",
6+
"build-ipfs": "../../packages/cli/bin/run build --ipfs /ip4/127.0.0.1/tcp/5001 subgraph.yaml",
7+
"build-wast": "../../packages/cli/bin/run build -t wast subgraph.yaml",
8+
"codegen": "../../packages/cli/bin/run codegen --output-dir src/types/ subgraph.yaml"
99
},
1010
"devDependencies": {
1111
"@graphprotocol/graph-ts": "workspace:*"

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,10 @@
3636
"eslint": "^8.31.0",
3737
"jest": "29.5.0",
3838
"prettier": "^2.8.2"
39+
},
40+
"pnpm": {
41+
"patchedDependencies": {
42+
43+
}
3944
}
4045
}

packages/cli/bin/run

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env node
2+
3+
require('@oclif/core')
4+
.run()
5+
.then(require('@oclif/core/flush'))
6+
.catch(require('@oclif/core/handle'));

packages/cli/bin/run.cmd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@echo off
2+
3+
node "%~dp0\run" %*

packages/cli/install.sh

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/bin/bash
2+
{
3+
set -e
4+
SUDO=''
5+
if [ "$(id -u)" != "0" ]; then
6+
SUDO='sudo'
7+
echo "This script requires superuser access."
8+
echo "You will be prompted for your password by sudo."
9+
# clear any previous sudo permission
10+
sudo -k
11+
fi
12+
13+
# run inside sudo
14+
$SUDO bash << SCRIPT
15+
set -e
16+
17+
OS=""
18+
ARCH=""
19+
OS_ARCH=""
20+
21+
echoerr() { echo "\$@" 1>&2; }
22+
23+
unsupported_arch() {
24+
local os=$1
25+
local arch=$2
26+
echoerr "The Graph CLI does not support $os / $arch at this time."
27+
exit 1
28+
}
29+
30+
set_os_arch() {
31+
if [ "\$(uname)" == "Darwin" ]; then
32+
OS=darwin
33+
elif [ "\$(expr substr \$(uname -s) 1 5)" == "Linux" ]; then
34+
OS=linux
35+
else
36+
OS=win32
37+
fi
38+
39+
ARCH="\$(uname -m)"
40+
if [ "\$ARCH" == "x86_64" ]; then
41+
ARCH=x64
42+
elif [ "\$ARCH" == "amd64" ]; then
43+
ARCH=x64
44+
elif [ "\$ARCH" == "arm64" ]; then
45+
if [ "\$OS" == "darwin" ]; then
46+
ARCH=arm64
47+
else
48+
ARCH=arm
49+
fi
50+
elif [[ "\$ARCH" == aarch* ]]; then
51+
ARCH=arm
52+
else
53+
unsupported_arch $OS $ARCH
54+
fi
55+
}
56+
57+
download() {
58+
DOWNLOAD_DIR=$(mktemp -d)
59+
60+
TARGET="\$OS-\$ARCH"
61+
URL="https://example.com/graph-\$TARGET.tar.gz"
62+
echo "Downloading \$URL"
63+
64+
if ! curl --progress-bar --fail -L "\$URL" -o "\$DOWNLOAD_DIR/graph.tar.gz"; then
65+
echo "Download failed."
66+
exit 1
67+
fi
68+
69+
echo "Downloaded to \$DOWNLOAD_DIR"
70+
71+
rm -rf "/usr/local/lib/graph"
72+
tar xzf "\$DOWNLOAD_DIR/graph.tar.gz" -C /usr/local/lib
73+
rm -rf "\$DOWNLOAD_DIR"
74+
echo "Unpacked to /usr/local/lib/graph"
75+
76+
echo "Installing to /usr/local/bin/graph"
77+
rm -f /usr/local/bin/graph
78+
ln -s /usr/local/lib/graph/bin/graph /usr/local/bin/graph
79+
}
80+
81+
set_os_arch
82+
download
83+
84+
SCRIPT
85+
LOCATION=$(command -v graph)
86+
echo "The Graph CLI installed to $LOCATION"
87+
graph --version
88+
}

packages/cli/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@
77
"node": ">=14"
88
},
99
"bin": {
10-
"graph": "dist/bin.js"
10+
"graph": "bin/run"
1111
},
1212
"main": "dist/index.js",
1313
"files": [
1414
"CHANGELOG.md",
15+
"bin",
1516
"dist",
1617
"oclif.manifest.json",
1718
"README.md"
1819
],
1920
"scripts": {
20-
"build": "tsc -b tsconfig.build.json && oclif manifest && copyfiles -u 1 src/**/*.graphql dist/ && chmod +x ./dist/bin.js",
21+
"build": "tsc -b tsconfig.build.json && oclif manifest && oclif readme && copyfiles -u 1 src/**/*.graphql dist/",
22+
"oclif:pack": "npm pack && pnpm oclif pack tarballs --no-xz && node scripts/rename-tarballs.mjs",
2123
"test": "jest --verbose",
2224
"test:add": "jest tests/cli/add.test.ts --verbose",
2325
"test:init": "jest tests/cli/init.test.ts --verbose",

0 commit comments

Comments
 (0)