diff --git a/library/src/main/kotlin/it/krzeminski/githubactions/yaml/ObjectToYaml.kt b/library/src/main/kotlin/it/krzeminski/githubactions/yaml/ObjectToYaml.kt index cf4895cdd0..2c09c8e4a9 100644 --- a/library/src/main/kotlin/it/krzeminski/githubactions/yaml/ObjectToYaml.kt +++ b/library/src/main/kotlin/it/krzeminski/githubactions/yaml/ObjectToYaml.kt @@ -20,6 +20,9 @@ import java.util.Optional internal fun Any.toYaml(): String { val settings = DumpSettings.builder() + // Otherwise line breaks appear in places that create an incorrect YAML, e.g. in the middle of GitHub + // expressions. + .setWidth(Int.MAX_VALUE) .build() val writer = object : StringWriter(), StreamDataWriter { override fun flush() { diff --git a/library/src/test/kotlin/it/krzeminski/githubactions/IntegrationTest.kt b/library/src/test/kotlin/it/krzeminski/githubactions/IntegrationTest.kt index 1e1a32bf65..bcc44971c2 100644 --- a/library/src/test/kotlin/it/krzeminski/githubactions/IntegrationTest.kt +++ b/library/src/test/kotlin/it/krzeminski/githubactions/IntegrationTest.kt @@ -6,6 +6,7 @@ import io.kotest.matchers.shouldBe import it.krzeminski.githubactions.actions.actions.CheckoutV3 import it.krzeminski.githubactions.actions.actions.GithubScriptV6 import it.krzeminski.githubactions.actions.actions.SetupPythonV4 +import it.krzeminski.githubactions.actions.awsactions.ConfigureAwsCredentialsV1 import it.krzeminski.githubactions.actions.endbug.AddAndCommitV9 import it.krzeminski.githubactions.domain.Concurrency import it.krzeminski.githubactions.domain.JobOutputs @@ -451,6 +452,79 @@ class IntegrationTest : FunSpec({ """.trimIndent() } + @Suppress("MaxLineLength") + test("toYaml() - long strings with GitHub expressions in action arguments") { + // when + val actualYaml = workflow( + name = "Test workflow", + on = listOf(Push()), + sourceFile = gitRootDir.resolve(".github/workflows/some_workflow.main.kts"), + ) { + job(id = "deploy-dev", runsOn = RunnerType.UbuntuLatest) { + uses( + action = ConfigureAwsCredentialsV1( + roleToAssume = "arn:aws:iam::${"1234567890".repeat(2)}:role/github-actions-role/${"1234567890".repeat(3)}", + awsRegion = "us-west-1", + ), + ) + uses( + action = ConfigureAwsCredentialsV1( + roleToAssume = "arn:aws:iam::${"1234567890".repeat(0)}:role/github-actions-role/${expr { github.token }}", + awsRegion = "us-west-1", + ), + ) + uses( + action = ConfigureAwsCredentialsV1( + roleToAssume = "arn:aws:iam::${"1234567890".repeat(1)}:role/github-actions-role/${expr { github.token }}", + awsRegion = "us-west-1", + ), + ) + uses( + action = ConfigureAwsCredentialsV1( + roleToAssume = "arn:aws:iam::${"1234567890".repeat(2)}:role/github-actions-role/${expr { github.token }}", + awsRegion = "us-west-1", + ), + ) + } + }.toYaml(addConsistencyCheck = false) + + // then + actualYaml shouldBe """ + # This file was generated using Kotlin DSL (.github/workflows/some_workflow.main.kts). + # If you want to modify the workflow, please change the Kotlin file and regenerate this YAML file. + # Generated with https://github.com/krzema12/github-workflows-kt + + name: Test workflow + on: + push: {} + jobs: + deploy-dev: + runs-on: ubuntu-latest + steps: + - id: step-0 + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-region: us-west-1 + role-to-assume: arn:aws:iam::12345678901234567890:role/github-actions-role/123456789012345678901234567890 + - id: step-1 + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-region: us-west-1 + role-to-assume: arn:aws:iam:::role/github-actions-role/${'$'}{{ github.token }} + - id: step-2 + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-region: us-west-1 + role-to-assume: arn:aws:iam::1234567890:role/github-actions-role/${'$'}{{ github.token }} + - id: step-3 + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-region: us-west-1 + role-to-assume: arn:aws:iam::12345678901234567890:role/github-actions-role/${'$'}{{ github.token }} + + """.trimIndent() + } + test("toYaml() - with concurrency, cancel in progress") { // when val actualYaml = workflow(