feat: support GITHUB_REF_NAME
& GITHUB_REF_TYPE
(#1142)
* feat: support `_REF_NAME` & `_REF_TYPE` * chore: fix `step_test::TestSetupEnv` * fix: logic & test * test: delete `GITHUB_REF_NAME`, `GITHUB_REF_TYPE`
This commit is contained in:
parent
dfca2c57df
commit
8e216c642e
3 changed files with 15 additions and 0 deletions
|
@ -18,6 +18,8 @@ type GithubContext struct {
|
||||||
EventName string `json:"event_name"`
|
EventName string `json:"event_name"`
|
||||||
Sha string `json:"sha"`
|
Sha string `json:"sha"`
|
||||||
Ref string `json:"ref"`
|
Ref string `json:"ref"`
|
||||||
|
RefName string `json:"ref_name"`
|
||||||
|
RefType string `json:"ref_type"`
|
||||||
HeadRef string `json:"head_ref"`
|
HeadRef string `json:"head_ref"`
|
||||||
BaseRef string `json:"base_ref"`
|
BaseRef string `json:"base_ref"`
|
||||||
Token string `json:"token"`
|
Token string `json:"token"`
|
||||||
|
|
|
@ -549,6 +549,15 @@ func (rc *RunContext) getGithubContext() *model.GithubContext {
|
||||||
|
|
||||||
ghc.SetRefAndSha(rc.Config.DefaultBranch, repoPath)
|
ghc.SetRefAndSha(rc.Config.DefaultBranch, repoPath)
|
||||||
|
|
||||||
|
// https://docs.github.com/en/actions/learn-github-actions/environment-variables
|
||||||
|
if strings.HasPrefix(ghc.Ref, "refs/tags/") {
|
||||||
|
ghc.RefType = "tag"
|
||||||
|
ghc.RefName = ghc.Ref[len("refs/tags/"):]
|
||||||
|
} else if strings.HasPrefix(ghc.Ref, "refs/heads/") {
|
||||||
|
ghc.RefType = "branch"
|
||||||
|
ghc.RefName = ghc.Ref[len("refs/heads/"):]
|
||||||
|
}
|
||||||
|
|
||||||
return ghc
|
return ghc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -624,6 +633,8 @@ func (rc *RunContext) withGithubEnv(env map[string]string) map[string]string {
|
||||||
env["GITHUB_WORKSPACE"] = github.Workspace
|
env["GITHUB_WORKSPACE"] = github.Workspace
|
||||||
env["GITHUB_SHA"] = github.Sha
|
env["GITHUB_SHA"] = github.Sha
|
||||||
env["GITHUB_REF"] = github.Ref
|
env["GITHUB_REF"] = github.Ref
|
||||||
|
env["GITHUB_REF_NAME"] = github.RefName
|
||||||
|
env["GITHUB_REF_TYPE"] = github.RefType
|
||||||
env["GITHUB_TOKEN"] = github.Token
|
env["GITHUB_TOKEN"] = github.Token
|
||||||
env["GITHUB_SERVER_URL"] = "https://github.com"
|
env["GITHUB_SERVER_URL"] = "https://github.com"
|
||||||
env["GITHUB_API_URL"] = "https://api.github.com"
|
env["GITHUB_API_URL"] = "https://api.github.com"
|
||||||
|
|
|
@ -154,6 +154,8 @@ func TestSetupEnv(t *testing.T) {
|
||||||
|
|
||||||
// These are commit or system specific
|
// These are commit or system specific
|
||||||
delete((env), "GITHUB_REF")
|
delete((env), "GITHUB_REF")
|
||||||
|
delete((env), "GITHUB_REF_NAME")
|
||||||
|
delete((env), "GITHUB_REF_TYPE")
|
||||||
delete((env), "GITHUB_SHA")
|
delete((env), "GITHUB_SHA")
|
||||||
delete((env), "GITHUB_WORKSPACE")
|
delete((env), "GITHUB_WORKSPACE")
|
||||||
delete((env), "GITHUB_REPOSITORY")
|
delete((env), "GITHUB_REPOSITORY")
|
||||||
|
|
Loading…
Reference in a new issue