diff --git a/cmd/readmevalidation/repostructure.go b/cmd/readmevalidation/repostructure.go index 7a529c01e..c77c723b6 100644 --- a/cmd/readmevalidation/repostructure.go +++ b/cmd/readmevalidation/repostructure.go @@ -4,6 +4,7 @@ import ( "errors" "os" "path" + "regexp" "slices" "strings" @@ -12,6 +13,10 @@ import ( var supportedUserNameSpaceDirectories = append(supportedResourceTypes, ".images") +// validNameRe validates that names contain only alphanumeric characters and hyphens +var validNameRe = regexp.MustCompile(`^[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`) + + // validateCoderResourceSubdirectory validates that the structure of a module or template within a namespace follows all // expected file conventions func validateCoderResourceSubdirectory(dirPath string) []error { @@ -42,6 +47,12 @@ func validateCoderResourceSubdirectory(dirPath string) []error { continue } + // Validate module/template name + if !validNameRe.MatchString(f.Name()) { + errs = append(errs, xerrors.Errorf("%q: name contains invalid characters (only alphanumeric characters and hyphens are allowed)", path.Join(dirPath, f.Name()))) + continue + } + resourceReadmePath := path.Join(dirPath, f.Name(), "README.md") if _, err := os.Stat(resourceReadmePath); err != nil { if errors.Is(err, os.ErrNotExist) { @@ -79,6 +90,12 @@ func validateRegistryDirectory() []error { continue } + // Validate namespace name + if !validNameRe.MatchString(nDir.Name()) { + allErrs = append(allErrs, xerrors.Errorf("%q: namespace name contains invalid characters (only alphanumeric characters and hyphens are allowed)", namespacePath)) + continue + } + contributorReadmePath := path.Join(namespacePath, "README.md") if _, err := os.Stat(contributorReadmePath); err != nil { allErrs = append(allErrs, err) diff --git a/registry/coder-labs/modules/sourcegraph_amp/README.md b/registry/coder-labs/modules/sourcegraph-amp/README.md similarity index 100% rename from registry/coder-labs/modules/sourcegraph_amp/README.md rename to registry/coder-labs/modules/sourcegraph-amp/README.md diff --git a/registry/coder-labs/modules/sourcegraph_amp/main.test.ts b/registry/coder-labs/modules/sourcegraph-amp/main.test.ts similarity index 100% rename from registry/coder-labs/modules/sourcegraph_amp/main.test.ts rename to registry/coder-labs/modules/sourcegraph-amp/main.test.ts diff --git a/registry/coder-labs/modules/sourcegraph_amp/main.tf b/registry/coder-labs/modules/sourcegraph-amp/main.tf similarity index 100% rename from registry/coder-labs/modules/sourcegraph_amp/main.tf rename to registry/coder-labs/modules/sourcegraph-amp/main.tf diff --git a/registry/coder-labs/modules/sourcegraph_amp/scripts/install.sh b/registry/coder-labs/modules/sourcegraph-amp/scripts/install.sh similarity index 100% rename from registry/coder-labs/modules/sourcegraph_amp/scripts/install.sh rename to registry/coder-labs/modules/sourcegraph-amp/scripts/install.sh diff --git a/registry/coder-labs/modules/sourcegraph_amp/scripts/start.sh b/registry/coder-labs/modules/sourcegraph-amp/scripts/start.sh similarity index 100% rename from registry/coder-labs/modules/sourcegraph_amp/scripts/start.sh rename to registry/coder-labs/modules/sourcegraph-amp/scripts/start.sh diff --git a/registry/coder-labs/modules/sourcegraph_amp/testdata/amp-mock.sh b/registry/coder-labs/modules/sourcegraph-amp/testdata/amp-mock.sh similarity index 100% rename from registry/coder-labs/modules/sourcegraph_amp/testdata/amp-mock.sh rename to registry/coder-labs/modules/sourcegraph-amp/testdata/amp-mock.sh