From 89cd78ce1cb70a5c3b551c2da7cd06ec33039ae2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renaud?= Date: Fri, 22 Mar 2024 14:15:09 +0100 Subject: [PATCH] fix(subgraph): fix ci deployment + better versioning (#13500) * prepare network files before deploying * change subgraph versioning * use only git sha in version label --- .github/workflows/_subgraph.yml | 4 +++- subgraph/bin/thegraph | 30 +++++++++++++++--------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/.github/workflows/_subgraph.yml b/.github/workflows/_subgraph.yml index e0800fff5cb..5d0fe438b11 100644 --- a/.github/workflows/_subgraph.yml +++ b/.github/workflows/_subgraph.yml @@ -21,6 +21,8 @@ jobs: node-version: 20 - run: yarn - run: yarn build + - name: Prepare the network files + run: yarn workspace @unlock-protocol/subgraph prepare - name: Deploying the subgraphs - run: cd subgraph && yarn deploy-all + run: yarn workspace @unlock-protocol/subgraph deploy-all shell: bash diff --git a/subgraph/bin/thegraph b/subgraph/bin/thegraph index 8498dfa47e8..24b73448263 100644 --- a/subgraph/bin/thegraph +++ b/subgraph/bin/thegraph @@ -25,30 +25,27 @@ const executeCommand = async (command) => { } } -const incrementVersion = (version) => { - const [_, major, minor, patch] = version.match( - /v([0-9]*)\.([0-9]*)\.([0-9]*)/ - ) - return `v${major}.${minor}.${parseInt(patch) + 1}` +// use shorthand of git sha commit as version label +const getVersion = () => { + const gitSha = require('child_process') + .execSync('git rev-parse --short HEAD') + .toString() + .trim() + return `${gitSha}` } -const executeStudioDeployWithVersionIncrement = async ({ +const executeStudioDeploy = async ({ subgraphName, - version = 'v0.0.1', // TODO: fetch latest version + version, flags = '--product=subgraph-studio', }) => { const cmd = `graph deploy --version-label="${version}" ${flags} ${subgraphName}` let stderr = await executeCommand(cmd) if (stderr) { if (stderr.includes(`Version label already exists`)) { - const nextVersion = incrementVersion(version) console.log( - `Studio version for ${subgraphName} exists - attempting deploy with version - ${nextVersion}` + `Studio version '${version}' for ${subgraphName} exists - skipping` ) - return executeStudioDeployWithVersionIncrement({ - subgraphName, - version: nextVersion, - }) } } } @@ -82,7 +79,10 @@ const deployStudio = async (subgraphName, version) => { await executeCommand( `graph auth --studio ${process.env.SUBGRAPH_STUDIO_DEPLOY_KEY}` ) - return executeStudioDeployWithVersionIncrement({ subgraphName, version }) + if (!version) { + version = getVersion() + } + return executeStudioDeploy({ subgraphName, version }) } /** @@ -102,7 +102,7 @@ const deploy = async (network, studioName, graphLabel) => { } if (!studioName) { - ; ({ studioName } = networks[network].subgraph) + ;({ studioName } = networks[network].subgraph) } if (!studioName) {