From 532500b3f5ec91dd8a811c92eee18e7a1ea98bcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torbj=C3=B8rn=20Vatn?= Date: Wed, 18 Nov 2020 16:14:34 +0100 Subject: [PATCH] Act env (#417) * Test more if env variants * The correct negation syntax is != * Make the Interpolate function support negated booleans from envs * Move assert := a.New(t) into t.Run This uncovered that some of the test premisses was wrong and the Eval Bool function also had flaws * Remove a stray logrus import * Add an ACT env set to true This can be used to skip certain steps that you don't want to run locally when testing. E.g. steps that sends messages to Slack channels on successful builds etc. * Add a description about env.ACT to the readme * A new attempt at Interpolation and EvalBool * One small merge fix * Remove some fmt.Printfs * Fix some merge conflicts --- .github/workflows/test-if.yml | 15 +++++++++++++++ act/runner/run_context.go | 1 + act/runner/run_context_test.go | 3 +++ 3 files changed, 19 insertions(+) diff --git a/.github/workflows/test-if.yml b/.github/workflows/test-if.yml index 191e7c21..085851bf 100644 --- a/.github/workflows/test-if.yml +++ b/.github/workflows/test-if.yml @@ -6,6 +6,7 @@ env: SOMETHING_TRUE: true SOMETHING_FALSE: false SOME_TEXT: text + ACT: true jobs: @@ -389,3 +390,17 @@ jobs: - name: "Double checking expr: true && €{{ env.SOMETHING_FALSE == 'true' }}" if: steps.step57.conclusion == 'skipped' run: echo "true && ${{ env.SOMETHING_FALSE == 'true' }} should have been true, but wasn't" + + - name: "✅ I should run, expr: €{{ env.ACT }}" + id: step60 + if: ${{ env.ACT }} + run: echo OK + + - name: "Double checking expr: €{{ env.ACT }}" + if: steps.step60.conclusion == 'skipped' + run: echo "${{ env.ACT }} should have been true, but wasn't" + + - name: "❌ I should not run, expr: €{{ !env.ACT }}" + id: step61 + if: ${{ !env.ACT }} + run: echo "${{ !env.ACT }} should be false, but was evaluated to true;" exit 1; diff --git a/act/runner/run_context.go b/act/runner/run_context.go index 7a59a075..4615b281 100644 --- a/act/runner/run_context.go +++ b/act/runner/run_context.go @@ -47,6 +47,7 @@ func (rc *RunContext) GetEnv() map[string]string { if rc.Env == nil { rc.Env = mergeMaps(rc.Config.Env, rc.Run.Workflow.Env, rc.Run.Job().Env) } + rc.Env["ACT"] = "true" return rc.Env } diff --git a/act/runner/run_context_test.go b/act/runner/run_context_test.go index 07b27dd9..fd9de7e3 100644 --- a/act/runner/run_context_test.go +++ b/act/runner/run_context_test.go @@ -126,6 +126,9 @@ func TestRunContext_EvalBool(t *testing.T) { // Check github context {in: "github.actor == 'nektos/act'", out: true}, {in: "github.actor == 'unknown'", out: false}, + // The special ACT flag + {in: "${{ env.ACT }}", out: true}, + {in: "${{ !env.ACT }}", out: false}, } updateTestIfWorkflow(t, tables, rc)