Skip to content

Commit 2417340

Browse files
committed
add GITHUB_BASE_REF as source for branch
1 parent 98838b6 commit 2417340

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

pkg/gitsemver.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,13 @@ func (vs *GitSemVer) GetTag(repo string) (string, bool) {
133133
}
134134

135135
func (vs *GitSemVer) getBranchGitHub(repo string) (branchName string) {
136-
if branchName = strings.TrimSpace(vs.Env.Getenv("GITHUB_REF_NAME")); branchName != "" {
137-
if strings.TrimSpace(vs.Env.Getenv("GITHUB_REF_TYPE")) == "tag" {
138-
for _, branchName = range vs.Git.GetBranchesFromTag(repo, branchName) {
139-
if vs.IsReleaseBranch(branchName) {
140-
break
136+
if branchName = strings.TrimSpace(vs.Env.Getenv("GITHUB_BASE_REF")); branchName == "" {
137+
if branchName = strings.TrimSpace(vs.Env.Getenv("GITHUB_REF_NAME")); branchName != "" {
138+
if strings.TrimSpace(vs.Env.Getenv("GITHUB_REF_TYPE")) == "tag" {
139+
for _, branchName = range vs.Git.GetBranchesFromTag(repo, branchName) {
140+
if vs.IsReleaseBranch(branchName) {
141+
break
142+
}
141143
}
142144
}
143145
}

pkg/gitsemver_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,13 @@ func Test_VersionStringer_GetBranch(t *testing.T) {
142142
delete(env, "GITHUB_REF_NAME")
143143
git.branch = ""
144144

145+
git.branch = "detached"
146+
env["GITHUB_BASE_REF"] = "main"
147+
name = vs.GetBranch(".")
148+
isEqual(t, "main", name)
149+
delete(env, "GITHUB_BASE_REF")
150+
git.branch = ""
151+
145152
git.branch = "detached"
146153
env["CI_COMMIT_REF_NAME"] = "gitlab---branch"
147154
name = vs.GetBranch(".")

0 commit comments

Comments
 (0)