Skip to content

Commit 79d5ecf

Browse files
fix: github actions CI condition
1 parent e5508ff commit 79d5ecf

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

pkg/condition/github.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@ func (gha *GitHubActions) IsBranchRef() bool {
2929
}
3030

3131
func (gha *GitHubActions) RunCondition(config CIConfig) error {
32+
defaultBranch := config["defaultBranch"].(string)
3233
if !gha.IsBranchRef() {
33-
return fmt.Errorf("not running on a branch")
34+
return fmt.Errorf("This test run is not running on a branch build.")
35+
}
36+
if branch := gha.GetCurrentBranch(); defaultBranch != "*" && branch != defaultBranch {
37+
return fmt.Errorf("This test run was triggered on the branch %s, while semantic-release is configured to only publish from %s.", branch, defaultBranch)
3438
}
3539
return nil
3640
}

pkg/condition/github_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
package condition
22

33
import (
4-
"os"
54
"testing"
65
)
76

87
func TestGithubValid(t *testing.T) {
9-
os.Setenv("GITHUB_REF", "")
108
gha := GitHubActions{}
11-
err := gha.RunCondition(CIConfig{})
9+
err := gha.RunCondition(CIConfig{"defaultBranch": ""})
1210
if err == nil {
1311
t.Fail()
1412
}

0 commit comments

Comments
 (0)