From ac38e2c000a47bb04b82c8b6d83965a820e6d92c Mon Sep 17 00:00:00 2001 From: Ryan Date: Thu, 19 Sep 2024 23:36:09 +0200 Subject: [PATCH] chore: run_context: add GITHUB_RUN_ATTEMPT (#2458) * run_context: add GITHUB_RUN_ATTEMPT Fixes https://github.com/nektos/act/issues/2451 Fixes https://github.com/nektos/act/issues/1615 * fix whitespace * fix githubcontext * fix TestSetupEnv --------- Co-authored-by: ChristopherHX Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> (cherry picked from commit 4178166d289bae351ef6d33414cc569518e62a01) Conflicts: act/runner/run_context.go trivial context conflict act/runner/step_test.go the corresponding test was removed in the Forgejo runner --- act/model/github_context.go | 1 + act/runner/run_context.go | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/act/model/github_context.go b/act/model/github_context.go index e7c8809e..02d4f779 100644 --- a/act/model/github_context.go +++ b/act/model/github_context.go @@ -13,6 +13,7 @@ type GithubContext struct { Event map[string]interface{} `json:"event"` EventPath string `json:"event_path"` Workflow string `json:"workflow"` + RunAttempt string `json:"run_attempt"` RunID string `json:"run_id"` RunNumber string `json:"run_number"` Actor string `json:"actor"` diff --git a/act/runner/run_context.go b/act/runner/run_context.go index 213f5dd5..97615023 100644 --- a/act/runner/run_context.go +++ b/act/runner/run_context.go @@ -1108,6 +1108,7 @@ func (rc *RunContext) getGithubContext(ctx context.Context) *model.GithubContext ghc := &model.GithubContext{ Event: make(map[string]interface{}), Workflow: rc.Run.Workflow.Name, + RunAttempt: rc.Config.Env["GITHUB_RUN_ATTEMPT"], RunID: rc.Config.Env["GITHUB_RUN_ID"], RunNumber: rc.Config.Env["GITHUB_RUN_NUMBER"], Actor: rc.Config.Actor, @@ -1136,6 +1137,10 @@ func (rc *RunContext) getGithubContext(ctx context.Context) *model.GithubContext ghc.Workspace = rc.JobContainer.ToContainerPath(rc.Config.Workdir) } + if ghc.RunAttempt == "" { + ghc.RunAttempt = "1" + } + if ghc.RunID == "" { ghc.RunID = "1" } @@ -1294,6 +1299,7 @@ func (rc *RunContext) withGithubEnv(ctx context.Context, github *model.GithubCon } env["CI"] = "true" set("WORKFLOW", github.Workflow) + set("RUN_ATTEMPT", github.RunAttempt) set("RUN_ID", github.RunID) set("RUN_NUMBER", github.RunNumber) set("ACTION", github.Action)