Unverified Commit 9983057a authored by Russell Cohen's avatar Russell Cohen Committed by GitHub
Browse files

Add inital CI workflow (#12)

* Add inital CI workflow

* Run unit tests

* Run integration tests & ktlint

* Split job, set REPO_ROOT

* Update to satisfy new cargo clippy

* Upload an artifact

* Run runtime tests in CI

* Add missing test.sh

* Make script path indepdendent

* Run clippy on Rust runtime

* move artifact upload to the correct job

* Don't upload target

* Fix Rust code formatting

* Fix kotlin codestyle

* Fix merge issue
parent 6e772b9d
Loading
Loading
Loading
Loading
+113 −0
Original line number Diff line number Diff line
on: [push]

name: CI

jobs:
  style:
    name: Kotlin style checks
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Set up JDK
        uses: actions/setup-java@v1
        with:
          java-version: 8
      - uses: actions/cache@v2
        with:
          path: |
            ~/.gradle/caches
            ~/.gradle/wrapper
          key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
          restore-keys: |
            ${{ runner.os }}-gradle-
      - name: ktlint
        run: ./gradlew ktlint
  unit-tests:
    name: Codegen unit tests
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/cache@v2
        with:
          path: |
            ~/.gradle/caches
            ~/.gradle/wrapper
          key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
          restore-keys: |
            ${{ runner.os }}-gradle-
      - uses: actions/cache@v2
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
      - name: Set up JDK
        uses: actions/setup-java@v1
        with:
          java-version: 8
      - name: test
        run: ./gradlew :codegen:test
  integration-tests:
    name: Codegen integration tests
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/cache@v2
        name: Gradle Cache
        with:
          path: |
            ~/.gradle/caches
            ~/.gradle/wrapper
          key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
          restore-keys: |
            ${{ runner.os }}-gradle-
      - uses: actions/cache@v2
        name: Cargo Cache
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
      - name: Set up JDK
        uses: actions/setup-java@v1
        with:
          java-version: 8
      - name: set REPO_ROOT
        run: echo "REPO_ROOT=$GITHUB_WORKSPACE" >> $GITHUB_ENV
      - name: integration-tests
        run: ./gradlew :codegen-test:test
      # TODO: when the multi repo integration tests are merged, update this to glob all of them
      - uses: actions/upload-artifact@v2
        name: Upload Codegen Output for inspection
        # Always upload the output even if the tests failed
        if: ${{ always() }}
        with:
          name: codegen-output
          path: |
            codegen-test/build/smithyprojections/codegen-test/source/rust-codegen/
            !**/target
  runtime-tests:
    name: Rust runtime tests
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/cache@v2
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
      - name: execute runtime tests
        run: ./rust-runtime/test.sh
+4 −3
Original line number Diff line number Diff line
@@ -18,15 +18,16 @@ import software.amazon.smithy.rust.codegen.smithy.isOptional
import software.amazon.smithy.rust.codegen.smithy.rustType
import software.amazon.smithy.utils.CodeWriter

fun CodeWriter.withBlock(
fun <T : CodeWriter> T.withBlock(
    textBeforeNewLine: String,
    textAfterNewLine: String,
    conditional: Boolean = true,
    block: CodeWriter.() -> Unit
): CodeWriter {
    block: T.() -> Unit
): T {
    if (conditional) {
        openBlock(textBeforeNewLine)
    }

    block(this)
    if (conditional) {
        closeBlock(textAfterNewLine)
+2 −1
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ import software.amazon.smithy.model.traits.EnumDefinition
import software.amazon.smithy.model.traits.EnumTrait
import software.amazon.smithy.rust.codegen.lang.RustWriter
import software.amazon.smithy.rust.codegen.lang.rustBlock
import software.amazon.smithy.rust.codegen.lang.withBlock
import software.amazon.smithy.rust.codegen.smithy.RuntimeType
import software.amazon.smithy.rust.codegen.util.doubleQuote

@@ -48,7 +49,7 @@ class EnumGenerator(
                write("&self.0")
            }

            writer.rustBlock("pub fn ${Values}() -> &'static [&'static str]") {
            writer.rustBlock("pub fn $Values() -> &'static [&'static str]") {
                withBlock("&[", "]") {
                    val memberList = sortedMembers.joinToString(", ") { it.value.doubleQuote() }
                    write(memberList)
+1 −1
Original line number Diff line number Diff line
@@ -89,7 +89,7 @@ class EnumGeneratorTest {
        val shape = model.expectShape(ShapeId.from("test#FooEnum"), StringShape::class.java)
        val trait = shape.expectTrait(EnumTrait::class.java)
        val provider: SymbolProvider = SymbolVisitor(model, "test")
        val writer = RustWriter("model.rs", "model")
        val writer = RustWriter.forModule("model")
        val generator = EnumGenerator(provider, writer, shape, trait)
        generator.render()
        writer.shouldCompile("""
+0 −1
Original line number Diff line number Diff line
@@ -104,7 +104,6 @@ class StructureGeneratorTest {
            assert_eq!(my_struct.bar, 0);
        """
        )

    }

    @Test
Loading