2017-10-20 19:06:12 +03:00
|
|
|
// Copyright 2017 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
// gitCheckout sets up a fresh git checkout in which to work,
|
|
|
|
// in $HOME/go-releasebot-work/<release>/gitwork
|
|
|
|
// (where <release> is a string like go1.8.5).
|
|
|
|
// The first time it is run for a particular release,
|
|
|
|
// gitCheckout also creates a clean checkout in
|
|
|
|
// $HOME/go-releasebot-work/<release>/gitmirror,
|
|
|
|
// to use as an object cache to speed future checkouts.
|
|
|
|
func (w *Work) gitCheckout() {
|
2017-12-11 23:49:42 +03:00
|
|
|
w.Dir = filepath.Join(os.Getenv("HOME"), "go-releasebot-work/"+strings.ToLower(w.Version))
|
2017-10-20 19:06:12 +03:00
|
|
|
w.log.Printf("working in %s\n", w.Dir)
|
|
|
|
if err := os.MkdirAll(w.Dir, 0777); err != nil {
|
|
|
|
w.log.Panic(err)
|
|
|
|
}
|
|
|
|
|
2018-12-12 22:37:02 +03:00
|
|
|
origin := "https://go.googlesource.com/go"
|
|
|
|
if w.Security {
|
|
|
|
origin = "sso://team/golang/go-private"
|
|
|
|
}
|
|
|
|
|
2017-10-20 19:06:12 +03:00
|
|
|
// Check out a local mirror to work-mirror, to speed future checkouts for this point release.
|
|
|
|
mirror := filepath.Join(w.Dir, "gitmirror")
|
2018-06-18 23:21:54 +03:00
|
|
|
r := w.runner(mirror)
|
2017-10-20 19:06:12 +03:00
|
|
|
if _, err := os.Stat(mirror); err != nil {
|
2018-12-12 22:37:02 +03:00
|
|
|
w.runner(w.Dir).run("git", "clone", origin, mirror)
|
2018-06-18 23:21:54 +03:00
|
|
|
r.run("git", "config", "gc.auto", "0") // don't throw away refs we fetch
|
2017-10-20 19:06:12 +03:00
|
|
|
} else {
|
2018-06-18 23:21:54 +03:00
|
|
|
r.run("git", "fetch", "origin", "master")
|
2017-10-20 19:06:12 +03:00
|
|
|
}
|
2018-06-18 23:21:54 +03:00
|
|
|
r.run("git", "fetch", "origin", w.ReleaseBranch)
|
2017-10-20 19:06:12 +03:00
|
|
|
|
|
|
|
// Clone real Gerrit, but using local mirror for most objects.
|
|
|
|
gitDir := filepath.Join(w.Dir, "gitwork")
|
|
|
|
if err := os.RemoveAll(gitDir); err != nil {
|
|
|
|
w.log.Panic(err)
|
|
|
|
}
|
2018-12-12 22:37:02 +03:00
|
|
|
w.runner(w.Dir).run("git", "clone", "--reference", mirror, "-b", w.ReleaseBranch, origin, gitDir)
|
2018-06-18 23:21:54 +03:00
|
|
|
r = w.runner(gitDir)
|
|
|
|
r.run("git", "codereview", "change", "relwork")
|
|
|
|
r.run("git", "config", "gc.auto", "0") // don't throw away refs we fetch
|
2018-06-25 22:54:24 +03:00
|
|
|
}
|
2017-10-20 19:06:12 +03:00
|
|
|
|
2018-06-25 22:54:24 +03:00
|
|
|
// gitTagExists returns whether git git tag is already present in the repository.
|
|
|
|
func (w *Work) gitTagExists() bool {
|
|
|
|
_, err := w.runner(filepath.Join(w.Dir, "gitwork")).runErr("git", "rev-parse", w.Version)
|
|
|
|
return err == nil
|
2017-10-20 19:06:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// gitTagVersion tags the release candidate or release in Git.
|
|
|
|
func (w *Work) gitTagVersion() {
|
2018-06-18 23:21:54 +03:00
|
|
|
r := w.runner(filepath.Join(w.Dir, "gitwork"))
|
2018-06-25 22:54:24 +03:00
|
|
|
if w.gitTagExists() {
|
|
|
|
out := r.runOut("git", "rev-parse", w.Version)
|
|
|
|
w.VersionCommit = strings.TrimSpace(string(out))
|
|
|
|
w.log.Printf("Git tag already exists (%s), resuming release.", w.VersionCommit)
|
2018-12-15 03:28:33 +03:00
|
|
|
return
|
2018-06-25 22:54:24 +03:00
|
|
|
}
|
2018-06-18 23:21:54 +03:00
|
|
|
out := r.runOut("git", "rev-parse", "HEAD")
|
2018-06-06 18:39:58 +03:00
|
|
|
w.VersionCommit = strings.TrimSpace(string(out))
|
2018-06-18 23:21:54 +03:00
|
|
|
out = r.runOut("git", "show", w.VersionCommit)
|
2018-06-06 18:39:58 +03:00
|
|
|
fmt.Printf("About to tag the following commit as %s:\n\n%s\n\nOk? (y/n) ", w.Version, out)
|
|
|
|
if dryRun {
|
2018-06-18 23:41:24 +03:00
|
|
|
fmt.Println("dry-run")
|
2017-10-20 19:06:12 +03:00
|
|
|
return
|
|
|
|
}
|
2018-06-06 18:39:58 +03:00
|
|
|
var response string
|
|
|
|
_, err := fmt.Scanln(&response)
|
2017-10-20 19:06:12 +03:00
|
|
|
if err != nil {
|
|
|
|
w.log.Panic(err)
|
|
|
|
}
|
2018-06-06 18:39:58 +03:00
|
|
|
if response != "y" {
|
|
|
|
w.log.Panic("stopped")
|
2017-10-20 19:06:12 +03:00
|
|
|
}
|
2018-06-18 23:21:54 +03:00
|
|
|
out, err = r.runErr("git", "tag", w.Version, w.VersionCommit)
|
2018-06-06 18:39:58 +03:00
|
|
|
if err != nil {
|
|
|
|
w.logError("git tag failed: %s\n%s", err, out)
|
|
|
|
return
|
2017-10-20 19:06:12 +03:00
|
|
|
}
|
2018-06-18 23:21:54 +03:00
|
|
|
r.run("git", "push", "origin", w.Version)
|
2017-10-20 19:06:12 +03:00
|
|
|
}
|
2018-12-15 00:55:42 +03:00
|
|
|
|
|
|
|
// gitHeadCommit returns the hash of the HEAD commit.
|
|
|
|
func (w *Work) gitHeadCommit() string {
|
|
|
|
r := w.runner(filepath.Join(w.Dir, "gitwork"))
|
|
|
|
out := r.runOut("git", "rev-parse", "HEAD")
|
|
|
|
return strings.TrimSpace(string(out))
|
|
|
|
}
|