Skip to content

Commit 6505439

Browse files
Le-CaignecgfournierProzguesmi
authored
ci: add deploy workflow for TheGraph Network (#471)
* feat: add deploy workflow for TheGraph Network * feat: add build-and-test job to subgraph deployment workflows * fix: update node-version input to be optional with default value * feat: enhance subgraph deployment workflow with version label and slug inputs * fix: remove push trigger from deploy workflow and add arbitrum-one network configuration * fix: correct version label input key in deploy workflow * fix: adjust working-directory for build step in subgraph CI workflow * feat: add deploy key and network name to subgraph deployment configuration * fix: correct input key for version label in deploy workflow * feat: add code generation step to subgraph deployment workflows * feat: add deployment success message and next steps to subgraph workflow * fix: remove unnecessary whitespace in deploy subgraph workflow * fix: reorder deploy-chainX script in package.json for consistency * fix: update build script to ensure code generation runs before building * fix: remove hardcoded addresses and start blocks from data sources in subgraph template * Update .github/workflows/deploy-subgraph-chainX.yml Co-authored-by: gfournieriExec <[email protected]> * feat: Add deploy workflow for Subgraph on TheGraph Network --------- Co-authored-by: gfournieriExec <[email protected]> Co-authored-by: Zied <[email protected]>
1 parent 74870fe commit 6505439

File tree

8 files changed

+200
-36
lines changed

8 files changed

+200
-36
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Deploy Subgraph - on TheGraph Network
2+
3+
on:
4+
workflow_dispatch: # Manual trigger
5+
inputs:
6+
network:
7+
description: 'Network'
8+
required: true
9+
type: choice
10+
options:
11+
- arbitrumSepolia
12+
- arbitrum
13+
version_label:
14+
description: 'Version label for the subgraph deployment'
15+
required: true
16+
type: string
17+
18+
jobs:
19+
build-and-test:
20+
uses: ./.github/workflows/subgraph-ci.yml
21+
with:
22+
node-version: 20
23+
24+
deploy:
25+
needs: build-and-test
26+
runs-on: ubuntu-latest
27+
# Associate the job with a GitHub Environment which has pre-defined variables and secrets.
28+
environment: ${{ github.event.inputs.network }}
29+
steps:
30+
- uses: actions/checkout@v4
31+
with:
32+
fetch-depth: 0
33+
- uses: actions/setup-node@v4
34+
with:
35+
node-version: '20'
36+
cache: 'npm'
37+
cache-dependency-path: 'packages/subgraph'
38+
39+
- name: Install dependencies
40+
working-directory: packages/subgraph
41+
run: npm ci
42+
43+
- name: Codegen
44+
working-directory: packages/subgraph
45+
run: npm run codegen
46+
47+
- name: Deploy Subgraph
48+
working-directory: packages/subgraph
49+
env:
50+
SUBGRAPH_DEPLOY_KEY: ${{ secrets.SUBGRAPH_DEPLOY_KEY }}
51+
SUBGRAPH_NETWORK_NAME: ${{ vars.SUBGRAPH_NETWORK_NAME }}
52+
SUBGRAPH_SLUG: ${{ vars.SUBGRAPH_SLUG }}
53+
VERSION_LABEL: ${{ github.event.inputs.version_label }}
54+
run: npm run deploy-studio
55+
56+
- name: Deployment Success
57+
run: |
58+
echo "🎉 Subgraph deployment completed successfully!"
59+
echo "📋 Next steps:"
60+
echo "1. Go to TheGraph Studio: https://thegraph.com/studio/"
61+
echo "2. Connect with the iExec wallet"
62+
echo "3. Publish the subgraph to make it publicly available"
63+
echo "4. Subgraph details:"
64+
echo " - Slug: ${{ vars.SUBGRAPH_SLUG }}"
65+
echo " - Network: ${{ vars.SUBGRAPH_NETWORK_NAME }}"
66+
echo " - Version: ${{ github.event.inputs.version_label }}"

.github/workflows/deploy-subgraph.yml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Deploy Subgraph
1+
name: Deploy Subgraph - on self-hosted node
22

33
on:
44
workflow_dispatch: # Triggered manually but we can also trigger with an release event
@@ -12,27 +12,29 @@ on:
1212
- staging
1313
- tmp
1414
- prod
15-
# Add new networks when needed. Do not forget to add necessary data in the networks.json file.
16-
networkName:
17-
description: 'Network Name'
18-
required: false
19-
default: bellecour
20-
type: choice
21-
options:
22-
- bellecour
2315

2416
jobs:
17+
build-and-test:
18+
uses: ./.github/workflows/subgraph-ci.yml
19+
with:
20+
node-version: 20
21+
2522
deploy:
23+
needs: build-and-test
2624
runs-on:
2725
group: Azure_runners
2826
labels: [ self-hosted, Linux, X64 ]
2927
# Associate the job with a GitHub Environment which has pre-defined variables and secrets.
3028
environment: ${{ github.event.inputs.environment }}
3129
steps:
3230
- uses: actions/checkout@v4
31+
with:
32+
fetch-depth: 0
3333
- uses: actions/setup-node@v4
3434
with:
3535
node-version: '20'
36+
cache: 'npm'
37+
cache-dependency-path: 'packages/subgraph'
3638

3739
- name: Install dependencies
3840
working-directory: packages/subgraph
@@ -52,7 +54,7 @@ jobs:
5254
- name: Deploy Subgraph
5355
working-directory: packages/subgraph
5456
env:
55-
NETWORK_NAME: ${{ github.event.inputs.networkName }}
57+
NETWORK_NAME: bellecour
5658
VERSION_LABEL: ${{ steps.set_version.outputs.version }}
5759
GRAPHNODE_URL: ${{ vars.GRAPHNODE_URL }}
5860
IPFS_URL: ${{ vars.IPFS_URL }}

.github/workflows/subgraph-ci.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Core Smart Contract - Default
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- '*'
7+
paths:
8+
- 'packages/subgraph/**'
9+
workflow_call:
10+
inputs:
11+
node-version:
12+
description: Node.js version to use
13+
required: false
14+
type: number
15+
default: 20
16+
17+
concurrency:
18+
group: ${{ github.ref }}-subgraph-ci
19+
cancel-in-progress: true
20+
21+
jobs:
22+
build-and-test:
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@v4
26+
with:
27+
fetch-depth: 0
28+
29+
- uses: actions/setup-node@v4
30+
with:
31+
node-version: ${{ inputs.node-version }}
32+
cache: 'npm'
33+
cache-dependency-path: 'packages/subgraph'
34+
35+
- name: Install dependencies
36+
working-directory: packages/subgraph
37+
run: npm ci
38+
39+
- name: Check Format
40+
working-directory: packages/subgraph
41+
run: npm run check-format
42+
43+
- name: Codegen
44+
working-directory: packages/subgraph
45+
run: npm run codegen
46+
47+
# TODO: fix test command
48+
# - name: Run unit tests
49+
# working-directory: packages/subgraph
50+
# run: npm run test
51+
52+
- name: Build
53+
working-directory: packages/subgraph
54+
run: npm run build

packages/subgraph/.env.template

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,12 @@ VERSION_LABEL=...
1212

1313
# Start block number for local testing
1414
START_BLOCK=...
15+
16+
# The slug for the subgraph created on The Graph Network
17+
SUBGRAPH_SLUG=...
18+
19+
# The deploy key for The Graph Network deployment
20+
SUBGRAPH_DEPLOY_KEY=...
21+
22+
# The network name for The Graph Network deployment (e.g., arbitrum-sepolia, arbitrum)
23+
SUBGRAPH_NETWORK_NAME=...

packages/subgraph/config/env.ts

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,45 @@ import 'dotenv/config';
22
import { z } from 'zod';
33

44
const envSchema = z.object({
5-
NETWORK_NAME: z.string().min(1, 'NETWORK_NAME is required').default('bellecour'),
5+
NETWORK_NAME: z
6+
.string()
7+
.min(1, 'NETWORK_NAME is required')
8+
.default('bellecour'),
69

7-
GRAPHNODE_URL: z
8-
.string()
9-
.url('GRAPHNODE_URL must be a valid URL')
10-
.default('http://localhost:8020'),
10+
GRAPHNODE_URL: z
11+
.string()
12+
.url('GRAPHNODE_URL must be a valid URL')
13+
.default('http://localhost:8020'),
1114

12-
IPFS_URL: z.string().url('IPFS_URL must be a valid URL').default('http://localhost:5001'),
15+
IPFS_URL: z
16+
.string()
17+
.url('IPFS_URL must be a valid URL')
18+
.default('http://localhost:5001'),
1319

14-
VERSION_LABEL: z.string().min(1, 'VERSION_LABEL is required').default('bellecour/poco-v5'),
20+
VERSION_LABEL: z.string().min(1, 'VERSION_LABEL is required').default('dev'),
1521

16-
START_BLOCK: z
17-
.string()
18-
.transform((val) => parseInt(val, 10))
19-
.refine((val) => !isNaN(val) && val >= 0, {
20-
message: 'START_BLOCK must be a valid non-negative integer',
21-
})
22-
.or(z.undefined()),
22+
START_BLOCK: z
23+
.string()
24+
.transform((val) => parseInt(val, 10))
25+
.refine((val) => !isNaN(val) && val >= 0, {
26+
message: 'START_BLOCK must be a valid non-negative integer',
27+
})
28+
.or(z.undefined()),
29+
30+
SUBGRAPH_SLUG: z
31+
.string()
32+
.min(1, 'SUBGRAPH_SLUG must not be empty')
33+
.optional(),
34+
35+
SUBGRAPH_DEPLOY_KEY: z
36+
.string()
37+
.min(1, 'SUBGRAPH_DEPLOY_KEY must not be empty')
38+
.optional(),
39+
40+
SUBGRAPH_NETWORK_NAME: z
41+
.string()
42+
.min(1, 'SUBGRAPH_NETWORK_NAME must not be empty')
43+
.optional(),
2344
});
2445

2546
export const env = envSchema.parse(process.env);

packages/subgraph/networks.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,28 @@
4343
"startBlock": 145960686
4444
}
4545
},
46+
"arbitrum-one": {
47+
"DataProtector": {
48+
"address": "0x0000000000000000000000000000000000000000",
49+
"startBlock": 0
50+
},
51+
"DatasetRegistry": {
52+
"address": "0x0000000000000000000000000000000000000000",
53+
"startBlock": 0
54+
},
55+
"DataProtectorSharing": {
56+
"address": "0x0000000000000000000000000000000000000000",
57+
"startBlock": 0
58+
},
59+
"AppRegistry": {
60+
"address": "0x0000000000000000000000000000000000000000",
61+
"startBlock": 0
62+
},
63+
"AddOnlyAppWhitelistRegistry": {
64+
"address": "0x0000000000000000000000000000000000000000",
65+
"startBlock": 0
66+
}
67+
},
4668
"bellecour": {
4769
"DataProtector": {
4870
"address": "0x3a4Ab33F3D605e75b6D00A32A0Fa55C3628F6A59",

packages/subgraph/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
"license": "UNLICENSED",
55
"scripts": {
66
"codegen": "graph codegen subgraph.template.yaml",
7-
"build": "dotenv -e .env -- sh -c 'graph codegen subgraph.template.yaml && graph build subgraph.template.yaml --network ${NETWORK_NAME:-bellecour}'",
8-
"deploy-theGraph": "graph deploy --node https://api.thegraph.com/deploy/ DataProtector",
7+
"build": "dotenv -e .env -- sh -c 'npm run codegen && graph build subgraph.template.yaml --network ${NETWORK_NAME:-bellecour}'",
98
"create": "dotenv -e .env -- sh -c 'graph create --node ${GRAPHNODE_URL:-http://localhost:8020} ${NETWORK_NAME:-bellecour}${DEPLOY_ENV:-/}dataprotector-v2'",
109
"deploy": "dotenv -e .env -- sh -c 'graph deploy ${NETWORK_NAME:-bellecour}${DEPLOY_ENV:-/}dataprotector-v2 subgraph.template.yaml --node ${GRAPHNODE_URL:-http://localhost:8020} --ipfs ${IPFS_URL:-http://localhost:5001} --network ${NETWORK_NAME:-bellecour} --version-label ${VERSION_LABEL:-dev}'",
10+
"deploy-studio": "dotenv -e .env -- sh -c 'graph deploy ${SUBGRAPH_SLUG} subgraph.template.yaml --deploy-key ${SUBGRAPH_DEPLOY_KEY} --network ${SUBGRAPH_NETWORK_NAME} --version-label ${VERSION_LABEL}'",
1111
"clean": "rm -rf generated && rm -rf build",
1212
"test": "npm run codegen && graph test",
1313
"all": " dotenv -e .env -- sh -c 'tsx ./test-stack/prepare-test-env.ts && npm run clean && npm run codegen && npm run build && npm run create && npm run deploy'",

packages/subgraph/subgraph.template.yaml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ dataSources:
77
kind: ethereum/contract
88
source:
99
abi: DataProtector
10-
address: "0x3a4Ab33F3D605e75b6D00A32A0Fa55C3628F6A59"
11-
startBlock: 25455501
1210
mapping:
1311
kind: ethereum/events
1412
apiVersion: 0.0.7
@@ -31,8 +29,6 @@ dataSources:
3129
kind: ethereum/contract
3230
source:
3331
abi: DatasetRegistry
34-
address: "0x0000000000000000000000000000000000000000"
35-
startBlock: 25455501
3632
mapping:
3733
kind: ethereum/events
3834
apiVersion: 0.0.7
@@ -53,8 +49,6 @@ dataSources:
5349
kind: ethereum/contract
5450
source:
5551
abi: AppRegistry
56-
address: "0x0000000000000000000000000000000000000000"
57-
startBlock: 28566236
5852
mapping:
5953
kind: ethereum/events
6054
apiVersion: 0.0.7
@@ -75,8 +69,6 @@ dataSources:
7569
kind: ethereum/contract
7670
source:
7771
abi: DataProtectorSharing
78-
address: "0x1390c3c6a545198809F1C7c5Dd2600ef74D60925"
79-
startBlock: 28566236
8072
mapping:
8173
kind: ethereum/events
8274
apiVersion: 0.0.7
@@ -127,8 +119,6 @@ dataSources:
127119
kind: ethereum/contract
128120
source:
129121
abi: AddOnlyAppWhitelistRegistry
130-
address: "0x498D324F711b8998Be81818742e268dEE30347c6"
131-
startBlock: 28566234
132122
mapping:
133123
kind: ethereum/events
134124
apiVersion: 0.0.7

0 commit comments

Comments
 (0)