mirror of
https://github.com/golang/go
synced 2024-11-18 19:14:40 -07:00
9a0fabac01
While experimenting with different static analysis on x/tools, I noticed that there are many actionable diagnostics found by staticcheck. Fix the ones that were not false positives. Change-Id: I0b68cf1f636b57b557db879fad84fff9b7237a89 Reviewed-on: https://go-review.googlesource.com/c/tools/+/222248 Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
68 lines
1.8 KiB
Go
68 lines
1.8 KiB
Go
// Copyright 2020 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 (
|
|
"flag"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"net/http"
|
|
"os"
|
|
"path"
|
|
)
|
|
|
|
var bucket = flag.String("bucket", "golang-gopls_integration_tests", "GCS bucket holding test artifacts.")
|
|
|
|
const usage = `
|
|
artifacts [--bucket=<bucket ID>] <cloud build evaluation ID>
|
|
|
|
Fetch artifacts from an integration test run. Evaluation ID should be extracted
|
|
from the cloud build notification.
|
|
|
|
In order for this to work, the GCS bucket that artifacts were written to must
|
|
be publicly readable. By default, this fetches from the
|
|
golang-gopls_integration_tests bucket.
|
|
`
|
|
|
|
func main() {
|
|
flag.Usage = func() {
|
|
fmt.Fprint(flag.CommandLine.Output(), usage)
|
|
}
|
|
flag.Parse()
|
|
if flag.NArg() != 1 {
|
|
flag.Usage()
|
|
os.Exit(2)
|
|
}
|
|
evalID := flag.Arg(0)
|
|
logURL := fmt.Sprintf("https://storage.googleapis.com/%s/log-%s.txt", *bucket, evalID)
|
|
if err := download(logURL); err != nil {
|
|
fmt.Fprintf(os.Stderr, "downloading logs: %v", err)
|
|
}
|
|
tarURL := fmt.Sprintf("https://storage.googleapis.com/%s/govim/%s/artifacts.tar.gz", *bucket, evalID)
|
|
if err := download(tarURL); err != nil {
|
|
fmt.Fprintf(os.Stderr, "downloading artifact tarball: %v", err)
|
|
}
|
|
}
|
|
|
|
func download(artifactURL string) error {
|
|
name := path.Base(artifactURL)
|
|
resp, err := http.Get(artifactURL)
|
|
if err != nil {
|
|
return fmt.Errorf("fetching from GCS: %v", err)
|
|
}
|
|
defer resp.Body.Close()
|
|
if resp.StatusCode != http.StatusOK {
|
|
return fmt.Errorf("got status code %d from GCS", resp.StatusCode)
|
|
}
|
|
data, err := ioutil.ReadAll(resp.Body)
|
|
if err != nil {
|
|
return fmt.Errorf("reading result: %v", err)
|
|
}
|
|
if err := ioutil.WriteFile(name, data, 0644); err != nil {
|
|
return fmt.Errorf("writing artifact: %v", err)
|
|
}
|
|
return nil
|
|
}
|