Skip to content

Commit bb79dde

Browse files
authored
feat(library): add the vars context (#1961)
Fixes #1955
1 parent c7907e9 commit bb79dde

File tree

5 files changed

+45
-0
lines changed

5 files changed

+45
-0
lines changed

github-workflows-kt/api/github-workflows-kt.api

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1978,6 +1978,7 @@ public final class io/github/typesafegithub/workflows/dsl/expressions/Contexts :
19781978
public final fun getGithub ()Lio/github/typesafegithub/workflows/dsl/expressions/contexts/GitHubContext;
19791979
public final fun getRunner ()Lio/github/typesafegithub/workflows/dsl/expressions/contexts/RunnerContext;
19801980
public final fun getSecrets ()Lio/github/typesafegithub/workflows/dsl/expressions/contexts/SecretsContext;
1981+
public final fun getVars ()Lio/github/typesafegithub/workflows/dsl/expressions/contexts/VarsContext;
19811982
}
19821983

19831984
public class io/github/typesafegithub/workflows/dsl/expressions/ExpressionContext : java/util/Map, kotlin/jvm/internal/markers/KMappedMarker {
@@ -3021,6 +3022,10 @@ public final class io/github/typesafegithub/workflows/dsl/expressions/contexts/S
30213022
public final fun getGITHUB_TOKEN ()Ljava/lang/String;
30223023
}
30233024

3025+
public final class io/github/typesafegithub/workflows/dsl/expressions/contexts/VarsContext : io/github/typesafegithub/workflows/dsl/expressions/ExpressionContext {
3026+
public static final field INSTANCE Lio/github/typesafegithub/workflows/dsl/expressions/contexts/VarsContext;
3027+
}
3028+
30243029
public final class io/github/typesafegithub/workflows/dsl/expressions/contexts/WorkflowDispatchEvent {
30253030
public static final field INSTANCE Lio/github/typesafegithub/workflows/dsl/expressions/contexts/WorkflowDispatchEvent;
30263031
public static final field ref Ljava/lang/String;

github-workflows-kt/src/main/kotlin/io/github/typesafegithub/workflows/dsl/expressions/Contexts.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import io.github.typesafegithub.workflows.dsl.expressions.contexts.FunctionsCont
55
import io.github.typesafegithub.workflows.dsl.expressions.contexts.GitHubContext
66
import io.github.typesafegithub.workflows.dsl.expressions.contexts.RunnerContext
77
import io.github.typesafegithub.workflows.dsl.expressions.contexts.SecretsContext
8+
import io.github.typesafegithub.workflows.dsl.expressions.contexts.VarsContext
89

910
/**
1011
* Root elements of GitHub expressions.
@@ -17,4 +18,5 @@ public object Contexts : FunctionsContext() {
1718
public val github: GitHubContext = GitHubContext
1819
public val runner: RunnerContext = RunnerContext
1920
public val secrets: SecretsContext = SecretsContext
21+
public val vars: VarsContext = VarsContext
2022
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package io.github.typesafegithub.workflows.dsl.expressions.contexts
2+
3+
import io.github.typesafegithub.workflows.dsl.expressions.ExpressionContext
4+
5+
/**
6+
* Vars
7+
*
8+
* Vars allow you to store configuration variables in your organization, repository, or repository environments.
9+
*
10+
* https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/accessing-contextual-information-about-workflow-runs#vars-context
11+
*/
12+
public object VarsContext : ExpressionContext("vars")

github-workflows-kt/src/test/kotlin/io/github/typesafegithub/workflows/docsnippets/TypeSafeExpressionsSnippets.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,23 @@ class TypeSafeExpressionsSnippets :
103103
// --8<-- [end:secrets]
104104
}
105105
}
106+
107+
test("vars") {
108+
workflow(
109+
name = "Test workflow",
110+
on = listOf(Push()),
111+
sourceFile = sourceTempFile,
112+
) {
113+
// --8<-- [start:secrets]
114+
val SOME_VARIABLE by Contexts.vars
115+
116+
job(id = "job1", runsOn = RunnerType.UbuntuLatest) {
117+
run(
118+
name = "Some Variable",
119+
command = "echo someVariable=${expr { SOME_VARIABLE }}",
120+
)
121+
}
122+
// --8<-- [end:secrets]
123+
}
124+
}
106125
})

github-workflows-kt/src/test/kotlin/io/github/typesafegithub/workflows/dsl/expressions/ContextsTest.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ class ContextsTest :
3333
}
3434
}
3535

36+
test("Vars") {
37+
assertSoftly {
38+
val SOME_VARIABLE by Contexts.vars
39+
expr { SOME_VARIABLE } shouldBe expr("vars.SOME_VARIABLE")
40+
}
41+
}
42+
3643
test("Runner context") {
3744
assertSoftly {
3845
expr { runner.name } shouldBe expr("runner.name")

0 commit comments

Comments
 (0)