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/config"
|
||||||
"github.com/trustwallet/assets/internal/file"
|
"github.com/trustwallet/assets/internal/file"
|
||||||
"github.com/trustwallet/assets/internal/processor"
|
"github.com/trustwallet/assets/internal/processor"
|
||||||
|
"github.com/trustwallet/assets/internal/report"
|
||||||
"github.com/trustwallet/assets/internal/service"
|
"github.com/trustwallet/assets/internal/service"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -23,9 +24,10 @@ func main() {
|
||||||
log.WithError(err).Fatal("Failed to load file structure.")
|
log.WithError(err).Fatal("Failed to load file structure.")
|
||||||
}
|
}
|
||||||
|
|
||||||
fileStorage := file.NewService(paths...)
|
fileService := file.NewService(paths...)
|
||||||
validatorsService := processor.NewService(fileStorage)
|
validatorsService := processor.NewService(fileService)
|
||||||
assetfsProcessor := service.NewService(fileStorage, validatorsService)
|
reportService := report.NewService()
|
||||||
|
assetfsProcessor := service.NewService(fileService, validatorsService, reportService)
|
||||||
|
|
||||||
switch script {
|
switch script {
|
||||||
case "checker":
|
case "checker":
|
||||||
|
@ -39,6 +41,14 @@ func main() {
|
||||||
default:
|
default:
|
||||||
log.Info("Nothing to launch. Use --script flag to choose a script to run.")
|
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() {
|
func setup() {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package file
|
package file
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
@ -147,7 +148,7 @@ func ReadLocalFileStructure(root string, filesToSkip []string) ([]string, error)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
paths = append(paths, path)
|
paths = append(paths, fmt.Sprintf("./%s", path))
|
||||||
|
|
||||||
return nil
|
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-go-libs/validation"
|
||||||
"github.com/trustwallet/assets/internal/file"
|
"github.com/trustwallet/assets/internal/file"
|
||||||
"github.com/trustwallet/assets/internal/processor"
|
"github.com/trustwallet/assets/internal/processor"
|
||||||
|
"github.com/trustwallet/assets/internal/report"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
@ -11,12 +12,14 @@ import (
|
||||||
type Service struct {
|
type Service struct {
|
||||||
fileService *file.Service
|
fileService *file.Service
|
||||||
processorService *processor.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{
|
return &Service{
|
||||||
fileService: fs,
|
fileService: fs,
|
||||||
processorService: cs,
|
processorService: cs,
|
||||||
|
reportService: rs,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +27,7 @@ func (s *Service) RunJob(paths []string, job func(*file.AssetFile)) {
|
||||||
for _, path := range paths {
|
for _, path := range paths {
|
||||||
f := s.fileService.GetAssetFile(path)
|
f := s.fileService.GetAssetFile(path)
|
||||||
job(f)
|
job(f)
|
||||||
|
s.reportService.IncTotalFiles()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,8 +36,7 @@ func (s *Service) Check(f *file.AssetFile) {
|
||||||
|
|
||||||
if validator != nil {
|
if validator != nil {
|
||||||
if err := validator.Run(f); err != nil {
|
if err := validator.Run(f); err != nil {
|
||||||
// TODO: somehow return an error from Check if there are any errors.
|
s.handleError(err, f, validator.Name)
|
||||||
HandleError(err, f, validator.Name)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,7 +46,7 @@ func (s *Service) Fix(f *file.AssetFile) {
|
||||||
|
|
||||||
for _, fixer := range fixers {
|
for _, fixer := range fixers {
|
||||||
if err := fixer.Run(f); err != nil {
|
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)
|
errors := UnwrapComposite(err)
|
||||||
|
|
||||||
for _, err := range errors {
|
for _, err := range errors {
|
||||||
|
@ -78,6 +81,8 @@ func HandleError(err error, info *file.AssetFile, valName string) {
|
||||||
"path": info.Path(),
|
"path": info.Path(),
|
||||||
"validation": valName,
|
"validation": valName,
|
||||||
}).Error(err)
|
}).Error(err)
|
||||||
|
|
||||||
|
s.reportService.IncErrors()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user