Skip to content
This repository was archived by the owner on May 22, 2026. It is now read-only.

Commit 44b5fd0

Browse files
committed
Merge branch 'autorestv3' of https://github.com/Azure/autorest.python into add_storage
* 'autorestv3' of https://github.com/Azure/autorest.python: fail on regeneration diff (#1173)
2 parents 67fa5e2 + 2ca272a commit 44b5fd0

3 files changed

Lines changed: 108 additions & 4 deletions

File tree

eng/pipelines/ci.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,8 @@ jobs:
8383
- script: |
8484
inv regenerate
8585
displayName: 'Regenerate Code'
86-
- script: |
87-
git add -A # 'add' first so 'diff' includes untracked files
88-
git diff --staged -w
89-
displayName: 'Diff regeneration'
86+
- script: node ./eng/scripts/check-for-changed-files.js
87+
displayName: Fail on regeneration diff
9088
- task: UsePythonVersion@0
9189
displayName: 'Use Python $(PythonVersion)'
9290
inputs:
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// @ts-check
2+
3+
const { run } = require("./helpers.js");
4+
5+
const proc = run("git", ["status", "--porcelain"], {
6+
encoding: "utf-8",
7+
stdio: [null, "pipe", "pipe"],
8+
});
9+
10+
if (proc.stdout) {
11+
console.log(proc.stdout);
12+
}
13+
14+
if (proc.stderr) {
15+
console.error(proc.stderr);
16+
}
17+
18+
if (proc.stdout || proc.stderr) {
19+
console.error(
20+
`ERROR: There are diffs in regeneration. Please run 'inv regenerate' and re-run. You may also have to remove 'node_modules' and re-run 'npm install' to get the latest testserver.`,
21+
);
22+
process.exit(1);
23+
}

eng/scripts/helpers.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// @ts-check
2+
const { spawn, spawnSync } = require("child_process");
3+
const { resolve } = require("path");
4+
5+
const repoRoot = resolve(__dirname, "../..");
6+
const prettier = resolve(
7+
repoRoot,
8+
"packages/extensions/core/node_modules/.bin/prettier"
9+
);
10+
const tsc = resolve(repoRoot, "packages/extensions/core/node_modules/.bin/tsc");
11+
12+
const isCmdOnWindows = ["rush", "npm", "code", "code-insiders", tsc, prettier];
13+
14+
function run(command, args, options) {
15+
console.log();
16+
console.log(`> ${command} ${args.join(" ")}`);
17+
18+
options = {
19+
stdio: "inherit",
20+
sync: true,
21+
throwOnNonZeroExit: true,
22+
...options,
23+
};
24+
25+
if (process.platform === "win32" && isCmdOnWindows.includes(command)) {
26+
command += ".cmd";
27+
}
28+
29+
const proc = (options.sync ? spawnSync : spawn)(command, args, options);
30+
if (proc.error) {
31+
if (options.ignoreCommandNotFound && proc.error.code === "ENOENT") {
32+
console.log(`Skipped: Command \`${command}\` not found.`);
33+
} else {
34+
throw proc.error;
35+
}
36+
} else if (
37+
options.throwOnNonZeroExit &&
38+
proc.status !== undefined &&
39+
proc.status !== 0
40+
) {
41+
throw new CommandFailedError(
42+
`Command \`${command} ${args.join(" ")}\` failed with exit code ${
43+
proc.status
44+
}`,
45+
proc
46+
);
47+
}
48+
49+
return proc;
50+
}
51+
52+
class CommandFailedError extends Error {
53+
constructor(msg, proc) {
54+
super(msg);
55+
this.proc = proc;
56+
}
57+
}
58+
59+
function runPrettier(...args) {
60+
run(
61+
prettier,
62+
[
63+
...args,
64+
"--config",
65+
".prettierrc.yml",
66+
"--ignore-path",
67+
".prettierignore",
68+
"**/*.{ts,js,cjs,mjs,json,yml,yaml,cadl,md}",
69+
],
70+
{
71+
cwd: repoRoot,
72+
}
73+
);
74+
}
75+
76+
module.exports = {
77+
repoRoot,
78+
prettier,
79+
tsc,
80+
run,
81+
runPrettier,
82+
CommandFailedError,
83+
};

0 commit comments

Comments
 (0)