Merge "misc/monthly.go: use release date in files names"

This commit is contained in:
Mathieu Lonjaret 2016-10-26 22:13:33 +00:00 committed by Gerrit Code Review
commit 45f47052cf
1 changed files with 39 additions and 10 deletions

View File

@ -49,17 +49,24 @@ import (
var (
flagRev = flag.String("rev", "", "Camlistore revision to build (tag or commit hash). For development purposes, you can instead specify the path to a local Camlistore source tree from which to build, with the form \"WIP:/path/to/dir\".")
flagDate = flag.String("date", "", "The release date to use in the file names to be uploaded, in the YYYYMMDD format. Defaults to today's date.")
flagUpload = flag.Bool("upload", true, "Upload all the generated tarballs and zip archives.")
flagSkipGen = flag.Bool("skipgen", false, "Do not recreate the release tarballs, and directly use the ones found in camlistore.org/misc/docker/release. Use -upload=true and -skipgen=true to only generate the monthly release page.")
// flagStatsFrom = flag.String("stats_from", "", "Also generate commit statistics on the release page, starting from the given commit, and ending at the one given as -rev.")
// TODO(mpl): make sanity run the tests too, once they're more reliable.
flagSanity = flag.Bool("sanity", true, "Verify 'go run make.go' succeeds when building the source tarball. Abort everything if not.")
)
var camDir string
var (
camDir string
releaseDate time.Time
)
const (
project = "camlistore-website"
bucket = "camlistore-release"
titleDateFormat = "2006-01-02"
fileDateFormat = "20060102"
project = "camlistore-website"
bucket = "camlistore-release"
)
func isWIP() bool {
@ -137,7 +144,7 @@ func upload(srcPath string) {
if !*flagUpload {
return
}
destName := strings.Replace(filepath.Base(srcPath), "camlistore", "camlistore-"+rev(), 1)
destName := strings.Replace(filepath.Base(srcPath), "camlistore", "camlistore-"+releaseDate.Format(fileDateFormat), 1)
versionedTarball := "monthly/" + destName
log.Printf("Uploading %s/%s ...", bucket, versionedTarball)
@ -199,8 +206,10 @@ type DownloadData struct {
}
type ReleaseData struct {
Date string
Download []DownloadData
Date string
Download []DownloadData
CamliVersion string
GoVersion string
}
// Note: the space trimming in the range loop is important. Since all of our
@ -209,6 +218,10 @@ type ReleaseData struct {
var monthlyTemplate = `
<h1>Monthly Release: {{.Date}}</h1>
<p>
Camlistore version <a href='https://github.com/camlistore/camlistore/commit/{{.CamliVersion}}'>{{.CamliVersion}}</a> built with Go {{.GoVersion}}.
</p>
<h2>Downloads</h2>
<center>
@ -224,6 +237,8 @@ var monthlyTemplate = `
</center>
`
const goVersion = "1.7" // Keep in sync with version in misc/docker/go
// listDownloads lists all the files found in the monthly repo, and from them,
// builds the data that we'll feed to the template to generate the monthly
// downloads camweb page.
@ -287,8 +302,9 @@ func listDownloads() (*ReleaseData, error) {
downloadData []DownloadData
nameToSum = make(map[string]string)
)
fileDate := releaseDate.Format(fileDateFormat)
for _, attrs := range objList.Results {
if !strings.Contains(attrs.Name, rev()) {
if !strings.Contains(attrs.Name, fileDate) {
continue
}
if err := checkDate(attrs.Updated); err != nil {
@ -304,7 +320,7 @@ func listDownloads() (*ReleaseData, error) {
nameToSum[strings.TrimSuffix(attrs.Name, ".sha256")] = sum
}
for _, attrs := range objList.Results {
if !strings.Contains(attrs.Name, rev()) {
if !strings.Contains(attrs.Name, fileDate) {
continue
}
if strings.HasSuffix(attrs.Name, ".sha256") {
@ -321,9 +337,13 @@ func listDownloads() (*ReleaseData, error) {
})
}
// TODO(mpl): guess Go version dynamically.
return &ReleaseData{
Date: date.Format("2006-01-02"),
Download: downloadData,
Date: releaseDate.Format(titleDateFormat),
Download: downloadData,
CamliVersion: rev(),
GoVersion: goVersion,
}, nil
}
@ -364,6 +384,15 @@ func checkFlags() {
fmt.Fprintf(os.Stderr, "Usage error: --rev is required.\n")
usage()
}
releaseDate = time.Now()
if *flagDate != "" {
var err error
releaseDate, err = time.Parse(fileDateFormat, *flagDate)
if err != nil {
fmt.Fprintf(os.Stderr, "Incorrect date format: %v", err)
usage()
}
}
}
func main() {