From 5eb0bff253ffb90b07dfad13e2fa687e97010571 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renaud?= Date: Thu, 21 Mar 2024 10:48:23 +0100 Subject: [PATCH 1/3] prepare network files before deploying --- .github/workflows/_subgraph.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 From 76f167c54a2eb43c468d29edb3f6b64c0135d259 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renaud?= Date: Thu, 21 Mar 2024 11:08:11 +0100 Subject: [PATCH 2/3] change subgraph versioning --- subgraph/bin/thegraph | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/subgraph/bin/thegraph b/subgraph/bin/thegraph index 8498dfa47e8..f7c42207677 100644 --- a/subgraph/bin/thegraph +++ b/subgraph/bin/thegraph @@ -7,6 +7,10 @@ */ const { hideBin } = require('yargs/helpers') const networks = require('@unlock-protocol/networks') +const { + UNLOCK_LATEST_VERSION, + PUBLICLOCK_LATEST_VERSION, +} = require('@unlock-protocol/contracts') const util = require('util') const exec = util.promisify(require('child_process').exec) const { networkName } = require('./networks') @@ -25,30 +29,26 @@ 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}` +const getVersion = () => { + const gitSha = require('child_process') + .execSync('git rev-parse --short HEAD') + .toString() + .trim() + return `v${UNLOCK_LATEST_VERSION}-${PUBLICLOCK_LATEST_VERSION}-${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 +82,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 +105,7 @@ const deploy = async (network, studioName, graphLabel) => { } if (!studioName) { - ; ({ studioName } = networks[network].subgraph) + ;({ studioName } = networks[network].subgraph) } if (!studioName) { From dffc6389f9b21376f17c269243fb28295465685d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renaud?= Date: Thu, 21 Mar 2024 16:01:58 +0100 Subject: [PATCH 3/3] use only git sha in version label --- subgraph/bin/thegraph | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/subgraph/bin/thegraph b/subgraph/bin/thegraph index f7c42207677..24b73448263 100644 --- a/subgraph/bin/thegraph +++ b/subgraph/bin/thegraph @@ -7,10 +7,6 @@ */ const { hideBin } = require('yargs/helpers') const networks = require('@unlock-protocol/networks') -const { - UNLOCK_LATEST_VERSION, - PUBLICLOCK_LATEST_VERSION, -} = require('@unlock-protocol/contracts') const util = require('util') const exec = util.promisify(require('child_process').exec) const { networkName } = require('./networks') @@ -29,12 +25,13 @@ const executeCommand = async (command) => { } } +// 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 `v${UNLOCK_LATEST_VERSION}-${PUBLICLOCK_LATEST_VERSION}-${gitSha}` + return `${gitSha}` } const executeStudioDeploy = async ({