Skip to content

Commit

Permalink
chore(scripts): build smithy-typescript from specific commit during c…
Browse files Browse the repository at this point in the history
…odegen (#5139)

Co-authored-by: Steven Yuan <s.yuan.all@gmail.com>
  • Loading branch information
trivikr and syall authored Aug 24, 2023
1 parent eb91cee commit 4c4bf11
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
32 changes: 32 additions & 0 deletions scripts/generate-clients/build-smithy-typescript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// @ts-check
const { access, rm } = require("fs/promises");
const { spawnProcess } = require("../utils/spawn-process");

const buildSmithyTypeScript = async (repo, commit) => {
let deleteSmithyTsRepo = false;

// Check out smithy-typescript at repo, if it does not exist.
try {
await access(repo);
} catch (error) {
deleteSmithyTsRepo = true;
await spawnProcess("git", ["clone", "https://github.com/awslabs/smithy-typescript.git", repo]);

This comment has been minimized.

Copy link
@trivikr

trivikr Aug 30, 2023

Author Member

ToDo: The smithy-typescript repo can be shallow cloned from commit here

This comment has been minimized.

Copy link
@trivikr

trivikr Aug 31, 2023

Author Member

Done in #5159

}

// Checkout commit
const tempBranchName = `temp-${commit}`;
await spawnProcess("git", ["checkout", "-b", tempBranchName, commit], { cwd: repo });

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

if (deleteSmithyTsRepo) {
await rm(repo, { recursive: true, force: true });
} else {
// Delete temp branch
await spawnProcess("git", ["checkout", "main"], { cwd: repo });
await spawnProcess("git", ["branch", "-D", tempBranchName], { cwd: repo });
}
};

module.exports = { buildSmithyTypeScript };
15 changes: 14 additions & 1 deletion scripts/generate-clients/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ const {
} = require("./code-gen-dir");
const { prettifyCode } = require("./code-prettify");
const { eslintFixCode } = require("./code-eslint-fix");
const { buildSmithyTypeScript } = require("./build-smithy-typescript");

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

Expand All @@ -26,6 +28,8 @@ const {
s: serverOnly,
batchSize,
keepFiles,
repo,
commit,
} = yargs(process.argv.slice(2))
.alias("m", "models")
.string("m")
Expand All @@ -51,11 +55,20 @@ const {
.number("b")
.alias("b", "batch-size")
.default("b", 50)
.describe("r", "The location where smithy-typescript is cloned.")
.string("r")
.alias("r", "repo")
.default("r", SMITHY_TS_DIR)
.describe("c", "The smithy-typescript commit to be used for codegen.")
.string("c")
.alias("c", "commit")
.default("c", "HEAD") // ToDo: Change to a specific commit once CI is updated.
.help().argv;

(async () => {
try {
require('../runtime-dependency-version-check/runtime-dep-version-check');
require("../runtime-dependency-version-check/runtime-dep-version-check");
await buildSmithyTypeScript(repo, commit);

if (serverOnly === true) {
await generateProtocolTests();
Expand Down

0 comments on commit 4c4bf11

Please sign in to comment.