diff options
author | Kuan Yong <wong0514@gmail.com> | 2023-06-10 20:09:27 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-10 20:09:27 +0200 |
commit | 6ce45e3f246f12d6617691de9a2423920d5fdbe6 (patch) | |
tree | 83595e5981a6bf59c28045b3ceb06d619caf3389 /pkg/runner | |
parent | Fix bug in processing jobs on platforms without Docker (#1834) (diff) | |
download | forgejo-act-6ce45e3f246f12d6617691de9a2423920d5fdbe6.tar.xz forgejo-act-6ce45e3f246f12d6617691de9a2423920d5fdbe6.zip |
feature: Add support for github action variables (#1833)
* feature: Add support for github action variables
* add --var flag for github variables
* unitests: Updated unittests to cover vars context.
* Remove syntax extension for vars and correct unit tests
* Update pkg/runner/expression.go
Co-authored-by: ChristopherHX <christopher.homberger@web.de>
---------
Co-authored-by: kuanyong-wong-partior <kuanyong.wong@partior.com>
Co-authored-by: ChristopherHX <christopher.homberger@web.de>
Diffstat (limited to 'pkg/runner')
-rw-r--r-- | pkg/runner/expression.go | 6 | ||||
-rw-r--r-- | pkg/runner/expression_test.go | 10 | ||||
-rw-r--r-- | pkg/runner/runner.go | 1 |
3 files changed, 17 insertions, 0 deletions
diff --git a/pkg/runner/expression.go b/pkg/runner/expression.go index 111274b..cc144af 100644 --- a/pkg/runner/expression.go +++ b/pkg/runner/expression.go @@ -77,6 +77,7 @@ func (rc *RunContext) NewExpressionEvaluatorWithEnv(ctx context.Context, env map // but required to interpolate/evaluate the step outputs on the job Steps: rc.getStepsContext(), Secrets: getWorkflowSecrets(ctx, rc), + Vars: getWorkflowVars(ctx, rc), Strategy: strategy, Matrix: rc.Matrix, Needs: using, @@ -124,6 +125,7 @@ func (rc *RunContext) NewStepExpressionEvaluator(ctx context.Context, step step) Job: rc.getJobContext(), Steps: rc.getStepsContext(), Secrets: getWorkflowSecrets(ctx, rc), + Vars: getWorkflowVars(ctx, rc), Strategy: strategy, Matrix: rc.Matrix, Needs: using, @@ -483,3 +485,7 @@ func getWorkflowSecrets(ctx context.Context, rc *RunContext) map[string]string { return rc.Config.Secrets } + +func getWorkflowVars(ctx context.Context, rc *RunContext) map[string]string { + return rc.Config.Vars +} diff --git a/pkg/runner/expression_test.go b/pkg/runner/expression_test.go index 283b6cf..5cc2f7b 100644 --- a/pkg/runner/expression_test.go +++ b/pkg/runner/expression_test.go @@ -28,6 +28,9 @@ func createRunContext(t *testing.T) *RunContext { Secrets: map[string]string{ "CASE_INSENSITIVE_SECRET": "value", }, + Vars: map[string]string{ + "CASE_INSENSITIVE_VAR": "value", + }, }, Env: map[string]string{ "key": "value", @@ -122,6 +125,8 @@ func TestEvaluateRunContext(t *testing.T) { {"env.key", "value", ""}, {"secrets.CASE_INSENSITIVE_SECRET", "value", ""}, {"secrets.case_insensitive_secret", "value", ""}, + {"vars.CASE_INSENSITIVE_VAR", "value", ""}, + {"vars.case_insensitive_var", "value", ""}, {"format('{{0}}', 'test')", "{0}", ""}, {"format('{{{0}}}', 'test')", "{test}", ""}, {"format('}}')", "}", ""}, @@ -195,6 +200,9 @@ func TestInterpolate(t *testing.T) { Secrets: map[string]string{ "CASE_INSENSITIVE_SECRET": "value", }, + Vars: map[string]string{ + "CASE_INSENSITIVE_VAR": "value", + }, }, Env: map[string]string{ "KEYWITHNOTHING": "valuewithnothing", @@ -229,6 +237,8 @@ func TestInterpolate(t *testing.T) { {" ${{ env.KEY_WITH_UNDERSCORES }} ", " value_with_underscores "}, {"${{ secrets.CASE_INSENSITIVE_SECRET }}", "value"}, {"${{ secrets.case_insensitive_secret }}", "value"}, + {"${{ vars.CASE_INSENSITIVE_VAR }}", "value"}, + {"${{ vars.case_insensitive_var }}", "value"}, {"${{ env.UNKNOWN }}", ""}, {"${{ env.SOMETHING_TRUE }}", "true"}, {"${{ env.SOMETHING_FALSE }}", "false"}, diff --git a/pkg/runner/runner.go b/pkg/runner/runner.go index e1d8d8a..01fd06c 100644 --- a/pkg/runner/runner.go +++ b/pkg/runner/runner.go @@ -34,6 +34,7 @@ type Config struct { Env map[string]string // env for containers Inputs map[string]string // manually passed action inputs Secrets map[string]string // list of secrets + Vars map[string]string // list of vars Token string // GitHub token InsecureSecrets bool // switch hiding output when printing to terminal Platforms map[string]string // list of platforms |