diff --git a/packages/retag/src/index.ts b/packages/retag/src/index.ts index 655aeb61cb..5f1ebc6eb5 100644 --- a/packages/retag/src/index.ts +++ b/packages/retag/src/index.ts @@ -14,6 +14,7 @@ import { LoggerWithErrors, cacheDir, nAtATime, + sleep, } from "@definitelytyped/utils"; import { AnyPackage, TypingsData, AllPackages, getDefinitelyTyped } from "@definitelytyped/definitions-parser"; import * as pacote from "pacote"; @@ -56,16 +57,41 @@ async function tag(dry: boolean, definitelyTypedPath: string, name?: string) { await updateLatestTag(pkg.name, version, publishClient, consoleLogger.info, dry); } else { const allPackages = AllPackages.fromFS(dt); + let allowedErrors = 10; await nAtATime(5, await allPackages.allLatestTypings(), async (pkg) => { - // Only update tags for the latest version of the package. - const version = await getLatestTypingVersion(pkg); - await updateTypeScriptVersionTags(pkg, version, publishClient, consoleLogger.info, dry); - await updateLatestTag(pkg.name, version, publishClient, consoleLogger.info, dry); + try { + await retry(async () => { + // Only update tags for the latest version of the package. + const version = await getLatestTypingVersion(pkg); + await updateTypeScriptVersionTags(pkg, version, publishClient, consoleLogger.info, dry); + await updateLatestTag(pkg.name, version, publishClient, consoleLogger.info, dry); + }, /*count*/ 2, /*delaySeconds*/ 5); + } catch (e: any) { + consoleLogger.error(`Error tagging ${pkg.name}: ${e.stack || e}`); + allowedErrors--; + if (allowedErrors <= 0) { + consoleLogger.error("Too many errors, exiting."); + throw e; + } + } }); } // Don't tag notNeeded packages } +async function retry(fn: () => Promise, count: number, delaySeconds: number): Promise { + let lastError: any; + for (let i = 0; i < count; i++) { + try { + return await fn(); + } catch (e) { + await sleep(delaySeconds); + lastError = e; + } + } + throw lastError; +} + export async function updateTypeScriptVersionTags( pkg: AnyPackage, version: string,