Skip to content

Commit

Permalink
fix(subgraph): fix ci deployment + better versioning (#13500)
Browse files Browse the repository at this point in the history
* prepare network files before deploying

* change subgraph versioning

* use only git sha in version label
  • Loading branch information
clemsos committed Mar 22, 2024
1 parent 7ba617d commit 89cd78c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/_subgraph.yml
Expand Up @@ -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
30 changes: 15 additions & 15 deletions subgraph/bin/thegraph
Expand Up @@ -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,
})
}
}
}
Expand Down Expand Up @@ -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 })
}

/**
Expand All @@ -102,7 +102,7 @@ const deploy = async (network, studioName, graphLabel) => {
}

if (!studioName) {
; ({ studioName } = networks[network].subgraph)
;({ studioName } = networks[network].subgraph)
}

if (!studioName) {
Expand Down

0 comments on commit 89cd78c

Please sign in to comment.