Commit 865904f6 authored by Andrew Gerrand's avatar Andrew Gerrand

misc/makerelease: report uploads to the new downloads page

LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/102040047
parent 98b6410f
...@@ -12,12 +12,15 @@ import ( ...@@ -12,12 +12,15 @@ import (
"bufio" "bufio"
"bytes" "bytes"
"compress/gzip" "compress/gzip"
"crypto/sha1"
"encoding/json"
"flag" "flag"
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
"log" "log"
"net/http" "net/http"
"net/url"
"os" "os"
"os/exec" "os/exec"
"path" "path"
...@@ -43,12 +46,13 @@ var ( ...@@ -43,12 +46,13 @@ var (
staticToolchain = flag.Bool("static", true, "try to build statically linked toolchain (only supported on ELF targets)") staticToolchain = flag.Bool("static", true, "try to build statically linked toolchain (only supported on ELF targets)")
tokenCache = flag.String("token", defaultCacheFile, "Authentication token cache file") tokenCache = flag.String("token", defaultCacheFile, "Authentication token cache file")
storageBucket = flag.String("bucket", "golang", "Cloud Storage Bucket") storageBucket = flag.String("bucket", "golang", "Cloud Storage Bucket")
uploadURL = flag.String("upload_url", defaultUploadURL, "Upload URL")
defaultCacheFile = filepath.Join(os.Getenv("HOME"), ".makerelease-request-token") defaultCacheFile = filepath.Join(os.Getenv("HOME"), ".makerelease-request-token")
defaultUploadURL = "http://golang.org/dl/upload"
) )
const ( const (
uploadURL = "https://go.googlecode.com/files"
blogPath = "code.google.com/p/go.blog" blogPath = "code.google.com/p/go.blog"
toolPath = "code.google.com/p/go.tools" toolPath = "code.google.com/p/go.tools"
tourPath = "code.google.com/p/go-tour" tourPath = "code.google.com/p/go-tour"
...@@ -167,7 +171,7 @@ func main() { ...@@ -167,7 +171,7 @@ func main() {
continue continue
} }
if err := b.Upload(version, targ); err != nil { if err := b.Upload(version, targ); err != nil {
log.Printf("%s: %v", targ, err) log.Printf("uploading %s: %v", targ, err)
} }
continue continue
} }
...@@ -455,7 +459,7 @@ func (b *Build) Do() error { ...@@ -455,7 +459,7 @@ func (b *Build) Do() error {
for _, targ := range targs { for _, targ := range targs {
err = b.Upload(version, targ) err = b.Upload(version, targ)
if err != nil { if err != nil {
return err return fmt.Errorf("uploading %s: %v", targ, err)
} }
} }
} }
...@@ -653,28 +657,67 @@ func (b *Build) env() []string { ...@@ -653,28 +657,67 @@ func (b *Build) env() []string {
} }
func (b *Build) Upload(version string, filename string) error { func (b *Build) Upload(version string, filename string) error {
svc, err := storage.New(oauthClient) file, err := ioutil.ReadFile(filename)
if err != nil { if err != nil {
return err return err
} }
svc, err := storage.New(oauthClient)
if err != nil {
return err
}
obj := &storage.Object{ obj := &storage.Object{
Acl: []*storage.ObjectAccessControl{{Entity: "allUsers", Role: "READER"}}, Acl: []*storage.ObjectAccessControl{{Entity: "allUsers", Role: "READER"}},
Name: filename, Name: filename,
} }
f, err := os.Open(filename) _, err = svc.Objects.Insert(*storageBucket, obj).Media(bytes.NewReader(file)).Do()
if err != nil { if err != nil {
return err return err
} }
defer f.Close()
_, err = svc.Objects.Insert(*storageBucket, obj).Media(f).Do() sum := fmt.Sprintf("%x", sha1.Sum(file))
kind := "unknown"
switch {
case b.Source:
kind = "source"
case strings.HasSuffix(filename, ".tar.gz"), strings.HasSuffix(filename, ".zip"):
kind = "archive"
case strings.HasSuffix(filename, ".msi"), strings.HasSuffix(filename, ".pkg"):
kind = "installer"
}
req, err := json.Marshal(File{
Filename: filename,
Version: version,
OS: b.OS,
Arch: b.Arch,
Checksum: sum,
Kind: kind,
})
if err != nil {
return err
}
u := fmt.Sprintf("%s?%s", *uploadURL, url.Values{"key": []string{builderKey}}.Encode())
resp, err := http.Post(u, "application/json", bytes.NewReader(req))
if err != nil { if err != nil {
return err return err
} }
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("upload status: %v", resp.Status)
}
return nil return nil
} }
type File struct {
Filename string
OS string
Arch string
Version string
Checksum string `datastore:",noindex"`
Kind string // "archive", "installer", "source"
}
func setupOAuthClient() error { func setupOAuthClient() error {
config := &oauth.Config{ config := &oauth.Config{
ClientId: "999119582588-h7kpj5pcm6d9solh5lgrbusmvvk4m9dn.apps.googleusercontent.com", ClientId: "999119582588-h7kpj5pcm6d9solh5lgrbusmvvk4m9dn.apps.googleusercontent.com",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment