File tree 3 files changed +15
-0
lines changed
3 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,8 @@ type GithubContext struct {
18
18
EventName string `json:"event_name"`
19
19
Sha string `json:"sha"`
20
20
Ref string `json:"ref"`
21
+ RefName string `json:"ref_name"`
22
+ RefType string `json:"ref_type"`
21
23
HeadRef string `json:"head_ref"`
22
24
BaseRef string `json:"base_ref"`
23
25
Token string `json:"token"`
Original file line number Diff line number Diff line change @@ -549,6 +549,15 @@ func (rc *RunContext) getGithubContext() *model.GithubContext {
549
549
550
550
ghc .SetRefAndSha (rc .Config .DefaultBranch , repoPath )
551
551
552
+ // https://docs.github.com/en/actions/learn-github-actions/environment-variables
553
+ if strings .HasPrefix (ghc .Ref , "refs/tags/" ) {
554
+ ghc .RefType = "tag"
555
+ ghc .RefName = ghc .Ref [len ("refs/tags/" ):]
556
+ } else if strings .HasPrefix (ghc .Ref , "refs/heads/" ) {
557
+ ghc .RefType = "branch"
558
+ ghc .RefName = ghc .Ref [len ("refs/heads/" ):]
559
+ }
560
+
552
561
return ghc
553
562
}
554
563
@@ -624,6 +633,8 @@ func (rc *RunContext) withGithubEnv(env map[string]string) map[string]string {
624
633
env ["GITHUB_WORKSPACE" ] = github .Workspace
625
634
env ["GITHUB_SHA" ] = github .Sha
626
635
env ["GITHUB_REF" ] = github .Ref
636
+ env ["GITHUB_REF_NAME" ] = github .RefName
637
+ env ["GITHUB_REF_TYPE" ] = github .RefType
627
638
env ["GITHUB_TOKEN" ] = github .Token
628
639
env ["GITHUB_SERVER_URL" ] = "https://github.com"
629
640
env ["GITHUB_API_URL" ] = "https://api.github.com"
Original file line number Diff line number Diff line change @@ -154,6 +154,8 @@ func TestSetupEnv(t *testing.T) {
154
154
155
155
// These are commit or system specific
156
156
delete ((env ), "GITHUB_REF" )
157
+ delete ((env ), "GITHUB_REF_NAME" )
158
+ delete ((env ), "GITHUB_REF_TYPE" )
157
159
delete ((env ), "GITHUB_SHA" )
158
160
delete ((env ), "GITHUB_WORKSPACE" )
159
161
delete ((env ), "GITHUB_REPOSITORY" )
You can’t perform that action at this time.
0 commit comments