Skip to content

Commit b6ae293

Browse files
aboodasfariCopilot
andauthored
Fix release tool dependency refresh after version bump (#39390)
## Problem JavaScript SDK validation for Azure/azure-rest-api-specs#44825 fails after SDK generation succeeds. `generateAzureSDKPackage` runs `pnpm install`, then changelog generation rewrites `package.json`, and subsequently invokes `pnpm run build:samples` and `pnpm pack`. With `verifyDepsBeforeRun: error`, pnpm rejects the stale workspace state. Failed runs: - https://dev.azure.com/azure-sdk/public/_build/results?buildId=6610114 - https://dev.azure.com/azure-sdk/public/_build/results?buildId=6610228 ## Fix Re-run the shared dependency installation step after changelog/version metadata changes and before samples/packing. Add a regression test for the required operation order. The release tool package will need to be published and the wrapper dependency updated before the spec validation can consume this fix. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: a935927e-29dd-47fa-87a6-b4b2bfe58ecd
1 parent a6d2853 commit b6ae293

3 files changed

Lines changed: 108 additions & 5 deletions

File tree

eng/tools/js-sdk-release-tools-src/src/common/rushUtils.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ export function isRushRepo(sdkRepoRoot: string): boolean {
8585
);
8686
}
8787

88+
export async function installDependencies() {
89+
await ensurePnpmInstalled();
90+
logger.info(`Start to pnpm install.`);
91+
await runCommand(`pnpm`, ["install"], runCommandOptions, false);
92+
logger.info(`Pnpm install successfully.`);
93+
}
94+
8895
export async function buildPackage(
8996
packageDirectory: string,
9097
options: ModularClientPackageOptions,
@@ -97,10 +104,7 @@ export async function buildPackage(
97104
logger.info(`Start to build package in '${relativePackageDirectoryToSdkRoot}'.`);
98105
const { name } = await getNpmPackageInfo(relativePackageDirectoryToSdkRoot);
99106
let buildStatus = `succeeded`;
100-
await ensurePnpmInstalled();
101-
logger.info(`Start to pnpm install.`);
102-
await runCommand(`pnpm`, ["install"], runCommandOptions, false);
103-
logger.info(`Pnpm install successfully.`);
107+
await installDependencies();
104108

105109
if (options.runMode === RunMode.Local || options.runMode === RunMode.Release) {
106110
await lintFix(packageDirectory);

eng/tools/js-sdk-release-tools-src/src/mlc/clientGenerator/modularClientPackageGenerator.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { ModularClientPackageOptions, NpmPackageInfo, PackageResult } from "../../common/types.js";
2-
import { buildPackage, createArtifact, tryBuildSamples } from "../../common/rushUtils.js";
2+
import {
3+
buildPackage,
4+
createArtifact,
5+
installDependencies,
6+
tryBuildSamples,
7+
} from "../../common/rushUtils.js";
38
import {
49
initPackageResult,
510
updateChangelogResult,
@@ -70,6 +75,7 @@ export async function generateAzureSDKPackage(
7075
const changelog = await generateChangelogAndBumpVersion(relativePackageDirToSdkRoot, options);
7176
updateChangelogResult(packageResult, changelog);
7277
changeReadmeMd(packageDirectory);
78+
await installDependencies();
7379
await tryBuildSamples(packageDirectory, options.sdkRepoRoot, options.runMode);
7480

7581
const npmPackageInfo = await getNpmPackageInfo(packageDirectory);
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import { beforeEach, describe, expect, test, vi } from "vitest";
2+
3+
const mocks = vi.hoisted(() => ({
4+
calls: [] as string[],
5+
packageResult: {
6+
artifacts: [] as string[],
7+
path: [] as string[],
8+
result: "pending",
9+
},
10+
}));
11+
12+
vi.mock("../../common/rushUtils.js", () => ({
13+
buildPackage: vi.fn(async () => mocks.calls.push("build")),
14+
installDependencies: vi.fn(async () => mocks.calls.push("install")),
15+
tryBuildSamples: vi.fn(async () => mocks.calls.push("samples")),
16+
createArtifact: vi.fn(async () => "/sdk/pkg/test.tgz"),
17+
}));
18+
19+
vi.mock("../../common/packageResultUtils.js", () => ({
20+
initPackageResult: vi.fn(() => mocks.packageResult),
21+
updateChangelogResult: vi.fn(),
22+
updateNpmPackageResult: vi.fn(),
23+
}));
24+
25+
vi.mock("../../common/ciYamlUtils.js", () => ({
26+
createOrUpdateCiYaml: vi.fn(async () => undefined),
27+
}));
28+
29+
vi.mock("../../common/changelog/automaticGenerateChangeLogAndBumpVersion.js", () => ({
30+
generateChangelogAndBumpVersion: vi.fn(async () => {
31+
mocks.calls.push("changelog");
32+
return undefined;
33+
}),
34+
}));
35+
36+
vi.mock("../../mlc/clientGenerator/utils/typeSpecUtils.js", () => ({
37+
generateTypeScriptCodeFromTypeSpec: vi.fn(),
38+
}));
39+
40+
vi.mock("../../common/utils.js", () => ({
41+
getGeneratedPackageDirectory: vi.fn(async () => "/sdk/pkg"),
42+
specifyApiVersionToGenerateSDKByTypeSpec: vi.fn(),
43+
cleanUpPackageDirectory: vi.fn(),
44+
}));
45+
46+
vi.mock("../../common/npmUtils.js", () => ({
47+
getNpmPackageInfo: vi.fn(async () => ({
48+
name: "@azure/test",
49+
version: "1.0.0-beta.1",
50+
})),
51+
}));
52+
53+
vi.mock("../../utils/logger.js", () => ({
54+
logger: {
55+
info: vi.fn(),
56+
error: vi.fn(),
57+
},
58+
}));
59+
60+
vi.mock("fs-extra", () => ({
61+
exists: vi.fn(async () => false),
62+
}));
63+
64+
vi.mock("../../common/codeOwnersAndIgnoreLink/codeOwnersAndIgnoreLinkGenerator.js", () => ({
65+
codeOwnersAndIgnoreLinkGenerator: vi.fn(),
66+
}));
67+
68+
vi.mock("../../hlc/utils/changeReadmeMd.js", () => ({
69+
changeReadmeMd: vi.fn(),
70+
}));
71+
72+
describe("generateAzureSDKPackage", () => {
73+
beforeEach(() => {
74+
mocks.calls.length = 0;
75+
mocks.packageResult.artifacts.length = 0;
76+
mocks.packageResult.path.length = 0;
77+
mocks.packageResult.result = "pending";
78+
});
79+
80+
test("reinstalls dependencies after package metadata changes", async () => {
81+
const { generateAzureSDKPackage } =
82+
await import("../../mlc/clientGenerator/modularClientPackageGenerator.js");
83+
84+
await generateAzureSDKPackage({
85+
typeSpecDirectory: "/spec/project",
86+
sdkRepoRoot: "/sdk",
87+
specRepoRoot: "/spec",
88+
runMode: "spec-pull-request",
89+
} as never);
90+
91+
expect(mocks.calls).toEqual(["build", "changelog", "install", "samples"]);
92+
});
93+
});

0 commit comments

Comments
 (0)