mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
update version
This commit is contained in:
parent
9e61f38707
commit
37b29aebce
1 changed files with 19 additions and 12 deletions
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -14,26 +15,32 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func run() (err error) {
|
func run() (err error) {
|
||||||
b, err := ioutil.ReadFile("README.md")
|
version, err := exec.Command("git", "describe").Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
newVersion := GetStringInBetween(string(b), "version-", "-b")
|
|
||||||
|
|
||||||
b, err = ioutil.ReadFile("src/cli/cli.go")
|
err = replaceInFile("src/cli/cli.go", `Version ="`, `"`, string(version))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func replaceInFile(fname, start, end, replacement string) (err error) {
|
||||||
|
b, err := ioutil.ReadFile(fname)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
oldVersion := GetStringInBetween(string(b), `Version = "`, `"`)
|
oldVersion := GetStringInBetween(string(b), start, end)
|
||||||
|
if oldVersion == "" {
|
||||||
if newVersion != oldVersion {
|
err = fmt.Errorf("nothing")
|
||||||
fmt.Printf("new version: '%s'\n", newVersion)
|
return
|
||||||
fmt.Printf("old version: '%s'\n", oldVersion)
|
|
||||||
newCli := strings.Replace(string(b), fmt.Sprintf(`Version = "%s"`, oldVersion), fmt.Sprintf(`Version = "%s"`, newVersion), 1)
|
|
||||||
err = ioutil.WriteFile("src/cli/cli.go", []byte(newCli), 0644)
|
|
||||||
} else {
|
|
||||||
fmt.Printf("current version: '%s'\n", oldVersion)
|
|
||||||
}
|
}
|
||||||
|
newF := strings.Replace(
|
||||||
|
string(b),
|
||||||
|
fmt.Sprintf("%s%s%s", start, oldVersion, end),
|
||||||
|
fmt.Sprintf("%s%s%s", start, replacement, end),
|
||||||
|
1,
|
||||||
|
)
|
||||||
|
err = ioutil.WriteFile(fname, []byte(newF), 0644)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue