2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-26 14:56:29 +00:00

release.go: Add version to global.go

Closes #1958
This commit is contained in:
Alexander Neumann 2018-08-17 20:45:32 +02:00
parent 89f17847ad
commit 79d3a18b31

View File

@ -70,6 +70,21 @@ func run(cmd string, args ...string) {
} }
} }
func replace(filename, from, to string) {
reg := regexp.MustCompile(from)
buf, err := ioutil.ReadFile(filename)
if err != nil {
die("error reading file %v: %v", filename, err)
}
buf = reg.ReplaceAll(buf, []byte(to))
err = ioutil.WriteFile(filename, buf, 0644)
if err != nil {
die("error writing file %v: %v", filename, err)
}
}
func rm(file string) { func rm(file string) {
err := os.Remove(file) err := os.Remove(file)
if err != nil { if err != nil {
@ -272,18 +287,33 @@ func generateFiles() {
} }
} }
var versionPattern = `var version = ".*"`
const versionCodeFile = "cmd/restic/global.go"
func updateVersion() { func updateVersion() {
err := ioutil.WriteFile("VERSION", []byte(opts.Version+"\n"), 0644) err := ioutil.WriteFile("VERSION", []byte(opts.Version+"\n"), 0644)
if err != nil { if err != nil {
die("unable to write version to file: %v", err) die("unable to write version to file: %v", err)
} }
if len(uncommittedChanges("VERSION")) > 0 { newVersion := fmt.Sprintf("var version = %q", opts.Version)
msg("committing file VERSION") replace(versionCodeFile, versionPattern, newVersion)
run("git", "commit", "-m", fmt.Sprintf("Add VERSION for %v", opts.Version), "VERSION")
if len(uncommittedChanges("VERSION")) > 0 || len(uncommittedChanges(versionCodeFile)) > 0 {
msg("committing version files")
run("git", "commit", "-m", fmt.Sprintf("Add version for %v", opts.Version), "VERSION", versionCodeFile)
} }
} }
func updateVersionDev() {
newVersion := fmt.Sprintf(`var version = "%s-dev (compiled manually)"`, opts.Version)
replace(versionCodeFile, versionPattern, newVersion)
msg("committing cmd/restic/global.go with dev version")
run("git", "commit", "-m", fmt.Sprintf("Set development version for %v", opts.Version), "VERSION", versionCodeFile)
}
func addTag() { func addTag() {
tagname := "v" + opts.Version tagname := "v" + opts.Version
msg("add tag %v", tagname) msg("add tag %v", tagname)
@ -371,6 +401,7 @@ func main() {
generateFiles() generateFiles()
updateVersion() updateVersion()
addTag() addTag()
updateVersionDev()
exportTar() exportTar()
runBuild() runBuild()