Skip to content

Commit

Permalink
Merge pull request #5056 from Shopify/fallback-to-github-when-not-on-…
Browse files Browse the repository at this point in the history
…spin

Fall back to GitHub when repo is not on spin
  • Loading branch information
amcaplan authored Dec 16, 2024
2 parents cb09e4d + c459300 commit 3c13412
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions bin/get-graphql-schemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ async function getGithubPasswordFromDev() {
}
}

async function fetchFiles() {
async function withOctokit(func) {
let password = undefined
let tokenFromEnv = process.env.GITHUB_TOKEN || process.env.GH_TOKEN
if (!tokenFromEnv) {
Expand All @@ -145,10 +145,15 @@ async function fetchFiles() {
const octokit = new Octokit({
auth: authToken,
})
return func(octokit)
}

async function fetchFiles() {
let allSuccess = true
for (const schema of schemas) {
allSuccess = await fetchFileForSchema(schema, octokit) && allSuccess
allSuccess = allSuccess && await withOctokit(async (octokit) => {
return fetchFileForSchema(schema, octokit)
})
}

if (!allSuccess) {
Expand All @@ -161,7 +166,19 @@ async function fetchFilesFromSpin() {
for (const schema of schemas) {
const remotePath = `~/src/github.com/Shopify/${schema.repo}/${schema.pathToFile}`
const localPath = schema.localPath
await runCommand('spin', ['copy', `${process.env.SPIN_INSTANCE}:${remotePath}`, localPath])
try {
await runCommand('spin', ['copy', `${process.env.SPIN_INSTANCE}:${remotePath}`, localPath])
} catch(e) {
if (e.message.match(/scp.*No such file or directory/)) {
// Assume we need to just fetch the file from GitHub
console.log(`Cannot find file for ${schema.repo} in Spin, fetching from GitHub instead...`)
await withOctokit(async (octokit) => {
await fetchFileForSchema(schema, octokit)
})
} else {
throw e
}
}
}
}

Expand Down

0 comments on commit 3c13412

Please sign in to comment.