Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3b6b1ba

Browse files
committed
Update README validation and Go version
- Downgrade Go version in CI to 1.24 for consistency. - Fix naming and path issues in `readmevalidation` code. - Improve regex validation for module and namespace names. - Correct typos and improve comments for clarity.
1 parent 5b6d878 commit 3b6b1ba

File tree

6 files changed

+22
-29
lines changed

6 files changed

+22
-29
lines changed

‎.github/workflows/ci.yaml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ jobs:
6363
- name: Set up Go
6464
uses: actions/setup-go@v5
6565
with:
66-
go-version: "1.25.0"
67-
- name: Validate Reademde
66+
go-version: "1.24"
67+
- name: Validate README
6868
run: go build ./cmd/readmevalidation && ./readmevalidation
6969
- name: Remove build file artifact
7070
run: rm ./readmevalidation

‎cmd/readmevalidation/codermodules.go‎

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,14 @@ var (
1414
terraformSourceRe = regexp.MustCompile(`^\s*source\s*=\s*"([^"]+)"`)
1515
)
1616

17-
func normalizeModuleName(name string) string {
18-
// Normalize module names by replacing hyphens with underscores for comparison
19-
// since Terraform allows both but directory names typically use hyphens
20-
return strings.ReplaceAll(name, "-", "_")
21-
}
22-
23-
func extractNamespaceAndModuleFromPath(filePath string) (string, string, error) {
24-
// Expected path format: registry/<namespace>/modules/<module-name>/README.md
17+
func extractNamespaceAndModuleFromPath(filePath string) (namespace string, moduleName string, err error) {
18+
// Expected path format: registry/<namespace>/modules/<module-name>/README.md.
2519
parts := strings.Split(filepath.Clean(filePath), string(filepath.Separator))
2620
if len(parts) < 5 || parts[0] != "registry" || parts[2] != "modules" || parts[4] != "README.md" {
2721
return "", "", xerrors.Errorf("invalid module path format: %s", filePath)
2822
}
29-
namespace := parts[1]
30-
moduleName := parts[3]
23+
namespace = parts[1]
24+
moduleName = parts[3]
3125
return namespace, moduleName, nil
3226
}
3327

@@ -55,21 +49,21 @@ func validateModuleSourceURL(body string, filePath string) []error {
5549
isInsideTerraform = true
5650
firstTerraformBlock = false
5751
} else if isInsideTerraform {
58-
// End of first terraform block
52+
// End of first terraform block.
5953
break
6054
}
6155
continue
6256
}
6357

6458
if isInsideTerraform {
65-
// Check for any source line in the first terraform block
59+
// Check for any source line in the first terraform block.
6660
if matches := terraformSourceRe.FindStringSubmatch(nextLine); matches != nil {
6761
actualSource := matches[1]
6862
if actualSource == expectedSource {
6963
foundCorrectSource = true
7064
break
7165
} else if strings.HasPrefix(actualSource, "registry.coder.com/") && strings.Contains(actualSource, "/"+moduleName+"/coder") {
72-
// Found source for this module but with wrong namespace/format
66+
// Found source for this module but with wrong namespace/format.
7367
errs = append(errs, xerrors.Errorf("incorrect source URL format: found %q, expected %q", actualSource, expectedSource))
7468
return errs
7569
}

‎cmd/readmevalidation/coderresources.go‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var (
2525
terraformVersionRe = regexp.MustCompile(`^\s*\bversion\s+=`)
2626

2727
// Matches the format "> [!INFO]". Deliberately using a broad pattern to catch formatting issues that can mess up
28-
// the renderer for the Registry website
28+
// the renderer for the Registry website.
2929
gfmAlertRegex = regexp.MustCompile(`^>(\s*)\[!(\w+)\](\s*)(.*)`)
3030
)
3131

@@ -39,7 +39,7 @@ type coderResourceFrontmatter struct {
3939
}
4040

4141
// A slice version of the struct tags from coderResourceFrontmatter. Might be worth using reflection to generate this
42-
// list at runtime in the future, but this should be okay for now
42+
// list at runtime in the future, but this should be okay for now.
4343
var supportedCoderResourceStructKeys = []string{
4444
"description", "icon", "display_name", "verified", "tags", "supported_os",
4545
// TODO: This is an old, officially deprecated key from the archived coder/modules repo. We can remove this once we
@@ -315,15 +315,15 @@ func validateResourceGfmAlerts(readmeBody string) []error {
315315
}
316316

317317
// Nested GFM alerts is such a weird mistake that it's probably not really safe to keep trying to process the
318-
// rest of the content, so this will prevent any other validations from happening for the given line
318+
// rest of the content, so this will prevent any other validations from happening for the given line.
319319
if isInsideGfmQuotes {
320-
errs = append(errs, errors.New("registry does not support nested GFM alerts"))
320+
errs = append(errs, xerrors.New("registry does not support nested GFM alerts"))
321321
continue
322322
}
323323

324324
leadingWhitespace := currentMatch[1]
325325
if len(leadingWhitespace) != 1 {
326-
errs = append(errs, errors.New("GFM alerts must have one space between the '>' and the start of the GFM brackets"))
326+
errs = append(errs, xerrors.New("GFM alerts must have one space between the '>' and the start of the GFM brackets"))
327327
}
328328
isInsideGfmQuotes = true
329329

@@ -347,7 +347,7 @@ func validateResourceGfmAlerts(readmeBody string) []error {
347347
}
348348
}
349349

350-
if gfmAlertRegex.Match([]byte(sourceLine)) {
350+
if gfmAlertRegex.MatchString(sourceLine) {
351351
errs = append(errs, xerrors.Errorf("README has an incomplete GFM alert at the end of the file"))
352352
}
353353

‎cmd/readmevalidation/contributors.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type contributorProfileFrontmatter struct {
2626
}
2727

2828
// A slice version of the struct tags from contributorProfileFrontmatter. Might be worth using reflection to generate
29-
// this list at runtime in the future, but this should be okay for now
29+
// this list at runtime in the future, but this should be okay for now.
3030
var supportedContributorProfileStructKeys = []string{"display_name", "bio", "status", "avatar", "linkedin", "github", "website", "support_email"}
3131

3232
type contributorProfileReadme struct {

‎cmd/readmevalidation/repostructure.go‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ import (
1313

1414
var supportedUserNameSpaceDirectories = append(supportedResourceTypes, ".images")
1515

16-
// validNameRe validates that names contain only alphanumeric characters and hyphens
16+
// validNameRe validates that names contain only alphanumeric characters and hyphens.
1717
var validNameRe = regexp.MustCompile(`^[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`)
1818

19-
2019
// validateCoderResourceSubdirectory validates that the structure of a module or template within a namespace follows all
21-
// expected file conventions
20+
// expected file conventions.
2221
func validateCoderResourceSubdirectory(dirPath string) []error {
2322
resourceDir, err := os.Stat(dirPath)
2423
if err != nil {
@@ -47,7 +46,7 @@ func validateCoderResourceSubdirectory(dirPath string) []error {
4746
continue
4847
}
4948

50-
// Validate module/template name
49+
// Validate module/template name.
5150
if !validNameRe.MatchString(f.Name()) {
5251
errs = append(errs, xerrors.Errorf("%q: name contains invalid characters (only alphanumeric characters and hyphens are allowed)", path.Join(dirPath, f.Name())))
5352
continue
@@ -90,7 +89,7 @@ func validateRegistryDirectory() []error {
9089
continue
9190
}
9291

93-
// Validate namespace name
92+
// Validate namespace name.
9493
if !validNameRe.MatchString(nDir.Name()) {
9594
allErrs = append(allErrs, xerrors.Errorf("%q: namespace name contains invalid characters (only alphanumeric characters and hyphens are allowed)", namespacePath))
9695
continue
@@ -136,7 +135,7 @@ func validateRegistryDirectory() []error {
136135

137136
// validateRepoStructure validates that the structure of the repo is "correct enough" to do all necessary validation
138137
// checks. It is NOT an exhaustive validation of the entire repo structure – it only checks the parts of the repo that
139-
// are relevant for the main validation steps
138+
// are relevant for the main validation steps.
140139
func validateRepoStructure() error {
141140
var errs []error
142141
if vrdErrs := validateRegistryDirectory(); len(vrdErrs) != 0 {

‎go.mod‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module coder.com/coder-registry
22

3-
go 1.23.2
3+
go 1.24
44

55
require (
66
cdr.dev/slog v1.6.1

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /