wip: get concurrency stubs set up
This commit is contained in:
parent
aa0b8710d3
commit
e888506063
@ -19,11 +19,12 @@ type coderResourceFrontmatter struct {
|
|||||||
|
|
||||||
// coderResource represents a generic concept for a Terraform resource used to
|
// coderResource represents a generic concept for a Terraform resource used to
|
||||||
// help create Coder workspaces. As of 2025-04-15, this encapsulates both
|
// help create Coder workspaces. As of 2025-04-15, this encapsulates both
|
||||||
// Coder Modules and Coder Templates.
|
// Coder Modules and Coder Templates. If the newReadmeBody and newFrontmatter
|
||||||
|
// fields are nil, that represents that the file has been deleted
|
||||||
type coderResource struct {
|
type coderResource struct {
|
||||||
name string
|
name string
|
||||||
filePath string
|
filePath string
|
||||||
readmeBody string
|
newReadmeBody *string
|
||||||
oldFrontmatter *coderResourceFrontmatter
|
oldFrontmatter *coderResourceFrontmatter
|
||||||
newFrontmatter *coderResourceFrontmatter
|
newFrontmatter *coderResourceFrontmatter
|
||||||
oldIsVerified bool
|
oldIsVerified bool
|
||||||
@ -124,7 +125,8 @@ func validateCoderResourceVerifiedStatus(oldVerified bool, newVerified bool, act
|
|||||||
// Todo: once we decide on how we want the README frontmatter to be formatted
|
// Todo: once we decide on how we want the README frontmatter to be formatted
|
||||||
// for the Embedded Registry work, update this function to validate that the
|
// for the Embedded Registry work, update this function to validate that the
|
||||||
// correct Terraform code snippets are included in the README and are actually
|
// correct Terraform code snippets are included in the README and are actually
|
||||||
// valid Terraform
|
// valid Terraform. Might also want to validate that each header follows proper
|
||||||
|
// hierarchy (i.e., not jumping from h1 to h3 because you think it looks nicer)
|
||||||
func validateCoderResourceReadmeBody(body string) error {
|
func validateCoderResourceReadmeBody(body string) error {
|
||||||
trimmed := strings.TrimSpace(body)
|
trimmed := strings.TrimSpace(body)
|
||||||
if !strings.HasPrefix(trimmed, "# ") {
|
if !strings.HasPrefix(trimmed, "# ") {
|
||||||
@ -133,6 +135,45 @@ func validateCoderResourceReadmeBody(body string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateCoderResource(resource coderResource) []error {
|
func validateCoderResourceChanges(resource coderResource, actorOrgStatus github.OrgStatus) []error {
|
||||||
|
var problems []error
|
||||||
|
|
||||||
|
if resource.newReadmeBody != nil {
|
||||||
|
if err := validateCoderResourceReadmeBody(*resource.newReadmeBody); err != nil {
|
||||||
|
problems = append(problems, addFilePathToError(resource.filePath, err))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if resource.newFrontmatter != nil {
|
||||||
|
if err := validateCoderResourceDisplayName(resource.newFrontmatter.DisplayName); err != nil {
|
||||||
|
problems = append(problems, addFilePathToError(resource.filePath, err))
|
||||||
|
}
|
||||||
|
if err := validateCoderResourceDescription(resource.newFrontmatter.Description); err != nil {
|
||||||
|
problems = append(problems, addFilePathToError(resource.filePath, err))
|
||||||
|
}
|
||||||
|
if err := validateCoderResourceTags(resource.newFrontmatter.Tags); err != nil {
|
||||||
|
problems = append(problems, addFilePathToError(resource.filePath, err))
|
||||||
|
}
|
||||||
|
if err := validateCoderResourceVerifiedStatus(resource.oldIsVerified, resource.newIsVerified, actorOrgStatus); err != nil {
|
||||||
|
problems = append(problems, addFilePathToError(resource.filePath, err))
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, err := range validateCoderResourceIconURL(resource.newFrontmatter.IconURL) {
|
||||||
|
problems = append(problems, addFilePathToError(resource.filePath, err))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return problems
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseCoderResourceFiles(oldReadmeFiles []readme, newReadmeFiles []readme) (map[string]coderResource, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func validateCoderResourceRelativeUrls(map[string]coderResource) []error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func aggregateCoderResourceReadmeFiles() ([]readme, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|||||||
@ -334,9 +334,7 @@ func aggregateContributorReadmeFiles() ([]readme, error) {
|
|||||||
return allReadmeFiles, nil
|
return allReadmeFiles, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateContributorRelativeUrls(
|
func validateContributorRelativeUrls(contributors map[string]contributorProfile) error {
|
||||||
contributors map[string]contributorProfile,
|
|
||||||
) error {
|
|
||||||
// This function only validates relative avatar URLs for now, but it can be
|
// This function only validates relative avatar URLs for now, but it can be
|
||||||
// beefed up to validate more in the future
|
// beefed up to validate more in the future
|
||||||
problems := []error{}
|
problems := []error{}
|
||||||
|
|||||||
@ -9,6 +9,8 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"coder.com/coder-registry/cmd/github"
|
"coder.com/coder-registry/cmd/github"
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
@ -60,30 +62,64 @@ func main() {
|
|||||||
log.Println("Starting README validation")
|
log.Println("Starting README validation")
|
||||||
|
|
||||||
// Validate file structure of main README directory
|
// Validate file structure of main README directory
|
||||||
|
log.Println("Validating directory structure of the README directory")
|
||||||
err = validateRepoStructure()
|
err = validateRepoStructure()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panic(err)
|
log.Panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set up concurrency for validating each category of README file
|
||||||
|
var readmeValidationErrors []error
|
||||||
|
errChan := make(chan error, 1)
|
||||||
|
wg := sync.WaitGroup{}
|
||||||
|
go func() {
|
||||||
|
for err := range errChan {
|
||||||
|
readmeValidationErrors = append(readmeValidationErrors, err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
// Validate contributor README files
|
// Validate contributor README files
|
||||||
allReadmeFiles, err := aggregateContributorReadmeFiles()
|
wg.Add(1)
|
||||||
if err != nil {
|
go func() {
|
||||||
log.Panic(err)
|
defer wg.Done()
|
||||||
}
|
|
||||||
log.Printf("Processing %d README files\n", len(allReadmeFiles))
|
allReadmeFiles, err := aggregateContributorReadmeFiles()
|
||||||
contributors, err := parseContributorFiles(allReadmeFiles)
|
if err != nil {
|
||||||
log.Printf("Processed %d README files as valid contributor profiles", len(contributors))
|
log.Panic(err)
|
||||||
if err != nil {
|
}
|
||||||
log.Panic(err)
|
log.Printf("Processing %d README files\n", len(allReadmeFiles))
|
||||||
}
|
contributors, err := parseContributorFiles(allReadmeFiles)
|
||||||
err = validateContributorRelativeUrls(contributors)
|
log.Printf("Processed %d README files as valid contributor profiles", len(contributors))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panic(err)
|
log.Panic(err)
|
||||||
}
|
}
|
||||||
log.Println("All relative URLs for READMEs are valid")
|
err = validateContributorRelativeUrls(contributors)
|
||||||
log.Printf("Processed all READMEs in the %q directory\n", rootRegistryPath)
|
if err != nil {
|
||||||
|
log.Panic(err)
|
||||||
|
}
|
||||||
|
log.Println("All relative URLs for READMEs are valid")
|
||||||
|
log.Printf("Processed all READMEs in the %q directory\n", rootRegistryPath)
|
||||||
|
}()
|
||||||
|
|
||||||
// Validate modules
|
// Validate modules
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
}()
|
||||||
|
|
||||||
// Validate templates
|
// Validate templates
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
}()
|
||||||
|
|
||||||
|
// Clean up and log errors
|
||||||
|
wg.Wait()
|
||||||
|
close(errChan)
|
||||||
|
for _, err := range readmeValidationErrors {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
|
if len(readmeValidationErrors) != 0 {
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user