Skip to content

Commit 4c4bf11

Browse files
trivikrsyall
andauthored
chore(scripts): build smithy-typescript from specific commit during codegen (#5139)
Co-authored-by: Steven Yuan <[email protected]>
1 parent eb91cee commit 4c4bf11

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// @ts-check
2+
const { access, rm } = require("fs/promises");
3+
const { spawnProcess } = require("../utils/spawn-process");
4+
5+
const buildSmithyTypeScript = async (repo, commit) => {
6+
let deleteSmithyTsRepo = false;
7+
8+
// Check out smithy-typescript at repo, if it does not exist.
9+
try {
10+
await access(repo);
11+
} catch (error) {
12+
deleteSmithyTsRepo = true;
13+
await spawnProcess("git", ["clone", "https://github.com/awslabs/smithy-typescript.git", repo]);
14+
}
15+
16+
// Checkout commit
17+
const tempBranchName = `temp-${commit}`;
18+
await spawnProcess("git", ["checkout", "-b", tempBranchName, commit], { cwd: repo });
19+
20+
// Build smithy-typescript and publish to maven local
21+
await spawnProcess("./gradlew", ["clean", "publishToMavenLocal"], { cwd: repo });
22+
23+
if (deleteSmithyTsRepo) {
24+
await rm(repo, { recursive: true, force: true });
25+
} else {
26+
// Delete temp branch
27+
await spawnProcess("git", ["checkout", "main"], { cwd: repo });
28+
await spawnProcess("git", ["branch", "-D", tempBranchName], { cwd: repo });
29+
}
30+
};
31+
32+
module.exports = { buildSmithyTypeScript };

scripts/generate-clients/index.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ const {
1414
} = require("./code-gen-dir");
1515
const { prettifyCode } = require("./code-prettify");
1616
const { eslintFixCode } = require("./code-eslint-fix");
17+
const { buildSmithyTypeScript } = require("./build-smithy-typescript");
1718

19+
const SMITHY_TS_DIR = path.normalize(path.join(__dirname, "..", "..", "..", "smithy-typescript"));
1820
const SDK_CLIENTS_DIR = path.normalize(path.join(__dirname, "..", "..", "clients"));
1921
const PRIVATE_CLIENTS_DIR = path.normalize(path.join(__dirname, "..", "..", "private"));
2022

@@ -26,6 +28,8 @@ const {
2628
s: serverOnly,
2729
batchSize,
2830
keepFiles,
31+
repo,
32+
commit,
2933
} = yargs(process.argv.slice(2))
3034
.alias("m", "models")
3135
.string("m")
@@ -51,11 +55,20 @@ const {
5155
.number("b")
5256
.alias("b", "batch-size")
5357
.default("b", 50)
58+
.describe("r", "The location where smithy-typescript is cloned.")
59+
.string("r")
60+
.alias("r", "repo")
61+
.default("r", SMITHY_TS_DIR)
62+
.describe("c", "The smithy-typescript commit to be used for codegen.")
63+
.string("c")
64+
.alias("c", "commit")
65+
.default("c", "HEAD") // ToDo: Change to a specific commit once CI is updated.
5466
.help().argv;
5567

5668
(async () => {
5769
try {
58-
require('../runtime-dependency-version-check/runtime-dep-version-check');
70+
require("../runtime-dependency-version-check/runtime-dep-version-check");
71+
await buildSmithyTypeScript(repo, commit);
5972

6073
if (serverOnly === true) {
6174
await generateProtocolTests();

0 commit comments

Comments
 (0)