From a34d9c6d603b8d866cc9b50008478a25775bdbd8 Mon Sep 17 00:00:00 2001 From: Ryan Date: Thu, 19 Sep 2024 23:36:09 +0200 Subject: [PATCH] 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> --- pkg/model/github_context.go | 1 + pkg/runner/run_context.go | 6 ++++++ pkg/runner/step_test.go | 1 + 3 files changed, 8 insertions(+) diff --git a/pkg/model/github_context.go b/pkg/model/github_context.go index 71221a5..168447b 100644 --- a/pkg/model/github_context.go +++ b/pkg/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/pkg/runner/run_context.go b/pkg/runner/run_context.go index 8abc435..b8f338e 100644 --- a/pkg/runner/run_context.go +++ b/pkg/runner/run_context.go @@ -858,6 +858,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, @@ -886,6 +887,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" } @@ -997,6 +1002,7 @@ func nestedMapLookup(m map[string]interface{}, ks ...string) (rval interface{}) func (rc *RunContext) withGithubEnv(ctx context.Context, github *model.GithubContext, env map[string]string) map[string]string { env["CI"] = "true" env["GITHUB_WORKFLOW"] = github.Workflow + env["GITHUB_RUN_ATTEMPT"] = github.RunAttempt env["GITHUB_RUN_ID"] = github.RunID env["GITHUB_RUN_NUMBER"] = github.RunNumber env["GITHUB_ACTION"] = github.Action diff --git a/pkg/runner/step_test.go b/pkg/runner/step_test.go index 6752d72..b36ad9e 100644 --- a/pkg/runner/step_test.go +++ b/pkg/runner/step_test.go @@ -182,6 +182,7 @@ func TestSetupEnv(t *testing.T) { "GITHUB_RETENTION_DAYS": "0", "GITHUB_RUN_ID": "runId", "GITHUB_RUN_NUMBER": "1", + "GITHUB_RUN_ATTEMPT": "1", "GITHUB_SERVER_URL": "https://", "GITHUB_WORKFLOW": "", "INPUT_STEP_WITH": "with-value",