Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions .github/workflows/end-to-end-tests.main.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/end-to-end-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}'
Expand Down Expand Up @@ -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'
Expand All @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private fun Job<*>.toYaml(): Map<String, Any?> =
)
},
"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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ private fun ActionStep<*>.toYaml(): Map<String, Any?> =
}
},
"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

private fun CommandStep.toYaml(): Map<String, Any?> =
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(),
Expand All @@ -59,7 +59,7 @@ private fun KotlinLogicStep.toYaml(): Map<String, Any?> =
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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
Loading