Skip to content

Commit 1906520

Browse files
committed
chore: add logs for better feedback
1 parent 902b32f commit 1906520

File tree

1 file changed

+45
-14
lines changed
  • .github/scripts/readme-validation

1 file changed

+45
-14
lines changed

.github/scripts/readme-validation/main.go

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"github.com/ghodss/yaml"
1616
)
1717

18-
const rootRegistryPath = "./registry"
18+
const rootRegistryPath = "../../../registry"
1919

2020
type directoryReadme struct {
2121
FilePath string
@@ -70,7 +70,7 @@ type workflowPhaseError struct {
7070
}
7171

7272
func (wpe workflowPhaseError) Error() string {
73-
msg := fmt.Sprintf("Error during phase %q of README validation:", wpe.Phase)
73+
msg := fmt.Sprintf("Error during %q phase of README validation:", wpe.Phase)
7474
for _, e := range wpe.Errors {
7575
msg += fmt.Sprintf("\n- %v", e)
7676
}
@@ -456,59 +456,75 @@ func parseContributorFiles(input []directoryReadme) (
456456
return structured, nil
457457
}
458458

459-
func backfillAvatarUrls(contributors map[string]contributorProfile) error {
459+
// backfillAvatarUrls takes a map of contributor information, each keyed by
460+
// GitHub username, and tries to mutate each entry to fill in its missing avatar
461+
// URL. The first integer indicates the number of avatars that needed to be
462+
// backfilled, while the second indicates the number that could be backfilled
463+
// without any errors.
464+
//
465+
// The function will collect all request errors, rather than return the first
466+
// one found.
467+
func backfillAvatarUrls(contributors map[string]contributorProfile) (int, int, error) {
460468
if contributors == nil {
461-
return errors.New("provided map is nil")
469+
return 0, 0, errors.New("provided map is nil")
462470
}
463471

464472
wg := sync.WaitGroup{}
473+
mtx := sync.Mutex{}
465474
errors := []error{}
466-
errorsMutex := sync.Mutex{}
475+
successfulBackfills := 0
467476

468477
// Todo: Add actual fetching logic once everything else has been verified
469478
requestAvatarUrl := func(string) (string, error) {
470479
return "", nil
471480
}
472481

473-
for ghUsername, conCopy := range contributors {
474-
if conCopy.AvatarUrl != "" {
482+
avatarsThatNeedBackfill := 0
483+
for ghUsername, con := range contributors {
484+
if con.AvatarUrl != "" {
475485
continue
476486
}
477487

488+
avatarsThatNeedBackfill++
478489
wg.Add(1)
479490
go func() {
480491
defer wg.Done()
481492
url, err := requestAvatarUrl(ghUsername)
493+
mtx.Lock()
494+
defer mtx.Unlock()
495+
482496
if err != nil {
483-
errorsMutex.Lock()
484497
errors = append(errors, err)
485-
errorsMutex.Unlock()
486498
return
487499
}
488-
conCopy.AvatarUrl = url
489-
contributors[ghUsername] = conCopy
500+
501+
successfulBackfills++
502+
con.AvatarUrl = url
503+
contributors[ghUsername] = con
490504
}()
491505
}
492506

493507
wg.Wait()
494508
if len(errors) == 0 {
495-
return nil
509+
return avatarsThatNeedBackfill, successfulBackfills, nil
496510
}
497511

498512
slices.SortFunc(errors, func(e1 error, e2 error) int {
499513
return strings.Compare(e1.Error(), e2.Error())
500514
})
501-
return workflowPhaseError{
515+
return avatarsThatNeedBackfill, successfulBackfills, workflowPhaseError{
502516
Phase: "Avatar Backfill",
503517
Errors: errors,
504518
}
505519
}
506520

507521
func main() {
522+
log.Println("Starting README validation")
508523
dirEntries, err := os.ReadDir(rootRegistryPath)
509524
if err != nil {
510525
log.Panic(err)
511526
}
527+
log.Printf("Identified %d top-level directory entries\n", len(dirEntries))
512528

513529
allReadmeFiles := []directoryReadme{}
514530
fsErrors := workflowPhaseError{
@@ -543,14 +559,29 @@ func main() {
543559
log.Panic(fsErrors)
544560
}
545561

562+
log.Printf("Processing %d README files\n", len(allReadmeFiles))
546563
contributors, err := parseContributorFiles(allReadmeFiles)
547564
if err != nil {
548565
log.Panic(err)
549566
}
550-
err = backfillAvatarUrls(contributors)
567+
log.Printf(
568+
"Processed %d README files as valid contributor profiles",
569+
len(contributors),
570+
)
571+
572+
backfillsNeeded, successCount, err := backfillAvatarUrls(contributors)
551573
if err != nil {
552574
log.Panic(err)
553575
}
576+
if backfillsNeeded == 0 {
577+
log.Println("No GitHub avatar backfills needed")
578+
} else {
579+
log.Printf(
580+
"Backfilled %d/%d missing GitHub avatars",
581+
backfillsNeeded,
582+
successCount,
583+
)
584+
}
554585

555586
log.Printf(
556587
"Processed all READMEs in the %q directory\n",

0 commit comments

Comments
 (0)