vault/tools/pipeline/internal/pkg/changed/checkers_test.go
Ryan Cragun 10c4371135
VAULT-34834: pipeline: add better heuristics for changed files (#30284)
* VAULT-34834: pipeline: add better heuristics for changed files

To fully support automated Enterprise to Community backports we need to
have better changed file detection for community and enterprise only
files. Armed with this metadata, future changes will be able to inspect
changed files and automatically remove enterprise only files when
creating the CE backports.

For this change we now have the following changed file groups:
  - autopilot
  - changelog
  - community
  - docs
  - enos
  - enterprise
  - app
  - gotoolchain
  - pipeline
  - proto
  - tools
  - ui

Not included in the change, but something I did while updating out
checkers was generate a list of files that included only in
vault-enterprise and run every path the enterprise detection rules
to ensure that they are categorized appropriately post changes in
VAULT-35431. While it's possible that they'll drift, our changed
file categorization is best effort anyway and changes will always
happen in vault-enterprise and require a developer to approve the
changes.

We've also included a few new files into the various groups and updated
the various workflows to use the new categories. I've also included a
small change to the pipeline composite action whereby we do not handle
Go module caching. This will greatly reduce work on doc-only branches
that need only ensure that the pipeline binary is compiled.

Signed-off-by: Ryan Cragun <me@ryan.ec>
2025-04-18 10:54:41 -06:00

75 lines
4.6 KiB
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package changed
import (
"context"
"testing"
"github.com/google/go-github/v68/github"
"github.com/stretchr/testify/require"
)
func TestFileGroupDefaultCheckers(t *testing.T) {
t.Parallel()
for filename, groups := range map[string]FileGroups{
".github/actions/changed-files/actions.yml": {FileGroupPipeline},
".github/workflows/build.yml": {FileGroupPipeline},
".github/workflows/build-artifacts-ce.yml": {FileGroupCommunity, FileGroupPipeline},
".github/workflows/build-artifacts-ent.yml": {FileGroupEnterprise, FileGroupPipeline},
".go-version": {FileGroupGoToolchain},
"audit/backend_ce.go": {FileGroupGoApp, FileGroupCommunity},
"audit/backend_config_ent.go": {FileGroupGoApp, FileGroupEnterprise},
"builtin/logical/transit/something_ent.go": {FileGroupGoApp, FileGroupEnterprise},
"buf.yml": {FileGroupProto},
"changelog/1726.txt": {FileGroupChangelog},
"changelog/_1726.txt": {FileGroupChangelog, FileGroupEnterprise},
"command/server/config.go": {FileGroupGoApp},
"command/operator_raft_autopilot_state.go": {FileGroupGoApp, FileGroupAutopilot},
"command/agent_ent_test.go": {FileGroupGoApp, FileGroupEnterprise},
"enos/enos-samples-ce-build.hcl": {FileGroupCommunity, FileGroupEnos},
"enos/enos-samples-ent-build.hcl": {FileGroupEnos, FileGroupEnterprise},
"enos/enos-scenario-smoke.hcl": {FileGroupEnos},
"enos/enos-scenario-autopilot-ent.hcl": {FileGroupEnos, FileGroupEnterprise},
"go.mod": {FileGroupGoApp, FileGroupGoToolchain},
"go.sum": {FileGroupGoApp, FileGroupGoToolchain},
"helper/identity/mfa/types.proto": {FileGroupProto},
"http/util_stubs_oss.go": {FileGroupGoApp, FileGroupCommunity},
"physical/raft/raft_autopilot.go": {FileGroupGoApp, FileGroupAutopilot},
"physical/raft/types.proto": {FileGroupProto},
"scripts/ci-helper.sh": {FileGroupPipeline},
"scripts/cross/Dockerfile-ent": {FileGroupEnterprise, FileGroupPipeline},
"scripts/cross/Dockerfile-ent-hsm": {FileGroupEnterprise, FileGroupPipeline},
"scripts/dev/hsm/README.md": {FileGroupEnterprise, FileGroupPipeline},
"scripts/dist-ent.sh": {FileGroupEnterprise, FileGroupPipeline},
"scripts/testing/test-vault-license.sh": {FileGroupEnterprise, FileGroupPipeline},
"scripts/testing/upgrade/README.md": {FileGroupEnterprise, FileGroupPipeline},
"sdk/database/dbplugin/v5/proto/database_ent.pb.go": {FileGroupGoApp, FileGroupEnterprise},
"sdk/database/dbplugin/v5/proto/database_ent.proto": {FileGroupEnterprise, FileGroupProto},
"specs/merkle-tree/spec.md": {FileGroupEnterprise},
"tools/pipeline/main.go": {FileGroupPipeline},
"ui/lib/ldap/index.js": {FileGroupWebUI},
"vault/acl.go": {FileGroupGoApp},
"vault/activity_log_util_ent.go": {FileGroupGoApp, FileGroupEnterprise},
"vault/identity_store_ent_test.go": {FileGroupGoApp, FileGroupEnterprise},
"vault_ent/go.mod": {FileGroupGoApp, FileGroupEnterprise, FileGroupGoToolchain},
"vault_ent/go.sum": {FileGroupGoApp, FileGroupEnterprise, FileGroupGoToolchain},
"vault_ent/requires_ent.go": {FileGroupGoApp, FileGroupEnterprise},
"website/content/api-docs/index.mdx": {FileGroupDocs},
"CHANGELOG.md": {FileGroupChangelog},
"CODEOWNERS": {FileGroupPipeline},
"Dockerfile": {FileGroupPipeline},
"Makefile": {FileGroupPipeline},
"README.md": {FileGroupDocs},
} {
t.Run(filename, func(t *testing.T) {
t.Parallel()
file := &File{File: &github.CommitFile{Filename: &filename}}
Group(context.Background(), file, DefaultFileGroupCheckers...)
require.Equal(t, groups, file.Groups)
})
}
}