Skip to content

Commit 6c94e75

Browse files
feat: add CI detection
1 parent 88dfbed commit 6c94e75

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

cmd/semantic-release/main.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66
"errors"
77
"flag"
88
"fmt"
9-
"github.com/go-semantic-release/semantic-release/pkg/semrel"
109
"github.com/go-semantic-release/semantic-release/pkg/condition"
10+
"github.com/go-semantic-release/semantic-release/pkg/semrel"
1111
"github.com/go-semantic-release/semantic-release/pkg/update"
1212
"io/ioutil"
1313
"log"
@@ -43,7 +43,7 @@ func loadConfig() *SemRelConfig {
4343

4444
func main() {
4545
token := flag.String("token", os.Getenv("GITHUB_TOKEN"), "github token")
46-
slug := flag.String("slug", os.Getenv("TRAVIS_REPO_SLUG"), "slug of the repository")
46+
slug := flag.String("slug", condition.GetDefaultRepoSlug(), "slug of the repository")
4747
changelogFile := flag.String("changelog", "", "creates a changelog file")
4848
ghr := flag.Bool("ghr", false, "create a .ghr file with the parameters for ghr")
4949
noci := flag.Bool("noci", false, "run semantic-release locally")
@@ -71,6 +71,10 @@ func main() {
7171
if *token == "" {
7272
exitIfError(errors.New("github token missing"))
7373
}
74+
75+
ci := condition.NewCI()
76+
logger.Printf("detected CI: %s\n", ci.Name())
77+
7478
if *slug == "" {
7579
exitIfError(errors.New("slug missing"))
7680
}
@@ -86,7 +90,7 @@ func main() {
8690
logger.Println("repo is private")
8791
}
8892

89-
currentBranch := condition.GetCurrentBranch()
93+
currentBranch := ci.GetCurrentBranch()
9094
if currentBranch == "" {
9195
exitIfError(fmt.Errorf("current branch not found"))
9296
}
@@ -102,12 +106,17 @@ func main() {
102106
defaultBranch = "*"
103107
}
104108

105-
currentSha := condition.GetCurrentSHA()
109+
currentSha := ci.GetCurrentSHA()
106110
logger.Println("found current sha: " + currentSha)
107111

108112
if !*noci {
109113
logger.Println("running CI condition...")
110-
exitIfError(condition.Travis(*token, defaultBranch, isPrivate || *isTravisCom))
114+
config := condition.CIConfig{
115+
"token": *token,
116+
"defaultBranch": defaultBranch,
117+
"private": isPrivate || *isTravisCom,
118+
}
119+
exitIfError(ci.RunCondition(config))
111120
}
112121

113122
logger.Println("getting latest release...")

pkg/condition/condition.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type DefaultCI struct {
3737
}
3838

3939
func (d DefaultCI) Name() string {
40-
return "Default"
40+
return "none"
4141
}
4242

4343
func (d DefaultCI) RunCondition(config CIConfig) error {

0 commit comments

Comments
 (0)