chore: set up initial version of CI
This commit is contained in:
parent
3b9ec5ec41
commit
88f7be27ec
21
.github/workflows/validate-readme-files.yaml
vendored
Normal file
21
.github/workflows/validate-readme-files.yaml
vendored
Normal file
@ -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
|
||||||
@ -16,7 +16,7 @@ import (
|
|||||||
|
|
||||||
const rootRegistryPath = "./registry"
|
const rootRegistryPath = "./registry"
|
||||||
|
|
||||||
type directoryReadme struct {
|
type readme struct {
|
||||||
FilePath string
|
FilePath string
|
||||||
RawText string
|
RawText string
|
||||||
}
|
}
|
||||||
@ -38,16 +38,16 @@ type contributorFrontmatterWithFilePath struct {
|
|||||||
FilePath string
|
FilePath string
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ error = workflowPhaseError{}
|
var _ error = validationPhaseError{}
|
||||||
|
|
||||||
type workflowPhaseError struct {
|
type validationPhaseError struct {
|
||||||
Phase string
|
Phase string
|
||||||
Errors []error
|
Errors []error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wpe workflowPhaseError) Error() string {
|
func (vpe validationPhaseError) Error() string {
|
||||||
msg := fmt.Sprintf("Error during %q phase of README validation:", wpe.Phase)
|
msg := fmt.Sprintf("Error during %q phase of README validation:", vpe.Phase)
|
||||||
for _, e := range wpe.Errors {
|
for _, e := range vpe.Errors {
|
||||||
msg += fmt.Sprintf("\n- %v", e)
|
msg += fmt.Sprintf("\n- %v", e)
|
||||||
}
|
}
|
||||||
msg += "\n"
|
msg += "\n"
|
||||||
@ -383,12 +383,12 @@ func validateContributorYaml(yml contributorFrontmatterWithFilePath) []error {
|
|||||||
return problems
|
return problems
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseContributorFiles(readmeEntries []directoryReadme) (
|
func parseContributorFiles(readmeEntries []readme) (
|
||||||
map[string]contributorFrontmatterWithFilePath,
|
map[string]contributorFrontmatterWithFilePath,
|
||||||
error,
|
error,
|
||||||
) {
|
) {
|
||||||
frontmatterByUsername := map[string]contributorFrontmatterWithFilePath{}
|
frontmatterByUsername := map[string]contributorFrontmatterWithFilePath{}
|
||||||
yamlParsingErrors := workflowPhaseError{
|
yamlParsingErrors := validationPhaseError{
|
||||||
Phase: "YAML parsing",
|
Phase: "YAML parsing",
|
||||||
}
|
}
|
||||||
for _, rm := range readmeEntries {
|
for _, rm := range readmeEntries {
|
||||||
@ -434,7 +434,7 @@ func parseContributorFiles(readmeEntries []directoryReadme) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
employeeGithubGroups := map[string][]string{}
|
employeeGithubGroups := map[string][]string{}
|
||||||
yamlValidationErrors := workflowPhaseError{
|
yamlValidationErrors := validationPhaseError{
|
||||||
Phase: "Raw YAML Validation",
|
Phase: "Raw YAML Validation",
|
||||||
}
|
}
|
||||||
for _, yml := range frontmatterByUsername {
|
for _, yml := range frontmatterByUsername {
|
||||||
@ -475,13 +475,13 @@ func parseContributorFiles(readmeEntries []directoryReadme) (
|
|||||||
return frontmatterByUsername, nil
|
return frontmatterByUsername, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func aggregateReadmeFiles() ([]directoryReadme, error) {
|
func aggregateContributorReadmeFiles() ([]readme, error) {
|
||||||
dirEntries, err := os.ReadDir(rootRegistryPath)
|
dirEntries, err := os.ReadDir(rootRegistryPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
allReadmeFiles := []directoryReadme{}
|
allReadmeFiles := []readme{}
|
||||||
problems := []error{}
|
problems := []error{}
|
||||||
for _, e := range dirEntries {
|
for _, e := range dirEntries {
|
||||||
dirPath := path.Join(rootRegistryPath, e.Name())
|
dirPath := path.Join(rootRegistryPath, e.Name())
|
||||||
@ -502,14 +502,14 @@ func aggregateReadmeFiles() ([]directoryReadme, error) {
|
|||||||
problems = append(problems, err)
|
problems = append(problems, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
allReadmeFiles = append(allReadmeFiles, directoryReadme{
|
allReadmeFiles = append(allReadmeFiles, readme{
|
||||||
FilePath: readmePath,
|
FilePath: readmePath,
|
||||||
RawText: string(rmBytes),
|
RawText: string(rmBytes),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(problems) != 0 {
|
if len(problems) != 0 {
|
||||||
return nil, workflowPhaseError{
|
return nil, validationPhaseError{
|
||||||
Phase: "FileSystem reading",
|
Phase: "FileSystem reading",
|
||||||
Errors: problems,
|
Errors: problems,
|
||||||
}
|
}
|
||||||
@ -552,7 +552,7 @@ func validateRelativeUrls(
|
|||||||
if len(problems) == 0 {
|
if len(problems) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return workflowPhaseError{
|
return validationPhaseError{
|
||||||
Phase: "Relative URL validation",
|
Phase: "Relative URL validation",
|
||||||
Errors: problems,
|
Errors: problems,
|
||||||
}
|
}
|
||||||
@ -560,9 +560,9 @@ func validateRelativeUrls(
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
log.Println("Starting README validation")
|
log.Println("Starting README validation")
|
||||||
allReadmeFiles, err := aggregateReadmeFiles()
|
allReadmeFiles, err := aggregateContributorReadmeFiles()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
log.Panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("Processing %d README files\n", len(allReadmeFiles))
|
log.Printf("Processing %d README files\n", len(allReadmeFiles))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user