diff options
author | Denis Isaev <denis@golangci.com> | 2018-11-24 12:15:54 +0300 |
---|---|---|
committer | Denis Isaev <denis@golangci.com> | 2018-11-24 12:23:46 +0300 |
commit | 4e8e4612bd20ed12fa4b64f825f050e45ce5f9bd (patch) | |
tree | 5f5a2eb97e066c5f8f8bcb8b90acbeaf67ec4cea /scripts/push_new_patch | |
parent | b9ecb82cb7ea5be027ebfcfa33ad45287e08c5f7 (diff) |
fix 'main' redefinition in scripts/ dir
Diffstat (limited to 'scripts/push_new_patch')
-rwxr-xr-x | scripts/push_new_patch/main.go | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/scripts/push_new_patch/main.go b/scripts/push_new_patch/main.go new file mode 100755 index 000000000..b1660d3c1 --- /dev/null +++ b/scripts/push_new_patch/main.go @@ -0,0 +1,63 @@ +// call from project root with +// go run scripts/push_new_patch/main.go + +// goreleaser expects a $GITHUB_TOKEN env variable to be defined +// in order to push the release got github + +package main + +import ( + "fmt" + "io/ioutil" + "log" + "os" + "os/exec" + "strconv" + "strings" +) + +func main() { + + version, err := ioutil.ReadFile("VERSION") + if err != nil { + log.Panicln(err.Error()) + } + stringVersion := string(version) + fmt.Println("VERSION was " + stringVersion) + + runCommand("git", "pull") + + splitVersion := strings.Split(stringVersion, ".") + patch := splitVersion[len(splitVersion)-1] + newPatch, err := strconv.Atoi(patch) + splitVersion[len(splitVersion)-1] = strconv.FormatInt(int64(newPatch)+1, 10) + newVersion := strings.Join(splitVersion, ".") + + err = ioutil.WriteFile("VERSION", []byte(newVersion), 0644) + if err != nil { + log.Panicln(err.Error()) + } + + runCommand("git", "add", "VERSION") + runCommand("git", "commit", "-m", "bump version to "+newVersion, "--", "VERSION") + runCommand("git", "push") + runCommand("git", "tag", newVersion) + runCommand("git", "push", "origin", newVersion) + runCommand("goreleaser", "--rm-dist") + runCommand("rm", "-rf", "dist") +} + +func runCommand(args ...string) { + fmt.Println(strings.Join(args, " ")) + cmd := exec.Command(args[0], args[1:]...) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + err := cmd.Start() + if err != nil { + panic(err.Error()) + } + err = cmd.Wait() + if err != nil { + panic(err.Error()) + } +} |