diff --git a/.github/workflows/test-if.yml b/.github/workflows/test-if.yml index 191e7c2..085851b 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/README.md b/README.md index 5b44d58..026977f 100644 --- a/README.md +++ b/README.md @@ -166,6 +166,18 @@ Additionally, act supports loading environment variables from an `.env` file. Th act --env-file my.env ``` +# Skipping steps + +Act adds a special environement variable `ACT` that can be used to skip a step that you +don't want to run locally. E.g. a step that posts a Slack message or bumps a version number. + +```yml +- name: Some step + if: ${{ !env.ACT }} + run: | + ... +``` + # Events Every [GitHub event](https://developer.github.com/v3/activity/events/types) is accompanied by a payload. You can provide these events in JSON format with the `--eventpath` to simulate specific GitHub events kicking off an action. For example: diff --git a/pkg/runner/run_context.go b/pkg/runner/run_context.go index 7a59a07..4615b28 100644 --- a/pkg/runner/run_context.go +++ b/pkg/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/pkg/runner/run_context_test.go b/pkg/runner/run_context_test.go index 07b27dd..fd9de7e 100644 --- a/pkg/runner/run_context_test.go +++ b/pkg/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)