From 4c4bf116b45e26db4c20140e743d6e6347807a59 Mon Sep 17 00:00:00 2001 From: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Date: Thu, 24 Aug 2023 12:16:30 -0700 Subject: [PATCH] chore(scripts): build smithy-typescript from specific commit during codegen (#5139) Co-authored-by: Steven Yuan --- .../build-smithy-typescript.js | 32 +++++++++++++++++++ scripts/generate-clients/index.js | 15 ++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 scripts/generate-clients/build-smithy-typescript.js diff --git a/scripts/generate-clients/build-smithy-typescript.js b/scripts/generate-clients/build-smithy-typescript.js new file mode 100644 index 000000000000..8795265b4b7d --- /dev/null +++ b/scripts/generate-clients/build-smithy-typescript.js @@ -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]); + } + + // 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 }; diff --git a/scripts/generate-clients/index.js b/scripts/generate-clients/index.js index d4bcca1cc740..3faf715e223c 100644 --- a/scripts/generate-clients/index.js +++ b/scripts/generate-clients/index.js @@ -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")); @@ -26,6 +28,8 @@ const { s: serverOnly, batchSize, keepFiles, + repo, + commit, } = yargs(process.argv.slice(2)) .alias("m", "models") .string("m") @@ -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();