Skip to content

Commit

Permalink
ci: print error when getting tags fails
Browse files Browse the repository at this point in the history
This commit also removes fatal logs. The pruning process isn't essential
and should generally never cause the CI to report failure.
  • Loading branch information
rfratto committed Feb 5, 2020
1 parent 1fe5dc4 commit b05dbf7
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions tools/delete_tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ type auth struct {
Password string `json:"password"`
}

func logAndQuit(fmt string, args ...interface{}) {
log.Printf(fmt, args...)
os.Exit(0)
}

func main() {
var (
auth auth
Expand Down Expand Up @@ -51,12 +56,12 @@ func main() {
// Get an auth token
jwt, err := getJWT(auth)
if err != nil {
log.Fatalln(err)
logAndQuit(err.Error())
}

tags, err := getTags(jwt, repo)
if err != nil {
log.Fatalln(err)
logAndQuit(err.Error())
}

log.Printf("Discovered %d tags pre-filtering\n", len(tags))
Expand Down Expand Up @@ -108,7 +113,7 @@ func getJWT(a auth) (string, error) {
return "", err
}
resp.Body.Close()
log.Fatalf("failed to log in: %v", string(body))
return "", fmt.Errorf("failed to log in: %v", string(body))
}
defer resp.Body.Close()

Expand Down Expand Up @@ -165,11 +170,16 @@ func getTagsFromURL(jwt string, url string) (getTagResponse, error) {
if err != nil {
return res, err
}
if resp.StatusCode != 200 {
return res, errors.New("failed to get tags")
}
defer resp.Body.Close()

if resp.StatusCode/100 != 2 {
bb, err := ioutil.ReadAll(resp.Body)
if err != nil {
return res, err
}
return res, errors.New(string(bb))
}

err = json.NewDecoder(resp.Body).Decode(&res)
return res, err
}
Expand All @@ -188,10 +198,13 @@ func deleteTag(jwt string, repo string, tag string) error {
}
defer resp.Body.Close()

bb, err := ioutil.ReadAll(resp.Body)
if resp.StatusCode/100 != 2 {
return fmt.Errorf("resp code %d: %s", resp.StatusCode, string(bb))
bb, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
return errors.New(string(bb))
}

return err
return nil
}

0 comments on commit b05dbf7

Please sign in to comment.