Sfoglia il codice sorgente

get correct branch name for deployment target (#3653)

ianedwards 2 anni fa
parent
commit
ecd89e9df9
1 ha cambiato i file con 6 aggiunte e 1 eliminazioni
  1. 6 1
      cli/cmd/v2/apply.go

+ 6 - 1
cli/cmd/v2/apply.go

@@ -389,7 +389,12 @@ func deploymentTargetFromConfig(ctx context.Context, client api.Client, projectI
 
 
 	if previewApply {
 	if previewApply {
 		var branchName string
 		var branchName string
-		if os.Getenv("GITHUB_REF_NAME") != "" {
+
+		// branch name is set to different values in the GH env, depending on whether or not the workflow is triggered by a PR
+		// issue is being tracked here: https://github.com/github/docs/issues/15319
+		if os.Getenv("GITHUB_HEAD_REF") != "" {
+			branchName = os.Getenv("GITHUB_HEAD_REF")
+		} else if os.Getenv("GITHUB_REF_NAME") != "" {
 			branchName = os.Getenv("GITHUB_REF_NAME")
 			branchName = os.Getenv("GITHUB_REF_NAME")
 		} else if branch, err := git.CurrentBranch(); err == nil {
 		} else if branch, err := git.CurrentBranch(); err == nil {
 			branchName = branch
 			branchName = branch