diff --git a/.github/workflows/end-to-end-tests.main.kts b/.github/workflows/end-to-end-tests.main.kts index 9161be00db..b611b5ca2b 100755 --- a/.github/workflows/end-to-end-tests.main.kts +++ b/.github/workflows/end-to-end-tests.main.kts @@ -201,16 +201,13 @@ workflow( env = mapOf( FIRST_NAME to "Patrick", ), - // The assertion below presents the current, undesired behavior related to - // env vars, used either from shell or GitHub Actions expressions. - // TODO: fix in https://github.com/typesafegithub/github-workflows-kt/issues/1956 command = """ cat << EOF > actual - $GREETING-$FIRST_NAME + ${expr(GREETING)}-${expr(FIRST_NAME)} EOF cat << EOF > expected - - + World-Patrick EOF diff actual expected diff --git a/.github/workflows/end-to-end-tests.yaml b/.github/workflows/end-to-end-tests.yaml index 82f84105ee..689230a2a2 100644 --- a/.github/workflows/end-to-end-tests.yaml +++ b/.github/workflows/end-to-end-tests.yaml @@ -67,7 +67,7 @@ jobs: needs: - 'check_yaml_consistency' env: - $GREETING: 'World' + GREETING: 'World' outputs: scriptKey: '${{ steps.step-21.outputs.key }}' scriptKey2: '${{ steps.step-21.outputs.key2 }}' @@ -121,23 +121,23 @@ jobs: - id: 'step-10' name: 'Custom environment variable' env: - $FIRST_NAME: 'Patrick' + FIRST_NAME: 'Patrick' run: |- cat << EOF > actual - $GREETING-$FIRST_NAME + ${{ env.GREETING }}-${{ env.FIRST_NAME }} EOF cat << EOF > expected - - + World-Patrick EOF diff actual expected - id: 'step-11' name: 'Encrypted secret' env: - $SECRET: '${{ secrets.SUPER_SECRET }}' - $TOKEN: '${{ secrets.GITHUB_TOKEN }}' - run: 'echo secret=$SECRET token=$TOKEN' + SECRET: '${{ secrets.SUPER_SECRET }}' + TOKEN: '${{ secrets.GITHUB_TOKEN }}' + run: 'echo secret=env.SECRET token=env.TOKEN' - id: 'step-12' name: 'RunnerContext create temp directory' run: 'mkdir ${{ runner.temp }}/build_logs' @@ -146,7 +146,7 @@ jobs: run: 'echo ${{ github.sha }} ev ${{ github.event.release.url }}' - id: 'step-14' name: 'Default environment variable' - run: 'action=$GITHUB_ACTION repo=$GITHUB_REPOSITORY' + run: 'action=env.GITHUB_ACTION repo=env.GITHUB_REPOSITORY' if: '${{ always() }}' - id: 'step-15' name: 'Set up JDK' diff --git a/github-workflows-kt/src/main/kotlin/io/github/typesafegithub/workflows/dsl/expressions/contexts/EnvContext.kt b/github-workflows-kt/src/main/kotlin/io/github/typesafegithub/workflows/dsl/expressions/contexts/EnvContext.kt index cea23d5611..07e5c83d8b 100644 --- a/github-workflows-kt/src/main/kotlin/io/github/typesafegithub/workflows/dsl/expressions/contexts/EnvContext.kt +++ b/github-workflows-kt/src/main/kotlin/io/github/typesafegithub/workflows/dsl/expressions/contexts/EnvContext.kt @@ -9,7 +9,6 @@ import io.github.typesafegithub.workflows.dsl.expressions.MapFromLambda */ public object EnvContext : ExpressionContext( _path = "env", - propertyToExprPath = MapFromLambda { key: String -> "\$$key" }, ) { /** Always set to true. **/ public val CI: String by propertyToExprPath diff --git a/github-workflows-kt/src/main/kotlin/io/github/typesafegithub/workflows/yaml/JobsToYaml.kt b/github-workflows-kt/src/main/kotlin/io/github/typesafegithub/workflows/yaml/JobsToYaml.kt index e6d5a4cb3f..a66ee63f1d 100644 --- a/github-workflows-kt/src/main/kotlin/io/github/typesafegithub/workflows/yaml/JobsToYaml.kt +++ b/github-workflows-kt/src/main/kotlin/io/github/typesafegithub/workflows/yaml/JobsToYaml.kt @@ -27,7 +27,7 @@ private fun Job<*>.toYaml(): Map = ) }, "needs" to needs.ifEmpty { null }?.map { it.id }, - "env" to env.ifEmpty { null }, + "env" to env.mapKeys { it.key.removePrefix("env.") }.ifEmpty { null }, "if" to condition, "strategy" to strategyMatrix?.let { diff --git a/github-workflows-kt/src/main/kotlin/io/github/typesafegithub/workflows/yaml/StepsToYaml.kt b/github-workflows-kt/src/main/kotlin/io/github/typesafegithub/workflows/yaml/StepsToYaml.kt index 1ac3bb73a1..abfb063c66 100644 --- a/github-workflows-kt/src/main/kotlin/io/github/typesafegithub/workflows/yaml/StepsToYaml.kt +++ b/github-workflows-kt/src/main/kotlin/io/github/typesafegithub/workflows/yaml/StepsToYaml.kt @@ -38,7 +38,7 @@ private fun ActionStep<*>.toYaml(): Map = } }, "with" to action.toYamlArguments().ifEmpty { null }, - "env" to env.ifEmpty { null }, + "env" to env.mapKeys { it.key.removePrefix("env.") }.ifEmpty { null }, "if" to condition, ) + _customArguments @@ -46,7 +46,7 @@ private fun CommandStep.toYaml(): Map = mapOfNotNullValues( "id" to id, "name" to name, - "env" to env.ifEmpty { null }, + "env" to env.mapKeys { it.key.removePrefix("env.") }.ifEmpty { null }, "continue-on-error" to continueOnError, "timeout-minutes" to timeoutMinutes, "shell" to shell?.toYaml(), @@ -59,7 +59,7 @@ private fun KotlinLogicStep.toYaml(): Map = mapOfNotNullValues( "id" to id, "name" to name, - "env" to env.ifEmpty { null }, + "env" to env.mapKeys { it.key.removePrefix("env.") }.ifEmpty { null }, "continue-on-error" to continueOnError, "timeout-minutes" to timeoutMinutes, "shell" to shell?.toYaml(), diff --git a/github-workflows-kt/src/test/kotlin/io/github/typesafegithub/workflows/dsl/expressions/ContextsTest.kt b/github-workflows-kt/src/test/kotlin/io/github/typesafegithub/workflows/dsl/expressions/ContextsTest.kt index 2adc518949..ca44cd6fae 100644 --- a/github-workflows-kt/src/test/kotlin/io/github/typesafegithub/workflows/dsl/expressions/ContextsTest.kt +++ b/github-workflows-kt/src/test/kotlin/io/github/typesafegithub/workflows/dsl/expressions/ContextsTest.kt @@ -11,17 +11,17 @@ class ContextsTest : test("Environment variables") { assertSoftly { val DAY_OF_WEEK by Contexts.env - "$DAY_OF_WEEK == 'Monday'" shouldBe "\$DAY_OF_WEEK == 'Monday'" + "$DAY_OF_WEEK == 'Monday'" shouldBe "env.DAY_OF_WEEK == 'Monday'" "${Contexts.env.CI} == true && ${Contexts.env.GITHUB_ACTIONS} == true" shouldBe - "\$CI == true && \$GITHUB_ACTIONS == true" + "env.CI == true && env.GITHUB_ACTIONS == true" } } test("Environment variables from expressions") { val GREETING by Contexts.env - expr { GREETING } shouldBe "\${{ GREETING }}" - expr { env.GITHUB_ACTIONS } shouldBe "\${{ GITHUB_ACTIONS }}" + expr { GREETING } shouldBe "\${{ env.GREETING }}" + expr { env.GITHUB_ACTIONS } shouldBe "\${{ env.GITHUB_ACTIONS }}" } test("Secrets") {