Skip to content

Commit 899eb5c

Browse files
authored
chore(scripts): add codegen flag for PR creation (#7920)
1 parent 314b203 commit 899eb5c

2 files changed

Lines changed: 38 additions & 5 deletions

File tree

scripts/generate-clients/build-smithy-typescript.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,23 @@
22
const { access, rm } = require("node:fs/promises");
33
const { spawnProcess } = require("../utils/spawn-process");
44

5+
/**
6+
* @param {string} repo
7+
* @param {string} commit
8+
*/
59
const buildSmithyTypeScript = async (repo, commit) => {
10+
await runWithSpecificSmithyTypeScriptVersion(repo, commit, async () => {
11+
// Build smithy-typescript and publish to maven local
12+
await spawnProcess("./gradlew", ["clean", "publishToMavenLocal"], { cwd: repo });
13+
});
14+
};
15+
16+
/**
17+
* @param {string} repo
18+
* @param {string} commit
19+
* @param {Function} task
20+
*/
21+
const runWithSpecificSmithyTypeScriptVersion = async (repo, commit, task) => {
622
let deleteSmithyTsRepo = false;
723

824
// Check out smithy-typescript at repo, if it does not exist.
@@ -31,8 +47,7 @@ const buildSmithyTypeScript = async (repo, commit) => {
3147
}
3248
await spawnProcess("git", ["checkout", "-b", tempBranchName, commit], { cwd: repo });
3349

34-
// Build smithy-typescript and publish to maven local
35-
await spawnProcess("./gradlew", ["clean", "publishToMavenLocal"], { cwd: repo });
50+
await task();
3651

3752
if (deleteSmithyTsRepo) {
3853
await rm(repo, { recursive: true, force: true });
@@ -43,4 +58,4 @@ const buildSmithyTypeScript = async (repo, commit) => {
4358
}
4459
};
4560

46-
module.exports = { buildSmithyTypeScript };
61+
module.exports = { buildSmithyTypeScript, runWithSpecificSmithyTypeScriptVersion };

scripts/generate-clients/index.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ const {
1212
DEFAULT_CODE_GEN_INPUT_DIR,
1313
TEMP_CODE_GEN_INPUT_DIR,
1414
} = require("./code-gen-dir");
15-
const { buildSmithyTypeScript } = require("./build-smithy-typescript");
15+
const { buildSmithyTypeScript, runWithSpecificSmithyTypeScriptVersion } = require("./build-smithy-typescript");
1616
const { SMITHY_TS_COMMIT } = require("./config");
1717
const { spawnProcess } = require("../utils/spawn-process");
1818

1919
const REPO_ROOT = path.join(__dirname, "..", "..");
2020
const SMITHY_TS_DIR = path.normalize(path.join(__dirname, "..", "..", "..", "smithy-typescript"));
2121
const SDK_CLIENTS_DIR = path.normalize(path.join(__dirname, "..", "..", "clients"));
2222
const PRIVATE_CLIENTS_DIR = path.normalize(path.join(__dirname, "..", "..", "private"));
23+
const start = Date.now();
2324

2425
const {
2526
models,
@@ -33,6 +34,7 @@ const {
3334
commit,
3435
d: noSmithyCheckout,
3536
p: protocolTestsOnly,
37+
x: pullRequest,
3638
} = yargs(process.argv.slice(2))
3739
.alias("m", "models")
3840
.string("m")
@@ -51,6 +53,9 @@ const {
5153
.alias("d", "noSmithyCheckout")
5254
.boolean("d")
5355
.describe("d", "use existing Smithy version instead of target hash")
56+
.alias("x", "pullRequest")
57+
.boolean("x")
58+
.describe("x", "command was invoked by developer creating a pull request")
5459
.alias("p", "protocolTestsOnly")
5560
.boolean("p")
5661
.describe("p", "Generate protocol tests only")
@@ -129,7 +134,15 @@ const {
129134
await generateNestedClients();
130135
}
131136

132-
require("../runtime-dependency-version-check/runtime-dep-version-check");
137+
if (!noSmithyCheckout && pullRequest) {
138+
await runWithSpecificSmithyTypeScriptVersion(repo, commit, async () => {
139+
process.argv.push("--set-smithy-version");
140+
require("../runtime-dependency-version-check/runtime-dep-version-check");
141+
});
142+
} else {
143+
require("../runtime-dependency-version-check/runtime-dep-version-check");
144+
}
145+
133146
await spawnProcess("yarn", ["install", "--no-immutable"], {
134147
cwd: REPO_ROOT,
135148
stdio: "inherit",
@@ -141,6 +154,11 @@ const {
141154
stdio: "inherit",
142155
env: { ...process.env },
143156
});
157+
158+
if (!noSmithyCheckout && pullRequest) {
159+
const end = Date.now();
160+
console.log(`Codegen completed in ${((end - start) / 1000) | 0}s. Run git commit.`);
161+
}
144162
} catch (e) {
145163
console.log(e);
146164
process.exit(1);

0 commit comments

Comments
 (0)