Skip to content

Commit 6d03a6c

Browse files
authored
Merge pull request #167 from replicatedhq/gha-branch
better GHA branch detection
2 parents 4056cff + 5bd30db commit 6d03a6c

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

cli/cmd/release_create.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (r *runners) InitReleaseCreate(parent *cobra.Command) error {
6363
func (r *runners) gitSHABranch() (sha string, branch string, dirty bool, err error) {
6464
path := "."
6565
rev := "HEAD"
66-
repository, err := git.PlainOpen(path)
66+
repository, err := git.PlainOpenWithOptions(path, &git.PlainOpenOptions{DetectDotGit: true})
6767
if err != nil {
6868
return "", "", false, errors.Wrapf(err, "open %q", path)
6969
}
@@ -85,7 +85,15 @@ func (r *runners) gitSHABranch() (sha string, branch string, dirty bool, err err
8585
return "", "", false, errors.Wrap(err, "get git status")
8686
}
8787

88-
return h.String()[0:7], head.Name().Short(), !status.IsClean(), nil
88+
branchName := head.Name().Short()
89+
90+
// for GH Actions, prefer env branch
91+
envBranch := os.Getenv("GITHUB_BRANCH")
92+
if envBranch != "" {
93+
branchName = envBranch
94+
}
95+
96+
return h.String()[0:7], branchName, !status.IsClean(), nil
8997
}
9098

9199
func (r *runners) setKOTSDefaultReleaseParams() error {

0 commit comments

Comments
 (0)