mirror of
https://github.com/Instadapp/trustwallet-assets.git
synced 2024-07-29 22:37:31 +00:00
Add reporter for CI scripts (#16774)
* Add reporter for CI scripts * Fix asset errors
This commit is contained in:
parent
a6418fcbb5
commit
8c997de194
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB |
16
cmd/main.go
16
cmd/main.go
|
@ -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() {
|
||||
|
|
|
@ -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
|
||||
})
|
||||
|
|
28
internal/report/service.go
Normal file
28
internal/report/service.go
Normal 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)
|
||||
}
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user