1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2025-09-15 18:57:01 +00:00

Add various GitHub environment variables (#604)

* define GITHUB_ACTION_PATH #603

* Add more environment variables

* Add job name

Note: the job name gets a suffix for matrix builds, but this is not part of the env var

* fix: remove unnecessary variables

* feat: add `RepositoryOwner`

credit: @KnisterPeter

* feat: add test for `getGithubContext()`

Co-authored-by: Ryan (hackercat) <me@hackerc.at>
This commit is contained in:
Josh Soref 2021-05-06 16:02:29 -04:00 committed by GitHub
parent 133e8a4475
commit 9210fafdc1
5 changed files with 132 additions and 41 deletions

View file

@ -11,7 +11,9 @@ import (
"github.com/nektos/act/pkg/model"
a "github.com/stretchr/testify/assert"
"gotest.tools/v3/assert"
log "github.com/sirupsen/logrus"
"github.com/sirupsen/logrus/hooks/test"
)
@ -277,3 +279,44 @@ func TestRunContext_GetBindsAndMounts(t *testing.T) {
}
}
}
func TestGetGitHubContext(t *testing.T) {
log.SetLevel(log.DebugLevel)
cwd, err := os.Getwd()
assert.NilError(t, err)
rc := &RunContext{
Config: &Config{
EventName: "push",
Workdir: cwd,
},
Run: &model.Run{
Workflow: &model.Workflow{
Name: "GitHubContextTest",
},
},
Name: "GitHubContextTest",
CurrentStep: "step",
Matrix: map[string]interface{}{},
Env: map[string]string{},
ExtraPath: []string{},
StepResults: map[string]*stepResult{},
OutputMappings: map[MappableOutput]MappableOutput{},
}
ghc := rc.getGithubContext()
log.Debugf("%v", ghc)
assert.Equal(t, ghc.RunID, "1")
assert.Equal(t, ghc.Workspace, cwd)
assert.Equal(t, ghc.RunNumber, "1")
assert.Equal(t, ghc.RetentionDays, "0")
assert.Equal(t, ghc.Actor, "nektos/act")
assert.Equal(t, ghc.Repository, "nektos/act")
assert.Equal(t, ghc.RepositoryOwner, "nektos")
assert.Equal(t, ghc.RunnerPerflog, "/dev/null")
assert.Equal(t, ghc.EventPath, "/tmp/workflow/event.json")
assert.Equal(t, ghc.Token, rc.Config.Secrets["GITHUB_TOKEN"])
}