|
1 | 1 | name: Deploy Subgraph |
2 | 2 |
|
3 | 3 | on: |
4 | | - workflow_dispatch: |
| 4 | + workflow_dispatch: # Triggered manually but we can also trigger with an release event |
| 5 | + inputs: |
| 6 | + environment: |
| 7 | + description: 'Deployment environment (must match a GitHub Environment name)' |
| 8 | + required: true |
| 9 | + default: staging |
| 10 | + type: choice |
| 11 | + options: |
| 12 | + - staging |
| 13 | + - tmp |
| 14 | + - 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 |
5 | 23 |
|
6 | 24 | jobs: |
7 | 25 | deploy: |
8 | 26 | runs-on: |
9 | 27 | group: Azure_runners |
10 | 28 | labels: [ self-hosted, Linux, X64 ] |
11 | | - strategy: |
12 | | - matrix: |
13 | | - include: |
14 | | - - target: staging |
15 | | - subgraph_name: 'bellecour/staging-dataprotector-v2' |
16 | | - env_name: staging |
17 | | - graphnode_url: ${{ secrets.GRAPHNODE_URL_STAGING }} |
18 | | - ipfs_url: ${{ secrets.IPFS_URL_STAGING }} |
19 | | - version_method: npm_version |
20 | | - - target: tmp |
21 | | - subgraph_name: 'bellecour/tmp-dataprotector-v2' |
22 | | - env_name: prod |
23 | | - graphnode_url: ${{ secrets.GRAPHNODE_URL }} |
24 | | - ipfs_url: ${{ secrets.IPFS_URL }} |
25 | | - version_method: commit |
26 | | - - target: prod |
27 | | - subgraph_name: 'bellecour/dataprotector-v2' |
28 | | - env_name: prod |
29 | | - graphnode_url: ${{ secrets.GRAPHNODE_URL }} |
30 | | - ipfs_url: ${{ secrets.IPFS_URL }} |
31 | | - version_method: npm_version |
32 | | - |
33 | | - # Run only on main branch |
34 | | - if: github.ref == 'refs/heads/main' |
| 29 | + # Associate the job with a GitHub Environment which has pre-defined variables and secrets. |
| 30 | + environment: ${{ github.event.inputs.environment }} |
35 | 31 | steps: |
36 | 32 | - uses: actions/checkout@v4 |
37 | 33 | - uses: actions/setup-node@v4 |
38 | 34 | with: |
39 | | - node-version: 18 |
| 35 | + node-version: '20' |
40 | 36 |
|
41 | | - - name: Install Dependencies |
| 37 | + - name: Install dependencies |
42 | 38 | working-directory: packages/subgraph |
43 | 39 | run: npm ci |
44 | 40 |
|
45 | | - - name: Run Codegen and Build |
46 | | - working-directory: packages/subgraph |
47 | | - run: | |
48 | | - npm run codegen |
49 | | - npm run build |
50 | | -
|
51 | 41 | - name: Set Version Label |
52 | | - id: set_version |
53 | 42 | working-directory: packages/subgraph |
| 43 | + id: set_version |
54 | 44 | run: | |
55 | | - if [ "${{ matrix.subgraph.version_method }}" = "commit" ]; then |
| 45 | + if [[ "${{ github.event.inputs.environment }}" == "staging" ]]; then |
56 | 46 | echo "version=${GITHUB_SHA}" >> $GITHUB_OUTPUT |
57 | 47 | else |
58 | 48 | version=$(npm pkg get version | sed 's/"//g') |
59 | | - echo "version=${version}" >> $GITHUB_OUTPUT |
| 49 | + echo "version=$version" >> $GITHUB_OUTPUT |
60 | 50 | fi |
61 | 51 |
|
62 | | - - name: Create Subgraph |
63 | | - working-directory: packages/subgraph |
64 | | - run: | |
65 | | - npx graph create --node ${{ matrix.subgraph.graphnode_url }} ${{ matrix.subgraph.subgraph_name }} |
66 | | -
|
67 | 52 | - name: Deploy Subgraph |
68 | 53 | working-directory: packages/subgraph |
| 54 | + env: |
| 55 | + NETWORK_NAME: ${{ github.event.inputs.networkName }} |
| 56 | + VERSION_LABEL: ${{ steps.set_version.outputs.version }} |
| 57 | + GRAPHNODE_URL: ${{ vars.GRAPHNODE_URL }} |
| 58 | + IPFS_URL: ${{ vars.IPFS_URL }} |
| 59 | + DEPLOY_ENV: ${{ vars.ENV_NAME }} |
69 | 60 | run: | |
70 | | - npx graph deploy --node ${{ matrix.subgraph.graphnode_url }} ${{ matrix.subgraph.subgraph_name }} --ipfs ${{ matrix.subgraph.ipfs_url }} --version-label ${{ steps.set_version.outputs.version }} |
| 61 | + echo "Starting deployment with the following parameters:" |
| 62 | + echo " Network Name: $NETWORK_NAME" |
| 63 | + echo " Version Label: $VERSION_LABEL" |
| 64 | + echo " DEPLOY_ENV: $DEPLOY_ENV" |
| 65 | + echo " GRAPHNODE_URL: $GRAPHNODE_URL" |
| 66 | + echo " IPFS_URL: $IPFS_URL" |
| 67 | + npm run all |
| 68 | + shell: bash |
0 commit comments