Skip to content

Commit

Permalink
Allow skipping download when regenerating all docs (Qiskit#819)
Browse files Browse the repository at this point in the history
I regenerated the docs last night and we haven't changed Box artifacts
since then. I want to regenerate the docs again today, so it's
convenient to let me skip the download to speed things up.
  • Loading branch information
Eric-Arellano authored Feb 15, 2024
1 parent ba213c8 commit 73d9c5d
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions scripts/commands/regenerateApiDocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ interface Arguments {
[x: string]: unknown;
package?: string;
currentApisOnly: boolean;
skipDownload: boolean;
}

const readArgs = (): Arguments => {
Expand All @@ -41,6 +42,11 @@ const readArgs = (): Arguments => {
default: false,
description: "Regenerate only the current API docs?",
})
.option("skip-download", {
type: "boolean",
default: false,
description: "Don't redownload docs from Box",
})
.parseSync();
};

Expand All @@ -62,6 +68,7 @@ zxMain(async () => {

const result = await processVersions(
pkgName,
args.skipDownload,
historicalVersions,
currentVersion,
maybeDevVersion,
Expand All @@ -83,6 +90,7 @@ git cherry-pick or git rebase -i so each PR only has the commits it wants to tar

async function processVersions(
pkgName: string,
skipDownload: boolean,
historicalVersions: string[],
currentVersion: string,
maybeDevVersion: string | undefined,
Expand All @@ -91,14 +99,21 @@ async function processVersions(

for (const historicalVersion of historicalVersions) {
results.push(
await regenerateVersion(pkgName, historicalVersion, "historical"),
await regenerateVersion(
pkgName,
historicalVersion,
skipDownload,
"historical",
),
);
}

results.push(await regenerateVersion(pkgName, currentVersion));
results.push(await regenerateVersion(pkgName, currentVersion, skipDownload));

if (maybeDevVersion) {
results.push(await regenerateVersion(pkgName, maybeDevVersion, "dev"));
results.push(
await regenerateVersion(pkgName, maybeDevVersion, skipDownload, "dev"),
);
}

return results;
Expand All @@ -107,15 +122,19 @@ async function processVersions(
async function regenerateVersion(
pkgName: string,
version: string,
skipDownload: boolean,
typeArgument?: "historical" | "dev",
): Promise<string> {
try {
if (typeArgument) {
await $`npm run gen-api -- -p ${pkgName} -v ${version} --${typeArgument}`;
} else {
await $`npm run gen-api -- -p ${pkgName} -v ${version}`;
}
const command = ["npm", "run", "gen-api", "--", "-p", pkgName, "-v", version];
if (typeArgument) {
command.push(`--${typeArgument}`);
}
if (skipDownload) {
command.push("--skip-download");
}

try {
await $`${command}`;
if ((await gitStatus()) !== "") {
await gitCommit(`Regenerate ${pkgName} ${version}`);
return `✅ ${pkgName} ${version} regenerated correctly`;
Expand Down

0 comments on commit 73d9c5d

Please sign in to comment.