Skip to content

Commit c442956

Browse files
author
Janos Bonic
committed
Fixes #21: Failed to recognize go mod updates needed.
1 parent 27b2be7 commit c442956

File tree

10 files changed

+1357
-27
lines changed

10 files changed

+1357
-27
lines changed

.gotestfmt/downloads.gotpl

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
This template contains the format for a package download.
44
*/ -}}
55
{{- $settings := .Settings -}}
6-
{{- if .Packages -}}
6+
{{- if or .Packages .Reason -}}
77
{{- if or (not $settings.HideSuccessfulDownloads) .Failed -}}
88
{{- if .Failed -}}
99
{{ "\033" }}[0;31m❌
@@ -31,4 +31,7 @@ This template contains the format for a package download.
3131
{{- end -}}
3232
{{- end -}}
3333
{{- end -}}
34+
{{- with .Reason -}}
35+
{{- " " -}}{{- "\033" }}[0;31m🛑 {{ . }}{{- "\033" }}[0m{{ "\n" -}}
36+
{{- end -}}
3437
{{- end -}}

.gotestfmt/github/downloads.gotpl

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
This template contains the format for a package download.
44
*/ -}}
55
{{- $settings := .Settings -}}
6-
{{- if .Packages -}}
6+
{{- if or .Packages .Reason -}}
77
{{- if or (not .Settings.HideSuccessfulDownloads) .Failed -}}
88
::group::
99
{{- if .Failed -}}
@@ -31,6 +31,9 @@ This template contains the format for a package download.
3131
{{- end -}}
3232
{{- end -}}
3333
{{- end -}}
34+
{{- with .Reason -}}
35+
{{- " " -}}{{- "\033" }}[0;31m🛑 {{ . }}{{- "\033" }}[0m{{ "\n" -}}
36+
{{- end -}}
3437
::endgroup::
3538
{{- end -}}
36-
{{- end -}}
39+
{{- end -}}

.gotestfmt/gitlab/downloads.gotpl

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
This template contains the format for a package download.
44
*/ -}}
55
{{- $settings := .Settings -}}
6-
{{- if .Packages -}}
6+
{{- if or .Packages .Reason -}}
77
{{- if or (not .Settings.HideSuccessfulDownloads) .Failed -}}
88
{{- "\033" }}[0Ksection_start:{{ with .StartTime }}{{ .Unix }}{{ else }}0{{ end }}:dependency_downloads{{ "\r\033" }}[0K{{- "\n" -}}
99
{{- if .Failed -}}
@@ -31,6 +31,9 @@ This template contains the format for a package download.
3131
{{- end -}}
3232
{{- end -}}
3333
{{- end -}}
34-
{{- "\033" }}[0Ksection_start:{{ with .EndTime }}{{ .Unix }}{{ else }}0{{ end }}:dependency_downloads{{ "\r\033" }}[0K{{- "\n" -}}
34+
{{- with .Reason -}}
35+
{{- " " -}}{{- "\033" }}[0;31m🛑 {{ . }}{{- "\033" }}[0m{{ "\n" -}}
36+
{{- end -}}
37+
{{- "\033" }}[0Ksection_end:{{ with .EndTime }}{{ .Unix }}{{ else }}0{{ end }}:dependency_downloads{{ "\r\033" }}[0K{{- "\n" -}}
3538
{{- end -}}
3639
{{- end -}}

.gotestfmt/teamcity/downloads.gotpl

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
This template contains the format for a package download.
44
*/ -}}
55
{{- $settings := .Settings -}}
6-
{{- if .Packages -}}
6+
{{- if or .Packages .Reason -}}
77
{{- if or (not $settings.HideSuccessfulDownloads) .Failed -}}
88
{{- $title := "Dependency downloads" -}}
99
{{- if .Failed -}}
1010
{{- $title = print "❌ " $title -}}
1111
{{- else -}}
1212
{{- $title = print "📥 " $title -}}
1313
{{- end -}}
14-
##teamcity[blockOpened name='{{ $title }}']
15-
14+
##teamcity[blockOpened name='{{ $title }}']{{ "\n" -}}
1615
{{- range .Packages -}}
1716
{{- if or (not $settings.HideSuccessfulDownloads) .Failed -}}
1817
{{- " " -}}
@@ -29,6 +28,9 @@ This template contains the format for a package download.
2928
{{- end -}}
3029
{{- end -}}
3130
{{- end -}}
31+
{{- with .Reason -}}
32+
{{- " " -}}🛑 {{ . }}{{ "\n" -}}
33+
{{- end -}}
3234
##teamcity[blockClosed name='{{ $title }}']
3335
{{- end -}}
3436
{{- end -}}

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ This file contains the output fragment showing the package downloads in the Go t
219219
| `.Packages` | `[]Package` | A list of packages that have been processed. |
220220
| `.StartTime` | `*time.Time` | The time the first download line was seen. May be empty. |
221221
| `.EndTime` | `*time.Time` | The time the last download line was seen. May be empty. |
222+
| `.Reason` | `string` | If an extra reason is given for the failure, the text is included here. |
222223
| `.Settings` | [`RenderSettings`](#render-settings) | The render settings (what to hide, etc, [see below](#render-settings)). |
223224

224225
The `Package` items have the following format:

parser/model.go

+3
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ func (p *Package) ID() string {
9090
)
9191
}
9292

93+
// Download is the download information about a single package.
9394
type Download struct {
9495
// Package is the name of the package being downloaded.
9596
Package string `json:"package"`
@@ -111,6 +112,8 @@ type Downloads struct {
111112
StartTime *time.Time `json:"-"`
112113
// EndTime indicates when the downloads finished.
113114
EndTime *time.Time `json:"-"`
115+
// Reason describes the failure reason if a separate one is present.
116+
Reason string `json:"reason"`
114117
}
115118

116119
// ParseResult is an overall structure for parser results, containing the prefix text, downloads and packagesByName.

parser/parse.go

+45-19
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,32 @@ func Parse(
2121
) (<-chan string, <-chan *Downloads, <-chan *Package) {
2222
prefixChannel := make(chan string)
2323
downloadsChannel := make(chan *Downloads)
24+
downloadsFailureReason := make(chan string)
2425
packagesChannel := make(chan *Package)
25-
go parse(evts, prefixChannel, downloadsChannel, packagesChannel)
26+
go parse(evts, prefixChannel, downloadsChannel, downloadsFailureReason, packagesChannel)
2627
return prefixChannel, downloadsChannel, packagesChannel
2728
}
2829

2930
var downloadErrors = []*regexp.Regexp{
3031
regexp.MustCompile(`no required module provides package (?P<package>[^\s]+);`),
32+
regexp.MustCompile(`updates to go.mod needed; to update it:`),
3133
}
3234

3335
func parse(
3436
evts <-chan tokenizer.Event,
3537
prefixChannel chan string,
3638
downloadsChannel chan *Downloads,
39+
downloadsFailureReason chan string,
3740
packagesChannel chan *Package,
3841
) {
3942
outputStarted := false
4043
downloadTracker := &downloadsTracker{
41-
prefixChannel: prefixChannel,
42-
downloadResultsList: nil,
43-
downloadsByPackage: map[string]*Download{},
44-
downloadsFinished: false,
45-
target: downloadsChannel,
44+
prefixChannel: prefixChannel,
45+
downloadResultsList: nil,
46+
downloadsByPackage: map[string]*Download{},
47+
downloadsFinished: false,
48+
downloadsFailureReason: downloadsFailureReason,
49+
target: downloadsChannel,
4650
}
4751
pkgTracker := &packageTracker{
4852
packagesByName: map[string]*Package{},
@@ -131,17 +135,26 @@ func parse(
131135
foundDLError := false
132136
for _, dlError := range downloadErrors {
133137
if submatch := dlError.FindSubmatch(evt.Output); len(submatch) > 0 {
134-
pkgName := string(submatch[1])
135-
downloadTracker.SetDownloadFailed(pkgName, "")
136-
downloadTracker.AddReason(pkgName, evt.Output)
137-
prevErroredDownload = pkgName
138+
if len(submatch) > 1 {
139+
pkgName := string(submatch[1])
140+
downloadTracker.SetDownloadFailed(pkgName, "")
141+
downloadTracker.AddReason(pkgName, evt.Output)
142+
prevErroredDownload = pkgName
143+
} else {
144+
downloadTracker.SetFailureReason(submatch[0])
145+
prevErroredDownload = "*"
146+
}
138147
foundDLError = true
139148
outputStarted = true
140149
}
141150
}
142151
if !foundDLError {
143152
if prevErroredDownload != "" {
144-
downloadTracker.AddReason(prevErroredDownload, evt.Output)
153+
if prevErroredDownload == "*" {
154+
downloadTracker.SetFailureReason(evt.Output)
155+
} else {
156+
downloadTracker.AddReason(prevErroredDownload, evt.Output)
157+
}
145158
} else if prevErroredPkg != "" {
146159
pkgTracker.AddOutput(prevErroredPkg, "", evt.Output)
147160
} else if !outputStarted {
@@ -341,14 +354,16 @@ func compareTestCaseNames(name1 string, name2 string) bool {
341354
}
342355

343356
type downloadsTracker struct {
344-
downloadResultsList []*Download
345-
downloadsByPackage map[string]*Download
346-
downloadsFinished bool
347-
lastDownload *Download
348-
target chan *Downloads
349-
prefixChannel chan string
350-
startTime *time.Time
351-
endTime *time.Time
357+
downloadResultsList []*Download
358+
downloadsByPackage map[string]*Download
359+
downloadsFinished bool
360+
lastDownload *Download
361+
target chan *Downloads
362+
prefixChannel chan string
363+
startTime *time.Time
364+
endTime *time.Time
365+
downloadsFailureReason chan string
366+
failureReason []byte
352367
}
353368

354369
func (d *downloadsTracker) Add(name string, version string) {
@@ -379,11 +394,15 @@ func (d *downloadsTracker) Write() {
379394
}
380395
dl.Reason = strings.TrimRight(dl.Reason, "\n")
381396
}
397+
if len(d.failureReason) > 0 {
398+
failed = true
399+
}
382400
d.target <- &Downloads{
383401
Packages: d.downloadResultsList,
384402
Failed: failed,
385403
StartTime: d.startTime,
386404
EndTime: d.endTime,
405+
Reason: strings.TrimSpace(string(d.failureReason)),
387406
}
388407
d.downloadsFinished = true
389408
d.downloadResultsList = nil
@@ -424,3 +443,10 @@ func (d *downloadsTracker) AddReason(name string, output []byte) {
424443
pkg := d.ensurePackage(name)
425444
pkg.Reason = pkg.Reason + string(output) + "\n"
426445
}
446+
447+
func (d *downloadsTracker) SetFailureReason(output []byte) {
448+
if d.downloadsFinished {
449+
panic(fmt.Errorf("tried to add download failure reason after downloads are already finished"))
450+
}
451+
d.failureReason = append(append(d.failureReason, output...), '\n')
452+
}

0 commit comments

Comments
 (0)