From e6ff1c6307441e23e0622a4d77a6a4fc392667b9 Mon Sep 17 00:00:00 2001 From: Adam Thomas Date: Wed, 6 Oct 2021 14:45:07 -0700 Subject: [PATCH] feat(codegen): test non-AWS client builds Generate a non-AWS client and add a GitHub action that verifies that it will compile. --- .github/workflows/generic-client-tests.yml | 40 +++++++++++++++ .../build.gradle.kts | 39 ++++++++++++++ .../model/echo.smithy | 51 +++++++++++++++++++ .../smithy-build.json | 30 +++++++++++ codegen/settings.gradle.kts | 1 + 5 files changed, 161 insertions(+) create mode 100644 .github/workflows/generic-client-tests.yml create mode 100644 codegen/generic-client-test-codegen/build.gradle.kts create mode 100644 codegen/generic-client-test-codegen/model/echo.smithy create mode 100644 codegen/generic-client-test-codegen/smithy-build.json diff --git a/.github/workflows/generic-client-tests.yml b/.github/workflows/generic-client-tests.yml new file mode 100644 index 000000000000..07896b67ebdd --- /dev/null +++ b/.github/workflows/generic-client-tests.yml @@ -0,0 +1,40 @@ +name: generic-client-tests + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - uses: actions/setup-java@v1 + with: + java-version: '11' + + - uses: actions/setup-node@v2 + with: + node-version: '14' + cache: 'yarn' + + - name: build and publish smithy-typescript + run: | + git clone --depth 1 /~https://github.com/awslabs/smithy-typescript.git + cd smithy-typescript + ./gradlew clean build publishToMavenLocal + cd .. + + - name: build codegen and generate generic client + run: | + cd codegen + ./gradlew clean smithy-aws-typescript-codegen:build generic-client-test-codegen:build + + - name: build generic client + run: | + cd codegen/generic-client-test-codegen/build/smithyprojections/generic-client-test-codegen/aws-echo-service/typescript-codegen/ + yarn install && yarn build diff --git a/codegen/generic-client-test-codegen/build.gradle.kts b/codegen/generic-client-test-codegen/build.gradle.kts new file mode 100644 index 000000000000..2440e1c79b95 --- /dev/null +++ b/codegen/generic-client-test-codegen/build.gradle.kts @@ -0,0 +1,39 @@ +/* + * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +import software.amazon.smithy.gradle.tasks.SmithyBuild + +plugins { + id("software.amazon.smithy") version "0.5.3" +} + +dependencies { + implementation("software.amazon.smithy:smithy-aws-protocol-tests:[1.11.0, 1.12.0[") + implementation(project(":smithy-aws-typescript-codegen")) +} + +// This project doesn't produce a JAR. +tasks["jar"].enabled = false + +// Run the SmithyBuild task manually since this project needs the built JAR +// from smithy-aws-typescript-codegen. +tasks["smithyBuildJar"].enabled = false + +tasks.create("buildSdk") { + addRuntimeClasspath = true +} + +// Run the `buildSdk` automatically. +tasks["build"].finalizedBy(tasks["buildSdk"]) diff --git a/codegen/generic-client-test-codegen/model/echo.smithy b/codegen/generic-client-test-codegen/model/echo.smithy new file mode 100644 index 000000000000..c062557d7888 --- /dev/null +++ b/codegen/generic-client-test-codegen/model/echo.smithy @@ -0,0 +1,51 @@ +$version: "1.0" + +namespace aws.test.generic + +use aws.protocols#restJson1 + +@restJson1 +service EchoService { + version: "2018-05-10", + operations: [Echo, Length], +} + +@http(code: 200, method: "POST", uri: "/echo",) +operation Echo { + input: EchoInput, + output: EchoOutput, + errors: [PalindromeException], +} + +@readonly +@http(code: 200, method: "GET", uri: "/length/{string}") +operation Length { + input: LengthInput, + output: LengthOutput, + errors: [PalindromeException], +} + +structure EchoInput { + string: String, +} + +structure EchoOutput { + string: String, +} + +structure LengthInput { + @required + @httpLabel + string: String, +} + +structure LengthOutput { + length: Integer, +} + +/// For some reason, this service does not like palindromes! +@httpError(400) +@error("client") +structure PalindromeException { + message: String, +} diff --git a/codegen/generic-client-test-codegen/smithy-build.json b/codegen/generic-client-test-codegen/smithy-build.json new file mode 100644 index 000000000000..33ca19c221a9 --- /dev/null +++ b/codegen/generic-client-test-codegen/smithy-build.json @@ -0,0 +1,30 @@ +{ + "version": "1.0", + "imports": ["model/echo.smithy"], + "projections": { + "aws-echo-service": { + "transforms": [ + { + "name": "includeServices", + "args": { + "services": ["aws.test.generic#EchoService"] + } + } + ], + "plugins": { + "typescript-codegen": { + "package": "@aws-sdk/aws-echo-service", + "packageVersion": "1.0.0-alpha.1", + "packageJson": { + "author": { + "name": "AWS SDK for JavaScript Team", + "url": "https://aws.amazon.com/javascript/" + }, + "license": "Apache-2.0" + }, + "private": true + } + } + } + } +} diff --git a/codegen/settings.gradle.kts b/codegen/settings.gradle.kts index 919c108ee7b6..176d20e8eeb7 100644 --- a/codegen/settings.gradle.kts +++ b/codegen/settings.gradle.kts @@ -17,3 +17,4 @@ rootProject.name = "codegen" include(":smithy-aws-typescript-codegen") include(":sdk-codegen") include(":protocol-test-codegen") +include(":generic-client-test-codegen")