From c656571ac04697e1098c711775ae077b055160da Mon Sep 17 00:00:00 2001 From: Brian Flad Date: Mon, 3 Jun 2024 17:02:16 -0400 Subject: [PATCH] validate: Remove number of files check (#381) Reference: https://github.com/hashicorp/terraform-registry/pull/3811 This check is no longer valid due to a change in the Terraform Registry. --- .../unreleased/NOTES-20240531-093539.yaml | 5 ++ README.md | 1 - ...amework_provider_success_legacy_docs.txtar | 1 - ...ework_provider_success_registry_docs.txtar | 1 - internal/check/directory.go | 36 -------------- internal/check/directory_test.go | 48 ------------------- internal/provider/validate.go | 4 -- 7 files changed, 5 insertions(+), 91 deletions(-) create mode 100644 .changes/unreleased/NOTES-20240531-093539.yaml diff --git a/.changes/unreleased/NOTES-20240531-093539.yaml b/.changes/unreleased/NOTES-20240531-093539.yaml new file mode 100644 index 00000000..144c832c --- /dev/null +++ b/.changes/unreleased/NOTES-20240531-093539.yaml @@ -0,0 +1,5 @@ +kind: NOTES +body: 'validate: The number of files check has been removed to match the latest Terraform Registry ingress logic' +time: 2024-05-31T09:35:39.965379-07:00 +custom: + Issue: "381" diff --git a/README.md b/README.md index 468e85b5..6e30fd9e 100644 --- a/README.md +++ b/README.md @@ -159,7 +159,6 @@ The `validate` subcommand can be used to validate the provider website documenta |---------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `InvalidDirectoriesCheck` | Checks for valid subdirectory structure and throws an error if an invalid Terraform Provider documentation subdirectory is found. | | `MixedDirectoriesCheck` | Throws an error if both legacy documentation (`/website/docs`) and registry documentation (`/docs`) are found. | -| `NumberOfFilesCheck` | Throws an error if the number of files in a directory is larger than the registry limit. | | `FileSizeCheck` | Throws an error if the documentation file is above the registry storage limit. | | `FileExtensionCheck` | Throws an error if the extension of the given file is not a valid registry documentation extension. | | `FrontMatterCheck` | Checks the YAML frontmatter of documentation for missing required fields or invalid fields. | diff --git a/cmd/tfplugindocs/testdata/scripts/schema-json/validate/framework_provider_success_legacy_docs.txtar b/cmd/tfplugindocs/testdata/scripts/schema-json/validate/framework_provider_success_legacy_docs.txtar index c8452040..c87edab2 100644 --- a/cmd/tfplugindocs/testdata/scripts/schema-json/validate/framework_provider_success_legacy_docs.txtar +++ b/cmd/tfplugindocs/testdata/scripts/schema-json/validate/framework_provider_success_legacy_docs.txtar @@ -10,7 +10,6 @@ cmp stdout expected-output.txt exporting schema from JSON file getting provider schema running mixed directories check -running number of files check detected legacy website directory, running checks running invalid directories check on website/docs/d running file checks on website/docs/d/example.html.md diff --git a/cmd/tfplugindocs/testdata/scripts/schema-json/validate/framework_provider_success_registry_docs.txtar b/cmd/tfplugindocs/testdata/scripts/schema-json/validate/framework_provider_success_registry_docs.txtar index 197fceb1..220a8c3b 100644 --- a/cmd/tfplugindocs/testdata/scripts/schema-json/validate/framework_provider_success_registry_docs.txtar +++ b/cmd/tfplugindocs/testdata/scripts/schema-json/validate/framework_provider_success_registry_docs.txtar @@ -10,7 +10,6 @@ cmpenv stdout expected-output.txt exporting schema from JSON file getting provider schema running mixed directories check -running number of files check detected static docs directory, running checks running invalid directories check on docs/data-sources running file checks on docs/data-sources/example.md diff --git a/internal/check/directory.go b/internal/check/directory.go index 3aefa6a1..3c3183b7 100644 --- a/internal/check/directory.go +++ b/internal/check/directory.go @@ -118,42 +118,6 @@ func MixedDirectoriesCheck(docFiles []string) error { return nil } -// NumberOfFilesCheck verifies that documentation is below the Terraform Registry storage limit. -// This check presumes that all provided directories are valid, e.g. that directory checking -// for invalid or mixed directory structures was previously completed. -func NumberOfFilesCheck(docFiles []string) error { - var numberOfFiles int - - directoryCounts := make(map[string]int) - for _, file := range docFiles { - directory := filepath.Dir(file) - - // Ignore CDKTF files. The file limit is per-language and presumably there is one CDKTF file per source HCL file. - if IsValidCdktfDirectory(directory) { - continue - } - - if directory == RegistryIndexDirectory || directory == filepath.FromSlash(LegacyIndexDirectory) { - continue - } - - directoryCounts[directory]++ - } - - for directory, count := range directoryCounts { - - log.Printf("[TRACE] Found %d documentation files in directory: %s", count, directory) - numberOfFiles = numberOfFiles + count - } - - log.Printf("[DEBUG] Found %d documentation files with limit of %d", numberOfFiles, RegistryMaximumNumberOfFiles) - if numberOfFiles >= RegistryMaximumNumberOfFiles { - return fmt.Errorf("exceeded maximum (%d) number of documentation files for Terraform Registry: %d", RegistryMaximumNumberOfFiles, numberOfFiles) - } - - return nil -} - func IsValidLegacyDirectory(directory string) bool { for _, validLegacyDirectory := range ValidLegacyDirectories { if directory == filepath.FromSlash(validLegacyDirectory) { diff --git a/internal/check/directory_test.go b/internal/check/directory_test.go index dc0c5687..29660713 100644 --- a/internal/check/directory_test.go +++ b/internal/check/directory_test.go @@ -4,7 +4,6 @@ package check import ( - "fmt" "os" "path/filepath" "testing" @@ -14,43 +13,6 @@ import ( var DocumentationGlobPattern = `{docs/index.md,docs/{,cdktf/}{data-sources,guides,resources,functions}/**/*,website/docs/**/*}` -func TestNumberOfFilesCheck(t *testing.T) { - t.Parallel() - testCases := map[string]struct { - files []string - ExpectError bool - }{ - "under limit": { - files: testGenerateFiles(RegistryMaximumNumberOfFiles - 1), - }, - "at limit": { - files: testGenerateFiles(RegistryMaximumNumberOfFiles), - ExpectError: true, - }, - "over limit": { - files: testGenerateFiles(RegistryMaximumNumberOfFiles + 1), - ExpectError: true, - }, - } - - for name, testCase := range testCases { - name := name - testCase := testCase - t.Run(name, func(t *testing.T) { - t.Parallel() - got := NumberOfFilesCheck(testCase.files) - - if got == nil && testCase.ExpectError { - t.Errorf("expected error, got no error") - } - - if got != nil && !testCase.ExpectError { - t.Errorf("expected no error, got error: %s", got) - } - }) - } -} - func TestMixedDirectoriesCheck(t *testing.T) { t.Parallel() testCases := map[string]struct { @@ -91,13 +53,3 @@ func TestMixedDirectoriesCheck(t *testing.T) { }) } } - -func testGenerateFiles(numberOfFiles int) []string { - files := make([]string, numberOfFiles) - - for i := 0; i < numberOfFiles; i++ { - files[i] = fmt.Sprintf("thing%d.md", i) - } - - return files -} diff --git a/internal/provider/validate.go b/internal/provider/validate.go index 00b6f661..a72be373 100644 --- a/internal/provider/validate.go +++ b/internal/provider/validate.go @@ -170,10 +170,6 @@ func (v *validator) validate(ctx context.Context) error { err = check.MixedDirectoriesCheck(files) result = errors.Join(result, err) - v.logger.infof("running number of files check") - err = check.NumberOfFilesCheck(files) - result = errors.Join(result, err) - if dirExists(filepath.Join(v.providerDir, "docs")) { v.logger.infof("detected static docs directory, running checks") err = v.validateStaticDocs(filepath.Join(v.providerDir, "docs"))