Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(scripts): build smithy-typescript from specific commit during codegen #5139

Merged
merged 4 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]);
}

// 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 codeden.")
trivikr marked this conversation as resolved.
Show resolved Hide resolved
.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