Skip to content

Commit c656571

Browse files
authored
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.
1 parent 0638bc3 commit c656571

File tree

7 files changed

+5
-91
lines changed

7 files changed

+5
-91
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
kind: NOTES
2+
body: 'validate: The number of files check has been removed to match the latest Terraform Registry ingress logic'
3+
time: 2024-05-31T09:35:39.965379-07:00
4+
custom:
5+
Issue: "381"

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ The `validate` subcommand can be used to validate the provider website documenta
159159
|---------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
160160
| `InvalidDirectoriesCheck` | Checks for valid subdirectory structure and throws an error if an invalid Terraform Provider documentation subdirectory is found. |
161161
| `MixedDirectoriesCheck` | Throws an error if both legacy documentation (`/website/docs`) and registry documentation (`/docs`) are found. |
162-
| `NumberOfFilesCheck` | Throws an error if the number of files in a directory is larger than the registry limit. |
163162
| `FileSizeCheck` | Throws an error if the documentation file is above the registry storage limit. |
164163
| `FileExtensionCheck` | Throws an error if the extension of the given file is not a valid registry documentation extension. |
165164
| `FrontMatterCheck` | Checks the YAML frontmatter of documentation for missing required fields or invalid fields. |

cmd/tfplugindocs/testdata/scripts/schema-json/validate/framework_provider_success_legacy_docs.txtar

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ cmp stdout expected-output.txt
1010
exporting schema from JSON file
1111
getting provider schema
1212
running mixed directories check
13-
running number of files check
1413
detected legacy website directory, running checks
1514
running invalid directories check on website/docs/d
1615
running file checks on website/docs/d/example.html.md

cmd/tfplugindocs/testdata/scripts/schema-json/validate/framework_provider_success_registry_docs.txtar

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ cmpenv stdout expected-output.txt
1010
exporting schema from JSON file
1111
getting provider schema
1212
running mixed directories check
13-
running number of files check
1413
detected static docs directory, running checks
1514
running invalid directories check on docs/data-sources
1615
running file checks on docs/data-sources/example.md

internal/check/directory.go

-36
Original file line numberDiff line numberDiff line change
@@ -118,42 +118,6 @@ func MixedDirectoriesCheck(docFiles []string) error {
118118
return nil
119119
}
120120

121-
// NumberOfFilesCheck verifies that documentation is below the Terraform Registry storage limit.
122-
// This check presumes that all provided directories are valid, e.g. that directory checking
123-
// for invalid or mixed directory structures was previously completed.
124-
func NumberOfFilesCheck(docFiles []string) error {
125-
var numberOfFiles int
126-
127-
directoryCounts := make(map[string]int)
128-
for _, file := range docFiles {
129-
directory := filepath.Dir(file)
130-
131-
// Ignore CDKTF files. The file limit is per-language and presumably there is one CDKTF file per source HCL file.
132-
if IsValidCdktfDirectory(directory) {
133-
continue
134-
}
135-
136-
if directory == RegistryIndexDirectory || directory == filepath.FromSlash(LegacyIndexDirectory) {
137-
continue
138-
}
139-
140-
directoryCounts[directory]++
141-
}
142-
143-
for directory, count := range directoryCounts {
144-
145-
log.Printf("[TRACE] Found %d documentation files in directory: %s", count, directory)
146-
numberOfFiles = numberOfFiles + count
147-
}
148-
149-
log.Printf("[DEBUG] Found %d documentation files with limit of %d", numberOfFiles, RegistryMaximumNumberOfFiles)
150-
if numberOfFiles >= RegistryMaximumNumberOfFiles {
151-
return fmt.Errorf("exceeded maximum (%d) number of documentation files for Terraform Registry: %d", RegistryMaximumNumberOfFiles, numberOfFiles)
152-
}
153-
154-
return nil
155-
}
156-
157121
func IsValidLegacyDirectory(directory string) bool {
158122
for _, validLegacyDirectory := range ValidLegacyDirectories {
159123
if directory == filepath.FromSlash(validLegacyDirectory) {

internal/check/directory_test.go

-48
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
package check
55

66
import (
7-
"fmt"
87
"os"
98
"path/filepath"
109
"testing"
@@ -14,43 +13,6 @@ import (
1413

1514
var DocumentationGlobPattern = `{docs/index.md,docs/{,cdktf/}{data-sources,guides,resources,functions}/**/*,website/docs/**/*}`
1615

17-
func TestNumberOfFilesCheck(t *testing.T) {
18-
t.Parallel()
19-
testCases := map[string]struct {
20-
files []string
21-
ExpectError bool
22-
}{
23-
"under limit": {
24-
files: testGenerateFiles(RegistryMaximumNumberOfFiles - 1),
25-
},
26-
"at limit": {
27-
files: testGenerateFiles(RegistryMaximumNumberOfFiles),
28-
ExpectError: true,
29-
},
30-
"over limit": {
31-
files: testGenerateFiles(RegistryMaximumNumberOfFiles + 1),
32-
ExpectError: true,
33-
},
34-
}
35-
36-
for name, testCase := range testCases {
37-
name := name
38-
testCase := testCase
39-
t.Run(name, func(t *testing.T) {
40-
t.Parallel()
41-
got := NumberOfFilesCheck(testCase.files)
42-
43-
if got == nil && testCase.ExpectError {
44-
t.Errorf("expected error, got no error")
45-
}
46-
47-
if got != nil && !testCase.ExpectError {
48-
t.Errorf("expected no error, got error: %s", got)
49-
}
50-
})
51-
}
52-
}
53-
5416
func TestMixedDirectoriesCheck(t *testing.T) {
5517
t.Parallel()
5618
testCases := map[string]struct {
@@ -91,13 +53,3 @@ func TestMixedDirectoriesCheck(t *testing.T) {
9153
})
9254
}
9355
}
94-
95-
func testGenerateFiles(numberOfFiles int) []string {
96-
files := make([]string, numberOfFiles)
97-
98-
for i := 0; i < numberOfFiles; i++ {
99-
files[i] = fmt.Sprintf("thing%d.md", i)
100-
}
101-
102-
return files
103-
}

internal/provider/validate.go

-4
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,6 @@ func (v *validator) validate(ctx context.Context) error {
170170
err = check.MixedDirectoriesCheck(files)
171171
result = errors.Join(result, err)
172172

173-
v.logger.infof("running number of files check")
174-
err = check.NumberOfFilesCheck(files)
175-
result = errors.Join(result, err)
176-
177173
if dirExists(filepath.Join(v.providerDir, "docs")) {
178174
v.logger.infof("detected static docs directory, running checks")
179175
err = v.validateStaticDocs(filepath.Join(v.providerDir, "docs"))

0 commit comments

Comments
 (0)