Skip to content

Merge pull request #95 from Secured-Finance/SF-1156-subgraph-support-… #1

Merge pull request #95 from Secured-Finance/SF-1156-subgraph-support-…

Merge pull request #95 from Secured-Finance/SF-1156-subgraph-support-… #1

Workflow file for this run

name: Deploy Subgraph
on:
workflow_dispatch:
inputs:
force_publish:
description: 'True to bypass the check for changes'
required: false
type: boolean
network:
description: 'Network'
required: true
default: 'development'
type: choice
options:
- development
- development-arb
- development-ava
- staging
- staging-arb
- staging-ava
- sepolia
- mainnet
- arbitrum-sepolia
- arbitrum-one
- avalanche-mainnet
- polygon-zkevm-mainnet
push:
branches:
- main
- develop
jobs:
identify-env:
name: Identify the environment
runs-on: ubuntu-latest
outputs:
environment: ${{ (github.event_name == 'workflow_dispatch' && github.event.inputs.network) || steps.extract_branch.outputs.branch == 'main' && 'staging' || 'development' }}
branch: ${{ steps.extract_branch.outputs.branch }}
steps:
- name: Extract branch name
shell: bash
run: echo "branch=$(echo ${GITHUB_REF#refs/heads/})" >>$GITHUB_OUTPUT
id: extract_branch
paths:
name: Path Filter
runs-on: ubuntu-latest
needs: [identify-env]
if: ${{ github.actor != 'secured-finance-machine-user[bot]' }}
outputs:
subgraph: ${{ steps.changes.outputs.subgraph }}
steps:
- uses: actions/checkout@v3
- name: Check Paths
uses: dorny/paths-filter@v2
id: changes
with:
base: ${{ needs.identify-env.outputs.branch }}
filters: |
subgraph:
- 'src/**'
- 'schema.graphql'
- 'subgraph.yaml'
- 'package.json'
deploy:
name: Deploy Graph
runs-on: ubuntu-latest
needs: [paths, identify-env]
environment: ${{ needs.identify-env.outputs.environment }}
if: ${{ needs.paths.outputs.subgraph == 'true' || github.event.inputs.force_publish == 'true' }}
steps:
- run: echo "${{ needs.paths.outputs.subgraph }}"
- name: Generate token
id: generate_token
uses: tibdex/github-app-token@v1
with:
app_id: ${{ secrets.MACHINE_USER_APP_ID }}
private_key: ${{ secrets.MACHINE_USER_PRIVATE_KEY }}
- name: Checkout Repository
uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ steps.generate_token.outputs.token }}
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: Install Dependencies
run: npm ci
env:
NPM_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build
run: npm run build
- name: Deploy Subgraph
id: deploy
run: |
npm run auth ${{secrets.GRAPH_ACCESS_TOKEN}}
npm run update-subgraphrc ${{needs.identify-env.outputs.environment}}
version=$(cat deployment.json | jq -r '."${{needs.identify-env.outputs.environment}}".version' | tr -d '"')
npm run generate ${{needs.identify-env.outputs.environment}}
cat ./subgraph.${{needs.identify-env.outputs.environment}}.yaml
npm run deploy:${{needs.identify-env.outputs.environment}} ${version}
- name: Commit and push
shell: bash
run: |
npm run format:fix
git config user.name "SF Machine User[bot]"
git config user.email "${{ secrets.MACHINE_USER_APP_ID }}+sf-machine-user[bot]@users.noreply.github.com"
git add .
git commit -m "chore: update .subgraphrc"
git push
- name: Merge main into develop
shell: bash
if: ${{ needs.identify-env.outputs.branch == 'main' }}
run: |
git switch develop
git merge main
git push