Skip to content

Commit 427a6c7

Browse files
feat: store ght opts in file
1 parent 50c0d61 commit 427a6c7

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

cmd/semantic-release/main.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ import (
99
"io/ioutil"
1010
"log"
1111
"os"
12+
"strings"
1213
)
1314

1415
func main() {
1516
token := flag.String("token", os.Getenv("GITHUB_TOKEN"), "github token")
1617
slug := flag.String("slug", os.Getenv("TRAVIS_REPO_SLUG"), "slug of the repository")
17-
ghr := flag.Bool("ghr", false, "print ghr flags to stdout")
18+
ghr := flag.Bool("ghr", false, "create a .ghr file with the parameters for ghr")
1819
noci := flag.Bool("noci", false, "run semantic-release locally")
1920
dry := flag.Bool("dry", false, "do not create release")
2021
vFile := flag.Bool("vf", false, "create a .version file")
@@ -27,8 +28,8 @@ func main() {
2728
os.Exit(1)
2829
return
2930
}
30-
if *slug == "" {
31-
logger.Println("slug missing")
31+
if *slug == "" || !strings.Contains(*slug, "/") {
32+
logger.Println("slug missing or invalid")
3233
os.Exit(1)
3334
return
3435
}
@@ -68,9 +69,9 @@ func main() {
6869
logger.Println("found: " + release.Version.String())
6970

7071
logger.Println("getting commits...")
71-
commits, err := repo.GetCommits()
72-
if err != nil {
73-
logger.Println(err)
72+
commits, cerr := repo.GetCommits()
73+
if cerr != nil {
74+
logger.Println(cerr)
7475
os.Exit(1)
7576
return
7677
}
@@ -99,7 +100,12 @@ func main() {
99100
}
100101

101102
if *ghr {
102-
fmt.Printf("-u %s -r %s v%s", repo.Owner, repo.Repo, newVer.String())
103+
gerr := ioutil.WriteFile(".ghr", []byte(fmt.Sprintf("-u %s -r %s v%s", repo.Owner, repo.Repo, newVer.String())), 0644)
104+
if gerr != nil {
105+
logger.Println(gerr)
106+
os.Exit(1)
107+
return
108+
}
103109
}
104110

105111
if *vFile {

0 commit comments

Comments
 (0)