-
Notifications
You must be signed in to change notification settings - Fork 3
chore: add logic to validate all modules #11
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
Conversation
type coderResourceReadmes map[string]coderResourceReadme | ||
|
||
func (crr coderResourceReadmes) Get(filePath string) (coderResourceReadme, bool) { | ||
rm, ok := crr[filePath] | ||
return rm, ok | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't sure if this pattern made sense in some cases. The idea is that if you have a map, the type signature doesn't communicate how the keys are formatted. With a custom type, the method makes it clear that you need a filePath to index the value by
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the type and method are unnecessary, you can leave a comment at the usage points informing the map structure since it doesn't travel far in the code when it is used.
var errs []error | ||
errs = append(errs, validateReadmeBody(trimmed)...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't sure about whether Go has any rules of thumb for when to treat data as immutable, but I treated the results of validateReadme
as if it were, even though there's no other owner for the slice after the function ends, and I could've just mutated the result directly
// would be a big improvement. | ||
var terraformVersionRe = regexp.MustCompile("^\\s*\\bversion\\s+=") | ||
|
||
func validateCoderResourceReadmeBody(body string) []error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is convoluted, but at least with it seeming to work (from all the input files that exist right now), I'd rather get unit tests in place for it, and then use those to guide refactoring the function to do AST parsing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't want to spend too much time on tests for this iteration, but needed to isolate the README-parsing logic to figure out how to make sure it worked faster
cmd/readmevalidation/readmeFiles.go
Outdated
// Todo: This seems to work okay for now, but the really proper way of doing | ||
// this is by parsing this as an AST, and then checking the resulting nodes | ||
func validateReadmeBody(body string) []error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would also like to get tests in place, and then use those to refactor this
chore: update README files and validation to reflect new requirements
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😎
We can talk about cleaning this and #10 up a bit and possibly moving it into coder/coder-registry post Profile launch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, I'm fine without tests because the existing readmes act as one for now and we can circle back with other work.
type coderResourceReadmes map[string]coderResourceReadme | ||
|
||
func (crr coderResourceReadmes) Get(filePath string) (coderResourceReadme, bool) { | ||
rm, ok := crr[filePath] | ||
return rm, ok | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the type and method are unnecessary, you can leave a comment at the usage points informing the map structure since it doesn't travel far in the code when it is used.
func validateCoderResourceTags(tags []string) error { | ||
if len(tags) == 0 { | ||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tags
can be nil
here, right? Is that valid, or should we check for it? len
will return 0 either way, but if you want to enforce that people put it in the frontmatter with an empty array we should fail on nil. If we are cool with omitting it there's nothing to do here, but we may want to put a comment saying that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, good call. I didn't think about it before, but I'll go ahead and add a check, even though I don't think it'll matter much in practice. The YAML library should guarantee that the tags
field gets parsed as an allocated array, but since the function can still be called separately, there's a risk of edge cases down the line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha, so even if the key is completely ommited it still parses to a slice with length 0? If so they it's safe, but I wasn't sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be nil if the field were optional, but it's required. So that gives us some guarantees, because parser errors out on omitted keys, instead of initializing them with nil values. If a user forgets the key, CI should ding them
@@ -27,7 +27,7 @@ type contributorProfileFrontmatter struct { | |||
ContributorStatus *string `yaml:"status"` | |||
} | |||
|
|||
type contributorProfile struct { | |||
type contributorProfileReadme struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
cmd/readmevalidation/readmeFiles.go
Outdated
strings.NewReader(strings.TrimSpace(readmeText)), | ||
) | ||
|
||
lineScanner := bufio.NewScanner(strings.NewReader(strings.TrimSpace(readmeText))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Oh and let's get rid of the camelCase, we do all lowercase for all go files like |
Closes coder/internal#531
Changes made
ValidationPhase
from an int to a stringNotes
maintainer_github
field, because that information can be intuited by the directory path. I didn't add any checks for it, because the new Registry site build process shouldn't need them