Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(subgraph): fix ci deployment + better versioning #13500

Merged
merged 3 commits into from Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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