From b1829759e2715ff30bf31f204214d7587c16950e Mon Sep 17 00:00:00 2001 From: Chase Coalwell <782571+srchase@users.noreply.github.com> Date: Mon, 4 Dec 2023 10:48:17 -0700 Subject: [PATCH] Test client generated from released codegenerator (#1094) --- scripts/build-generated-test-packages.js | 32 +++++++++++++---- settings.gradle.kts | 1 + .../build.gradle.kts | 2 -- .../released-version-test/build.gradle.kts | 35 +++++++++++++++++++ .../released-version-test/smithy-build.json | 14 ++++++++ 5 files changed, 75 insertions(+), 9 deletions(-) create mode 100644 smithy-typescript-codegen-test/released-version-test/build.gradle.kts create mode 100644 smithy-typescript-codegen-test/released-version-test/smithy-build.json diff --git a/scripts/build-generated-test-packages.js b/scripts/build-generated-test-packages.js index df665e9c3fd..65c378b8bb7 100644 --- a/scripts/build-generated-test-packages.js +++ b/scripts/build-generated-test-packages.js @@ -9,9 +9,13 @@ const { spawnProcess } = require("./utils/spawn-process"); const root = path.join(__dirname, ".."); -const codegenTestDir = path.join( +const testProjectDir = path.join( root, "smithy-typescript-codegen-test", +); + +const codegenTestDir = path.join( + testProjectDir, "build", "smithyprojections", "smithy-typescript-codegen-test", @@ -23,6 +27,16 @@ const weatherClientDir = path.join( "typescript-client-codegen" ); +const releasedClientDir = path.join( + testProjectDir, + "released-version-test", + "build", + "smithyprojections", + "released-version-test", + "source", + "typescript-codegen" +); + // TODO(experimentalIdentityAndAuth): build generic client for integration tests const weatherExperimentalIdentityAndAuthClientDir = path.join( codegenTestDir, @@ -61,13 +75,15 @@ const buildAndCopyToNodeModules = async (packageName, codegenDir, nodeModulesDir await spawnProcess("touch", ["yarn.lock"], { cwd: codegenDir }); await spawnProcess("yarn", { cwd: codegenDir }); await spawnProcess("yarn", ["build"], { cwd: codegenDir }); - // After building the package, it's packed and copied to node_modules so that + // Optionally, after building the package, it's packed and copied to node_modules so that // it can be used in integration tests by other packages within the monorepo. - await spawnProcess("yarn", ["pack"], { cwd: codegenDir }); - await spawnProcess("rm", ["-rf", packageName], { cwd: nodeModulesDir }); - await spawnProcess("mkdir", ["-p", packageName], { cwd: nodeModulesDir }); - const targetPackageDir = path.join(nodeModulesDir, packageName); - await spawnProcess("tar", ["-xf", "package.tgz", "-C", targetPackageDir, "--strip-components", "1"], { cwd: codegenDir }); + if (nodeModulesDir != undefined) { + await spawnProcess("yarn", ["pack"], { cwd: codegenDir }); + await spawnProcess("rm", ["-rf", packageName], { cwd: nodeModulesDir }); + await spawnProcess("mkdir", ["-p", packageName], { cwd: nodeModulesDir }); + const targetPackageDir = path.join(nodeModulesDir, packageName); + await spawnProcess("tar", ["-xf", "package.tgz", "-C", targetPackageDir, "--strip-components", "1"], { cwd: codegenDir }); + } } catch (e) { console.log(`Building and copying package \`${packageName}\` in \`${codegenDir}\` to \`${nodeModulesDir}\` failed:`) console.log(e); @@ -84,4 +100,6 @@ const buildAndCopyToNodeModules = async (packageName, codegenDir, nodeModulesDir await buildAndCopyToNodeModules("@smithy/identity-and-auth-http-api-key-auth-service", httpApiKeyAuthClientDir, nodeModulesDir); // TODO(experimentalIdentityAndAuth): add `@httpBearerAuth` client for integration tests await buildAndCopyToNodeModules("@smithy/identity-and-auth-http-bearer-auth-service", httpBearerAuthClientDir, nodeModulesDir); + // Test released version of smithy-typescript codegenerators, but + await buildAndCopyToNodeModules("released", releasedClientDir, undefined); })(); diff --git a/settings.gradle.kts b/settings.gradle.kts index c04c07472c3..a9336100df0 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -20,6 +20,7 @@ rootProject.name = "smithy-typescript" include(":smithy-typescript-codegen") include(":smithy-typescript-codegen-test") include(":smithy-typescript-codegen-test:example-weather-customizations") +include(":smithy-typescript-codegen-test:released-version-test") include(":smithy-typescript-ssdk-codegen-test-utils") file( diff --git a/smithy-typescript-codegen-test/build.gradle.kts b/smithy-typescript-codegen-test/build.gradle.kts index a273ccf91a7..b6a0f49c848 100644 --- a/smithy-typescript-codegen-test/build.gradle.kts +++ b/smithy-typescript-codegen-test/build.gradle.kts @@ -16,8 +16,6 @@ extra["displayName"] = "Smithy :: Typescript :: Codegen :: Test" extra["moduleName"] = "software.amazon.smithy.typescript.codegen.test" -tasks["jar"].enabled = false - val smithyVersion: String by project buildscript { diff --git a/smithy-typescript-codegen-test/released-version-test/build.gradle.kts b/smithy-typescript-codegen-test/released-version-test/build.gradle.kts new file mode 100644 index 00000000000..b4a2cd57b75 --- /dev/null +++ b/smithy-typescript-codegen-test/released-version-test/build.gradle.kts @@ -0,0 +1,35 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +tasks["jar"].enabled = false + +val smithyVersion: String by project +val version: String by project + +buildscript { + val smithyVersion: String by project + + repositories { + mavenCentral() + } + dependencies { + "classpath"("software.amazon.smithy:smithy-cli:$smithyVersion") + } +} + +plugins { + id("software.amazon.smithy") +} + +repositories { + mavenCentral() +} + +dependencies { + implementation("software.amazon.smithy.typescript:smithy-typescript-codegen:$version!!") + implementation("software.amazon.smithy.typescript:smithy-aws-typescript-codegen:$version!!") + implementation(project(":smithy-typescript-codegen-test")) + implementation(project(":smithy-typescript-codegen-test:example-weather-customizations")) +} diff --git a/smithy-typescript-codegen-test/released-version-test/smithy-build.json b/smithy-typescript-codegen-test/released-version-test/smithy-build.json new file mode 100644 index 00000000000..1a08e559353 --- /dev/null +++ b/smithy-typescript-codegen-test/released-version-test/smithy-build.json @@ -0,0 +1,14 @@ +{ + "version": "1.0", + "plugins": { + "typescript-codegen": { + "service": "example.weather#Weather", + "package": "weather", + "packageVersion": "0.0.1", + "packageJson": { + "license": "Apache-2.0", + "private": true + } + } + } +}