Skip to content

Commit

Permalink
[#616] fix(library): don't break lines for scalars (#617)
Browse files Browse the repository at this point in the history
The default value is 80.
  • Loading branch information
krzema12 authored Jan 12, 2023
1 parent e31808a commit 276c94f
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 276c94f

Please sign in to comment.