diff --git a/bot/internal/bot/bot.go b/bot/internal/bot/bot.go index e5476c91..5ec0e3f7 100644 --- a/bot/internal/bot/bot.go +++ b/bot/internal/bot/bot.go @@ -31,7 +31,11 @@ import ( // isCRDRegex matches Teleport operator CRD file paths. // Those files receive a special treatment as they're automatically generated. -var isCRDRegex = regexp.MustCompile(`.*/resources\.teleport\.dev_[[:alnum:]]+\.yaml$`) +var ( + isCRDRegex = regexp.MustCompile(`.*/resources\.teleport\.dev_[[:alnum:]]+\.yaml$`) + isTerraformSchemaRegexp = regexp.MustCompile(`integrations/terraform/tfschema/.+_terraform.go$`) + isOperatorDeepCopyRegexp = regexp.MustCompile(`integrations/operator/apis/resources/.+/zz_generated.deepcopy.go$`) +) // Client implements the GitHub API. type Client interface { @@ -279,9 +283,15 @@ func skipFileForSizeCheck(name string) bool { strings.HasSuffix(name, ".json") || strings.HasSuffix(name, ".snap") || strings.Contains(name, "webassets/") || + strings.HasSuffix(name, "derived.gen.go") || strings.Contains(name, "vendor/") || strings.Contains(name, "integrations/operator/crdgen/testdata/") || - isCRDRegex.MatchString(name) + strings.HasPrefix(name, "docs/pages/reference/infrastructure-as-code/terraform-provider/") || + strings.HasPrefix(name, "docs/pages/reference/infrastructure-as-code/operator-resources/") || + strings.HasPrefix(name, "docs/pages/includes/helm-reference/") || + isCRDRegex.MatchString(name) || + isTerraformSchemaRegexp.MatchString(name) || + isOperatorDeepCopyRegexp.MatchString(name) } func isReleaseBranch(branch string) bool { diff --git a/bot/internal/bot/bot_test.go b/bot/internal/bot/bot_test.go index c8a7e9d3..eaf2c01e 100644 --- a/bot/internal/bot/bot_test.go +++ b/bot/internal/bot/bot_test.go @@ -20,6 +20,7 @@ import ( "context" "testing" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/gravitational/shared-workflows/bot/internal/env" @@ -534,3 +535,45 @@ func (f *fakeGithub) GetRef(ctx context.Context, organization string, repository func (f *fakeGithub) ListCommitFiles(ctx context.Context, organization string, repository string, commitSHA string, pathPrefix string) ([]string, error) { return f.commitFiles, nil } + +func TestSkipFileForSizeCheck(t *testing.T) { + generatedFilePaths := []string{ + // go types from proto + "api/types/types.pb.go", + "api/gen/proto/go/teleport/accesslist/v1/accesslist.pb.go", + // derived functions + "api/types/accesslist/derived.gen.go", + // generated docs + "docs/pages/includes/helm-reference/zz_generated.teleport-kube-agent.mdx", + "docs/pages/reference/infrastructure-as-code/operator-resources/resources-teleport-dev-accesslists.mdx", + "docs/pages/reference/infrastructure-as-code/terraform-provider/resources/access_list.mdx", + "docs/pages/reference/infrastructure-as-code/terraform-provider/data-sources/access_list.mdx", + // CRDs + "integrations/operator/config/crd/bases/resources.teleport.dev_accesslists.yaml", + "examples/chart/teleport-cluster/charts/teleport-operator/operator-crds/resources.teleport.dev_accesslists.yaml", + // CRs deepcopy + "integrations/operator/apis/resources/v1/zz_generated.deepcopy.go", + // TF schemas + "integrations/terraform/tfschema/types_terraform.go", + "integrations/terraform/tfschema/accesslist/v1/accesslist_terraform.go", + } + for _, file := range generatedFilePaths { + assert.True(t, skipFileForSizeCheck(file), "file %q should be skipped for size check", file) + } + + // This is not very scientific but here are a few files that are similar to + // the generated ones but are hand-crafted. This test is not exhaustive, it + // is only here to avoid an accidental catch-all regexp. + nonGeneratedFilePaths := []string{ + "api/types/access_request.go", + "api/types/accesslist/accesslist.go", + "lib/accesslists/collection.go", + "integrations/terraform/tfschema/accesslist/v1/custom_types.go", + "integrations/operator/apis/resources/v1/accesslist_types.go", + "docs/pages/identity-governance/access-lists/access-lists.mdx", + } + + for _, file := range nonGeneratedFilePaths { + assert.False(t, skipFileForSizeCheck(file), "file %q should not be skipped for size check", file) + } +}