Skip to content

Commit abbc35d

Browse files
committed
feat: enhance subgraph deployment workflow with version label and slug inputs
1 parent 2f66ee3 commit abbc35d

File tree

4 files changed

+42
-43
lines changed

4 files changed

+42
-43
lines changed
Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
name: Deploy Subgraph - on TheGraph Network
22

33
on:
4+
push:
45
workflow_dispatch: # Manual trigger
56
inputs:
67
network:
78
description: 'Network'
89
required: true
910
type: choice
1011
options:
11-
- arbitrum-sepolia
12-
- arbitrum-one
12+
- arbitrumSepolia
13+
- arbitrum
14+
version-label:
15+
description: 'Version label for the subgraph deployment'
16+
required: true
17+
type: string
1318

1419
jobs:
1520
build-and-test:
@@ -20,7 +25,7 @@ jobs:
2025
needs: build-and-test
2126
runs-on: ubuntu-latest
2227
# Associate the job with a GitHub Environment which has pre-defined variables and secrets.
23-
environment: ${{ github.event.inputs.environment }}
28+
environment: ${{ github.event.inputs.network }}
2429
steps:
2530
- uses: actions/checkout@v4
2631
- uses: actions/setup-node@v4
@@ -31,31 +36,11 @@ jobs:
3136
working-directory: packages/subgraph
3237
run: npm ci
3338

34-
- name: Set Version Label
35-
working-directory: packages/subgraph
36-
id: set_version
37-
run: |
38-
if [[ "${{ github.event.inputs.environment }}" == "staging" ]]; then
39-
echo "version=${GITHUB_SHA}" >> $GITHUB_OUTPUT
40-
else
41-
version=$(npm pkg get version | sed 's/"//g')
42-
echo "version=$version" >> $GITHUB_OUTPUT
43-
fi
44-
4539
- name: Deploy Subgraph
4640
working-directory: packages/subgraph
4741
env:
48-
NETWORK_NAME: bellecour
49-
VERSION_LABEL: ${{ steps.set_version.outputs.version }}
50-
GRAPHNODE_URL: ${{ vars.GRAPHNODE_URL }}
51-
IPFS_URL: ${{ vars.IPFS_URL }}
52-
DEPLOY_ENV: ${{ vars.ENV_NAME }}
53-
run: |
54-
echo "Starting deployment with the following parameters:"
55-
echo " Network Name: $NETWORK_NAME"
56-
echo " Version Label: $VERSION_LABEL"
57-
echo " DEPLOY_ENV: $DEPLOY_ENV"
58-
echo " GRAPHNODE_URL: $GRAPHNODE_URL"
59-
echo " IPFS_URL: $IPFS_URL"
60-
npm run all
61-
shell: bash
42+
SUBGRAPH_DEPLOY_KEY: ${{ secrets.SUBGRAPH_DEPLOY_KEY }}
43+
SUBGRAPH_NETWORK_NAME: ${{ vars.SUBGRAPH_NETWORK_NAME }}
44+
SUBGRAPH_SLUG: ${{ vars.SUBGRAPH_SLUG }}
45+
VERSION_LABEL: ${{ github.event.inputs.version-label }}
46+
run: npm run deploy-chainX -- --deploy-key $SUBGRAPH_DEPLOY_KEY --network $SUBGRAPH_NETWORK_NAME --version-label $VERSION_LABEL

packages/subgraph/.env.template

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ 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=...

packages/subgraph/config/env.ts

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,35 @@ 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(),
2334
});
2435

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

packages/subgraph/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"scripts": {
66
"codegen": "graph codegen subgraph.template.yaml",
77
"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",
8+
"deploy-chainX": "dotenv -e .env -- sh -c 'graph deploy ${SUBGRAPH_SLUG} subgraph.template.yaml'",
99
"create": "dotenv -e .env -- sh -c 'graph create --node ${GRAPHNODE_URL:-http://localhost:8020} ${NETWORK_NAME:-bellecour}${DEPLOY_ENV:-/}dataprotector-v2'",
1010
"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}'",
1111
"clean": "rm -rf generated && rm -rf build",

0 commit comments

Comments
 (0)