Skip to content

Commit

Permalink
Retry tags, exit only after too many errors (#1039)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebailey authored Jul 29, 2024
1 parent 432b371 commit 27187c7
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions packages/retag/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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<T>(fn: () => Promise<T>, count: number, delaySeconds: number): Promise<T> {
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,
Expand Down

0 comments on commit 27187c7

Please sign in to comment.