Skip to content

Commit 8c9c17d

Browse files
committed
Retry blueprint token minting like the clone/checkout it guards
Addresses PR review feedback: a transient failure minting the GitHub App installation token used to fail the whole build immediately, unlike the clone/checkout steps which get 3 attempts with backoff.
1 parent f36cb3b commit 8c9c17d

1 file changed

Lines changed: 23 additions & 8 deletions

File tree

nuxt/lib/blueprints-sync.mjs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,35 @@ export function resolveSource ({ repoRoot, env = process.env, exists = existsSyn
6767
*/
6868
async function cloneBlueprints (ref, env, logger) {
6969
const { mintInstallationToken } = await import('./github-app-token.mjs')
70-
const token = await mintInstallationToken({
71-
appId: env.GH_BOT_APP_ID,
72-
privateKey: env.GH_BOT_APP_KEY,
73-
owner: REPO_OWNER,
74-
repo: REPO_NAME,
75-
})
76-
const authedUrl = REPO_URL.replace('https://', `https://x-access-token:${token}@`)
77-
const redact = (text) => text.split(token).join('***')
7870

7971
let lastMessage = 'unknown error'
8072
for (let attempt = 1; attempt <= CLONE_ATTEMPTS; attempt++) {
8173
const tmpDir = join(tmpdir(), `blueprint-library-${process.pid}-${attempt}`)
8274
if (existsSync(tmpDir)) rmSync(tmpDir, { recursive: true, force: true })
8375

76+
// Minted fresh each attempt so a transient failure here gets the same retry +
77+
// redaction as the clone/checkout below, rather than failing the build outright.
78+
let token
79+
try {
80+
token = await mintInstallationToken({
81+
appId: env.GH_BOT_APP_ID,
82+
privateKey: env.GH_BOT_APP_KEY,
83+
owner: REPO_OWNER,
84+
repo: REPO_NAME,
85+
})
86+
} catch (err) {
87+
lastMessage = err?.message || String(err)
88+
if (attempt === CLONE_ATTEMPTS) break
89+
90+
const wait = CLONE_BACKOFF_MS * attempt
91+
logger.warn(`Blueprint token mint attempt ${attempt}/${CLONE_ATTEMPTS} failed, retrying in ${wait}ms`)
92+
await sleep(wait)
93+
continue
94+
}
95+
96+
const authedUrl = REPO_URL.replace('https://', `https://x-access-token:${token}@`)
97+
const redact = (text) => text.split(token).join('***')
98+
8499
try {
85100
// Blobless but not shallow: dating a blueprint page needs that page's history,
86101
// and a --depth=1 clone stamps every page with the same commit date.

0 commit comments

Comments
 (0)