diff --git a/pkg/model/github_context.go b/pkg/model/github_context.go index 71221a5926b..168447b2aa4 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 8abc4353cac..b8f338eef96 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 6752d72702f..b36ad9e8ac3 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",