Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 88f7be2

Browse files
committed
chore: set up initial version of CI
1 parent 3b9ec5e commit 88f7be2

File tree

2 files changed

+37
-16
lines changed

2 files changed

+37
-16
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Validate README files
2+
on:
3+
pull_request:
4+
branches:
5+
- main
6+
jobs:
7+
validate-contributors:
8+
runs-on: ubuntu-latest
9+
strategy:
10+
fail-fast: true
11+
matrix:
12+
go-version: ["1.23.x"]
13+
steps:
14+
- name: Check out code
15+
uses: actions/checkout@v4
16+
- name: Set up Go ${{ matrix.go-version }}
17+
uses: actions/setup-go@v5
18+
with:
19+
go-version: ${{ matrix.go-version }}
20+
- name: Validate
21+
run: go run ./scripts/validate-contributor-readmes/main.go

scripts/validate-contributor-readmes/main.go

+16-16
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616

1717
const rootRegistryPath = "./registry"
1818

19-
type directoryReadme struct {
19+
type readme struct {
2020
FilePath string
2121
RawText string
2222
}
@@ -38,16 +38,16 @@ type contributorFrontmatterWithFilePath struct {
3838
FilePath string
3939
}
4040

41-
var _ error = workflowPhaseError{}
41+
var _ error = validationPhaseError{}
4242

43-
type workflowPhaseError struct {
43+
type validationPhaseError struct {
4444
Phase string
4545
Errors []error
4646
}
4747

48-
func (wpe workflowPhaseError) Error() string {
49-
msg := fmt.Sprintf("Error during %q phase of README validation:", wpe.Phase)
50-
for _, e := range wpe.Errors {
48+
func (vpe validationPhaseError) Error() string {
49+
msg := fmt.Sprintf("Error during %q phase of README validation:", vpe.Phase)
50+
for _, e := range vpe.Errors {
5151
msg += fmt.Sprintf("\n- %v", e)
5252
}
5353
msg += "\n"
@@ -383,12 +383,12 @@ func validateContributorYaml(yml contributorFrontmatterWithFilePath) []error {
383383
return problems
384384
}
385385

386-
func parseContributorFiles(readmeEntries []directoryReadme) (
386+
func parseContributorFiles(readmeEntries []readme) (
387387
map[string]contributorFrontmatterWithFilePath,
388388
error,
389389
) {
390390
frontmatterByUsername := map[string]contributorFrontmatterWithFilePath{}
391-
yamlParsingErrors := workflowPhaseError{
391+
yamlParsingErrors := validationPhaseError{
392392
Phase: "YAML parsing",
393393
}
394394
for _, rm := range readmeEntries {
@@ -434,7 +434,7 @@ func parseContributorFiles(readmeEntries []directoryReadme) (
434434
}
435435

436436
employeeGithubGroups := map[string][]string{}
437-
yamlValidationErrors := workflowPhaseError{
437+
yamlValidationErrors := validationPhaseError{
438438
Phase: "Raw YAML Validation",
439439
}
440440
for _, yml := range frontmatterByUsername {
@@ -475,13 +475,13 @@ func parseContributorFiles(readmeEntries []directoryReadme) (
475475
return frontmatterByUsername, nil
476476
}
477477

478-
func aggregateReadmeFiles() ([]directoryReadme, error) {
478+
func aggregateContributorReadmeFiles() ([]readme, error) {
479479
dirEntries, err := os.ReadDir(rootRegistryPath)
480480
if err != nil {
481481
return nil, err
482482
}
483483

484-
allReadmeFiles := []directoryReadme{}
484+
allReadmeFiles := []readme{}
485485
problems := []error{}
486486
for _, e := range dirEntries {
487487
dirPath := path.Join(rootRegistryPath, e.Name())
@@ -502,14 +502,14 @@ func aggregateReadmeFiles() ([]directoryReadme, error) {
502502
problems = append(problems, err)
503503
continue
504504
}
505-
allReadmeFiles = append(allReadmeFiles, directoryReadme{
505+
allReadmeFiles = append(allReadmeFiles, readme{
506506
FilePath: readmePath,
507507
RawText: string(rmBytes),
508508
})
509509
}
510510

511511
if len(problems) != 0 {
512-
return nil, workflowPhaseError{
512+
return nil, validationPhaseError{
513513
Phase: "FileSystem reading",
514514
Errors: problems,
515515
}
@@ -552,17 +552,17 @@ func validateRelativeUrls(
552552
if len(problems) == 0 {
553553
return nil
554554
}
555-
return workflowPhaseError{
555+
return validationPhaseError{
556556
Phase: "Relative URL validation",
557557
Errors: problems,
558558
}
559559
}
560560

561561
func main() {
562562
log.Println("Starting README validation")
563-
allReadmeFiles, err := aggregateReadmeFiles()
563+
allReadmeFiles, err := aggregateContributorReadmeFiles()
564564
if err != nil {
565-
panic(err)
565+
log.Panic(err)
566566
}
567567

568568
log.Printf("Processing %d README files\n", len(allReadmeFiles))

0 commit comments

Comments
 (0)