Skip to content

chore: add CI step for validating contributor READMEs #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 30 commits into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
96c20c4
chore: add sample README
Parkreiner Apr 8, 2025
a5c4495
wip: commit progress on CI validation script
Parkreiner Apr 8, 2025
20204b0
chore: add extra sample data file
Parkreiner Apr 8, 2025
902b32f
wip: commit more progress on script
Parkreiner Apr 8, 2025
1906520
chore: add logs for better feedback
Parkreiner Apr 8, 2025
da735da
fix: remove parsing bugs
Parkreiner Apr 8, 2025
b191321
fix: make logging better
Parkreiner Apr 8, 2025
629f4b3
chore: rename directory for script
Parkreiner Apr 8, 2025
2b9da92
refactor: remove goto statements
Parkreiner Apr 8, 2025
23f1cee
fix: remove accidental segfault
Parkreiner Apr 8, 2025
e20e679
wip: scaffold relative URL validation
Parkreiner Apr 8, 2025
df2e47e
refactor: remove unnecessary intermediary data types
Parkreiner Apr 8, 2025
36ebd8d
fix: update script to be runnable from root directory
Parkreiner Apr 8, 2025
c3f998d
refactor: rename script
Parkreiner Apr 8, 2025
9e48eb8
refactor: reorganize scripts again
Parkreiner Apr 8, 2025
3b9ec5e
chore: finish initial version of validation script
Parkreiner Apr 8, 2025
88f7be2
chore: set up initial version of CI
Parkreiner Apr 9, 2025
e035f1f
chore: beef up CI
Parkreiner Apr 9, 2025
3b9c01e
fix: ensure relative avatars keep small scope
Parkreiner Apr 9, 2025
bc4bbda
fix: remove unnecessary matrix
Parkreiner Apr 9, 2025
abf9815
fix: update static files
Parkreiner Apr 10, 2025
affc506
refactor: split validation function into smaller pieces
Parkreiner Apr 10, 2025
65fb7bc
refactor: standardize how errors are defined
Parkreiner Apr 11, 2025
96fa5d4
refactor: apply majority of feedback
Parkreiner Apr 11, 2025
5c45642
refactor: split off another function
Parkreiner Apr 11, 2025
ffd9861
refactor: extract pseudo-constants
Parkreiner Apr 14, 2025
bdf9c5f
refactor: update namespacing
Parkreiner Apr 14, 2025
39b264a
refactor: split up package boundaries
Parkreiner Apr 14, 2025
a2c246e
refactor: split out error func
Parkreiner Apr 14, 2025
50d651c
fix: update CI step
Parkreiner Apr 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: set up initial version of CI
  • Loading branch information
Parkreiner committed Apr 9, 2025
commit 88f7be27ec2ec6ff67848564a04c53654bdd4da7
21 changes: 21 additions & 0 deletions .github/workflows/validate-readme-files.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Validate README files
on:
pull_request:
branches:
- main
jobs:
validate-contributors:
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
go-version: ["1.23.x"]
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Validate
run: go run ./scripts/validate-contributor-readmes/main.go
32 changes: 16 additions & 16 deletions scripts/validate-contributor-readmes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

const rootRegistryPath = "./registry"

type directoryReadme struct {
type readme struct {
FilePath string
RawText string
}
Expand All @@ -38,16 +38,16 @@ type contributorFrontmatterWithFilePath struct {
FilePath string
}

var _ error = workflowPhaseError{}
var _ error = validationPhaseError{}

type workflowPhaseError struct {
type validationPhaseError struct {
Phase string
Errors []error
}

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

func parseContributorFiles(readmeEntries []directoryReadme) (
func parseContributorFiles(readmeEntries []readme) (
map[string]contributorFrontmatterWithFilePath,
error,
) {
frontmatterByUsername := map[string]contributorFrontmatterWithFilePath{}
yamlParsingErrors := workflowPhaseError{
yamlParsingErrors := validationPhaseError{
Phase: "YAML parsing",
}
for _, rm := range readmeEntries {
Expand Down Expand Up @@ -434,7 +434,7 @@ func parseContributorFiles(readmeEntries []directoryReadme) (
}

employeeGithubGroups := map[string][]string{}
yamlValidationErrors := workflowPhaseError{
yamlValidationErrors := validationPhaseError{
Phase: "Raw YAML Validation",
}
for _, yml := range frontmatterByUsername {
Expand Down Expand Up @@ -475,13 +475,13 @@ func parseContributorFiles(readmeEntries []directoryReadme) (
return frontmatterByUsername, nil
}

func aggregateReadmeFiles() ([]directoryReadme, error) {
func aggregateContributorReadmeFiles() ([]readme, error) {
dirEntries, err := os.ReadDir(rootRegistryPath)
if err != nil {
return nil, err
}

allReadmeFiles := []directoryReadme{}
allReadmeFiles := []readme{}
problems := []error{}
for _, e := range dirEntries {
dirPath := path.Join(rootRegistryPath, e.Name())
Expand All @@ -502,14 +502,14 @@ func aggregateReadmeFiles() ([]directoryReadme, error) {
problems = append(problems, err)
continue
}
allReadmeFiles = append(allReadmeFiles, directoryReadme{
allReadmeFiles = append(allReadmeFiles, readme{
FilePath: readmePath,
RawText: string(rmBytes),
})
}

if len(problems) != 0 {
return nil, workflowPhaseError{
return nil, validationPhaseError{
Phase: "FileSystem reading",
Errors: problems,
}
Expand Down Expand Up @@ -552,17 +552,17 @@ func validateRelativeUrls(
if len(problems) == 0 {
return nil
}
return workflowPhaseError{
return validationPhaseError{
Phase: "Relative URL validation",
Errors: problems,
}
}

func main() {
log.Println("Starting README validation")
allReadmeFiles, err := aggregateReadmeFiles()
allReadmeFiles, err := aggregateContributorReadmeFiles()
if err != nil {
panic(err)
log.Panic(err)
}

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