diff options
author | Ayush Ranjan <ayushranjan@google.com> | 2021-04-23 12:31:41 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2021-04-23 12:33:48 -0700 |
commit | 915b8137981e5acb48b58f378a058b88938d44d4 (patch) | |
tree | 9af0c25075dfbce5c3b22c9355c67e71dfc8d82b /tools/github | |
parent | 9e4aa04ad1f6e63f4aa99f516b19e4ff2592918b (diff) |
[op] Remove Build job from GitHub actions.
We already have blocking nogo tests which show all findings. This job was
building all nogo targets, and posting all the findings to GitHub as a check
run. Building nogo takes a while so we actually end up wasting a lot of time
doing redundant work.
This is aligned with our goal of moving away from GitHub actions to BuildKite
only.
PiperOrigin-RevId: 370134875
Diffstat (limited to 'tools/github')
-rw-r--r-- | tools/github/BUILD | 1 | ||||
-rw-r--r-- | tools/github/main.go | 35 | ||||
-rw-r--r-- | tools/github/nogo/BUILD | 16 | ||||
-rw-r--r-- | tools/github/nogo/nogo.go | 132 |
4 files changed, 5 insertions, 179 deletions
diff --git a/tools/github/BUILD b/tools/github/BUILD index 7d0a179f7..a345debf6 100644 --- a/tools/github/BUILD +++ b/tools/github/BUILD @@ -7,7 +7,6 @@ go_binary( srcs = ["main.go"], nogo = False, deps = [ - "//tools/github/nogo", "//tools/github/reviver", "@com_github_google_go_github_v32//github:go_default_library", "@org_golang_x_oauth2//:go_default_library", diff --git a/tools/github/main.go b/tools/github/main.go index 681003eef..dfb4c769d 100644 --- a/tools/github/main.go +++ b/tools/github/main.go @@ -22,12 +22,10 @@ import ( "io/ioutil" "log" "os" - "os/exec" "strings" "github.com/google/go-github/github" "golang.org/x/oauth2" - "gvisor.dev/gvisor/tools/github/nogo" "gvisor.dev/gvisor/tools/github/reviver" ) @@ -53,11 +51,10 @@ func (s *stringList) Set(value string) error { // Keep the options simple for now. Supports only a single path and repo. func init() { - flag.StringVar(&owner, "owner", "", "GitHub project org/owner (required, except nogo dry-run)") - flag.StringVar(&repo, "repo", "", "GitHub repo (required, except nogo dry-run)") + flag.StringVar(&owner, "owner", "", "GitHub project org/owner") + flag.StringVar(&repo, "repo", "", "GitHub repo") flag.StringVar(&tokenFile, "oauth-token-file", "", "file containing the GitHub token (or GITHUB_TOKEN is set)") - flag.Var(&paths, "path", "path(s) to scan (required for revive and nogo)") - flag.StringVar(&commit, "commit", "", "commit to associated (required for nogo, except dry-run)") + flag.Var(&paths, "path", "path(s) to scan (required for revive)") flag.BoolVar(&dryRun, "dry-run", false, "just print changes to be made") } @@ -96,12 +93,12 @@ func main() { // Check for mandatory parameters. command := args[0] - if len(owner) == 0 && (command != "nogo" || !dryRun) { + if len(owner) == 0 { fmt.Fprintln(flag.CommandLine.Output(), "missing --owner option.") flag.Usage() os.Exit(1) } - if len(repo) == 0 && (command != "nogo" || !dryRun) { + if len(repo) == 0 { fmt.Fprintln(flag.CommandLine.Output(), "missing --repo option.") flag.Usage() os.Exit(1) @@ -155,28 +152,6 @@ func main() { } os.Exit(1) } - case "nogo": - // Did we get a commit? Try to extract one. - if len(commit) == 0 && !dryRun { - cmd := exec.Command("git", "rev-parse", "HEAD") - revBytes, err := cmd.Output() - if err != nil { - fmt.Fprintf(flag.CommandLine.Output(), "missing --commit option, unable to infer: %v\n", err) - flag.Usage() - os.Exit(1) - } - commit = strings.TrimSpace(string(revBytes)) - } - // Scan all findings. - poster := nogo.NewFindingsPoster(client, owner, repo, commit, dryRun) - if err := poster.Walk(filteredPaths); err != nil { - fmt.Fprintln(os.Stderr, "Error finding nogo findings:", err) - os.Exit(1) - } - // Post to GitHub. - if err := poster.Post(); err != nil { - fmt.Fprintln(os.Stderr, "Error posting nogo findings:", err) - } default: // Not a known command. fmt.Fprintf(flag.CommandLine.Output(), "unknown command: %s\n", command) diff --git a/tools/github/nogo/BUILD b/tools/github/nogo/BUILD deleted file mode 100644 index 4259fe94c..000000000 --- a/tools/github/nogo/BUILD +++ /dev/null @@ -1,16 +0,0 @@ -load("//tools:defs.bzl", "go_library") - -package(licenses = ["notice"]) - -go_library( - name = "nogo", - srcs = ["nogo.go"], - nogo = False, - visibility = [ - "//tools/github:__subpackages__", - ], - deps = [ - "//tools/nogo", - "@com_github_google_go_github_v32//github:go_default_library", - ], -) diff --git a/tools/github/nogo/nogo.go b/tools/github/nogo/nogo.go deleted file mode 100644 index 894a0e7c3..000000000 --- a/tools/github/nogo/nogo.go +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright 2019 The gVisor Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package nogo provides nogo-related utilities. -package nogo - -import ( - "context" - "fmt" - "os" - "path/filepath" - "strings" - "time" - - "github.com/google/go-github/github" - "gvisor.dev/gvisor/tools/nogo" -) - -// FindingsPoster is a simple wrapper around the GitHub api. -type FindingsPoster struct { - owner string - repo string - commit string - dryRun bool - startTime time.Time - - findings map[nogo.Finding]struct{} - client *github.Client -} - -// NewFindingsPoster returns a object that can post findings. -func NewFindingsPoster(client *github.Client, owner, repo, commit string, dryRun bool) *FindingsPoster { - return &FindingsPoster{ - owner: owner, - repo: repo, - commit: commit, - dryRun: dryRun, - startTime: time.Now(), - findings: make(map[nogo.Finding]struct{}), - client: client, - } -} - -// Walk walks the given path tree for findings files. -func (p *FindingsPoster) Walk(paths []string) error { - for _, path := range paths { - if err := filepath.Walk(path, func(filename string, info os.FileInfo, err error) error { - if err != nil { - return err - } - // Skip any directories or files not ending in .findings. - if !strings.HasSuffix(filename, ".findings") || info.IsDir() { - return nil - } - findings, err := nogo.ExtractFindingsFromFile(filename) - if err != nil { - return err - } - // Add all findings to the list. We use a map to ensure - // that each finding is unique. - for _, finding := range findings { - p.findings[finding] = struct{}{} - } - return nil - }); err != nil { - return err - } - } - return nil -} - -// Post posts all results to the GitHub API as a check run. -func (p *FindingsPoster) Post() error { - // Just show results? - if p.dryRun { - for finding := range p.findings { - // Pretty print, so that this is useful for debugging. - fmt.Printf("%s: (%s+%d) %s\n", finding.Category, finding.Position.Filename, finding.Position.Line, finding.Message) - } - return nil - } - - // Construct the message. - title := "nogo" - count := len(p.findings) - status := "completed" - conclusion := "success" - if count > 0 { - conclusion = "failure" // Contains errors. - } - summary := fmt.Sprintf("%d findings.", count) - opts := github.CreateCheckRunOptions{ - Name: title, - HeadSHA: p.commit, - Status: &status, - Conclusion: &conclusion, - StartedAt: &github.Timestamp{p.startTime}, - CompletedAt: &github.Timestamp{time.Now()}, - Output: &github.CheckRunOutput{ - Title: &title, - Summary: &summary, - AnnotationsCount: &count, - }, - } - annotationLevel := "failure" // Always. - for finding := range p.findings { - title := string(finding.Category) - opts.Output.Annotations = append(opts.Output.Annotations, &github.CheckRunAnnotation{ - Path: &finding.Position.Filename, - StartLine: &finding.Position.Line, - EndLine: &finding.Position.Line, - Message: &finding.Message, - Title: &title, - AnnotationLevel: &annotationLevel, - }) - } - - // Post to GitHub. - _, _, err := p.client.Checks.CreateCheckRun(context.Background(), p.owner, p.repo, opts) - return err -} |