fix: github.job property is empty, GITHUB_JOB should be job id (#1646)

* fix: github.job property is empty, GITHUB_JOB should be job id

fix: github.job property is empty #1621
fix: GITHUB_JOB should be the id not the name #1473

* fix linter problem.

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
Alex Savchuk 2023-02-27 22:10:31 +03:00 committed by GitHub
parent 04d12b0206
commit 5500c928eb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 2 deletions

View file

@ -567,6 +567,7 @@ func (rc *RunContext) getGithubContext(ctx context.Context) *model.GithubContext
EventName: rc.Config.EventName,
Action: rc.CurrentStep,
Token: rc.Config.Token,
Job: rc.Run.JobID,
ActionPath: rc.ActionPath,
RepositoryOwner: rc.Config.Env["GITHUB_REPOSITORY_OWNER"],
RetentionDays: rc.Config.Env["GITHUB_RETENTION_DAYS"],
@ -693,7 +694,7 @@ func (rc *RunContext) withGithubEnv(ctx context.Context, github *model.GithubCon
env["GITHUB_REF_NAME"] = github.RefName
env["GITHUB_REF_TYPE"] = github.RefType
env["GITHUB_TOKEN"] = github.Token
env["GITHUB_JOB"] = rc.JobName
env["GITHUB_JOB"] = github.Job
env["GITHUB_REPOSITORY_OWNER"] = github.RepositoryOwner
env["GITHUB_RETENTION_DAYS"] = github.RetentionDays
env["RUNNER_PERFLOG"] = github.RunnerPerflog

View file

@ -144,6 +144,7 @@ func TestRunContext_EvalBool(t *testing.T) {
// Check github context
{in: "github.actor == 'nektos/act'", out: true},
{in: "github.actor == 'unknown'", out: false},
{in: "github.job == 'job1'", out: true},
// The special ACT flag
{in: "${{ env.ACT }}", out: true},
{in: "${{ !env.ACT }}", out: false},
@ -364,6 +365,7 @@ func TestGetGitHubContext(t *testing.T) {
StepResults: map[string]*model.StepResult{},
OutputMappings: map[MappableOutput]MappableOutput{},
}
rc.Run.JobID = "job1"
ghc := rc.getGithubContext(context.Background())
@ -392,6 +394,7 @@ func TestGetGitHubContext(t *testing.T) {
assert.Equal(t, ghc.RepositoryOwner, owner)
assert.Equal(t, ghc.RunnerPerflog, "/dev/null")
assert.Equal(t, ghc.Token, rc.Config.Secrets["GITHUB_TOKEN"])
assert.Equal(t, ghc.Job, "job1")
}
func TestGetGithubContextRef(t *testing.T) {

View file

@ -175,7 +175,7 @@ func TestSetupEnv(t *testing.T) {
"GITHUB_EVENT_PATH": "/var/run/act/workflow/event.json",
"GITHUB_GRAPHQL_URL": "https:///api/graphql",
"GITHUB_HEAD_REF": "",
"GITHUB_JOB": "",
"GITHUB_JOB": "1",
"GITHUB_RETENTION_DAYS": "0",
"GITHUB_RUN_ID": "runId",
"GITHUB_RUN_NUMBER": "1",