Add reporter for CI scripts (#16774)

* Add reporter for CI scripts

* Fix asset errors
This commit is contained in:
Daniel 2021-12-23 22:30:20 +03:00 committed by GitHub
parent a6418fcbb5
commit 8c997de194
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 53 additions and 9 deletions

View File

@ -8,6 +8,7 @@ import (
"github.com/trustwallet/assets/internal/config"
"github.com/trustwallet/assets/internal/file"
"github.com/trustwallet/assets/internal/processor"
"github.com/trustwallet/assets/internal/report"
"github.com/trustwallet/assets/internal/service"
)
@ -23,9 +24,10 @@ func main() {
log.WithError(err).Fatal("Failed to load file structure.")
}
fileStorage := file.NewService(paths...)
validatorsService := processor.NewService(fileStorage)
assetfsProcessor := service.NewService(fileStorage, validatorsService)
fileService := file.NewService(paths...)
validatorsService := processor.NewService(fileService)
reportService := report.NewService()
assetfsProcessor := service.NewService(fileService, validatorsService, reportService)
switch script {
case "checker":
@ -39,6 +41,14 @@ func main() {
default:
log.Info("Nothing to launch. Use --script flag to choose a script to run.")
}
reportMsg := reportService.GetReport()
if reportService.IsFailed() {
log.Fatal(reportMsg)
} else {
log.Info(reportMsg)
}
}
func setup() {

View File

@ -1,6 +1,7 @@
package file
import (
"fmt"
"os"
"path/filepath"
"regexp"
@ -147,7 +148,7 @@ func ReadLocalFileStructure(root string, filesToSkip []string) ([]string, error)
return nil
}
paths = append(paths, path)
paths = append(paths, fmt.Sprintf("./%s", path))
return nil
})

View File

@ -0,0 +1,28 @@
package report
import "fmt"
type Service struct {
errors int
totalFiles int
}
func NewService() *Service {
return &Service{}
}
func (s *Service) IncErrors() {
s.errors += 1
}
func (s *Service) IncTotalFiles() {
s.totalFiles += 1
}
func (s Service) IsFailed() bool {
return s.errors > 0
}
func (s Service) GetReport() string {
return fmt.Sprintf("Total files: %d, errors: %d", s.totalFiles, s.errors)
}

View File

@ -4,6 +4,7 @@ import (
"github.com/trustwallet/assets-go-libs/validation"
"github.com/trustwallet/assets/internal/file"
"github.com/trustwallet/assets/internal/processor"
"github.com/trustwallet/assets/internal/report"
log "github.com/sirupsen/logrus"
)
@ -11,12 +12,14 @@ import (
type Service struct {
fileService *file.Service
processorService *processor.Service
reportService *report.Service
}
func NewService(fs *file.Service, cs *processor.Service) *Service {
func NewService(fs *file.Service, cs *processor.Service, rs *report.Service) *Service {
return &Service{
fileService: fs,
processorService: cs,
reportService: rs,
}
}
@ -24,6 +27,7 @@ func (s *Service) RunJob(paths []string, job func(*file.AssetFile)) {
for _, path := range paths {
f := s.fileService.GetAssetFile(path)
job(f)
s.reportService.IncTotalFiles()
}
}
@ -32,8 +36,7 @@ func (s *Service) Check(f *file.AssetFile) {
if validator != nil {
if err := validator.Run(f); err != nil {
// TODO: somehow return an error from Check if there are any errors.
HandleError(err, f, validator.Name)
s.handleError(err, f, validator.Name)
}
}
}
@ -43,7 +46,7 @@ func (s *Service) Fix(f *file.AssetFile) {
for _, fixer := range fixers {
if err := fixer.Run(f); err != nil {
HandleError(err, f, fixer.Name)
s.handleError(err, f, fixer.Name)
}
}
}
@ -67,7 +70,7 @@ func (s *Service) runUpdaters(updaters []processor.Updater) {
}
}
func HandleError(err error, info *file.AssetFile, valName string) {
func (s *Service) handleError(err error, info *file.AssetFile, valName string) {
errors := UnwrapComposite(err)
for _, err := range errors {
@ -78,6 +81,8 @@ func HandleError(err error, info *file.AssetFile, valName string) {
"path": info.Path(),
"validation": valName,
}).Error(err)
s.reportService.IncErrors()
}
}