mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-06 22:57:02 +02:00
* VAULT-34822: Add `pipeline github list changed-files` Add a new `github list changed-files` sub-command to `pipeline` command and integrate it into the pipeline. This replaces our previous `changed-files.sh` script. This command works quite a bit differently than the full checkout and diff based solution we used before. Instead of checking out the base ref and head ref and comparing a diff, we now provide either a pull request number or git commit SHA and use the Github REST API to determine the changed files. This approach has several benefits: - Not requiring a local checkout of the repo to get the list of changed files. This yields a significant perfomance improvement in `setup` jobs where we typically determine the changed files list. - The CLI supports both PRs and commit SHAs. - The implementation is portable and doesn't require any system tools like `git` or `bash` to be installed. - A much more advanced system for adding group metadata to the changed files. These groupings are going to be used heavily in future pipeline automation work and will be used to make required jobs smarter. The theoretical drawbacks: - It requires a GITHUB_TOKEN and only works for remote branches or commits in Github. We could eventually add a local diff sub-command or option to work locally, but that was not required for what we're trying to achieve here. While the groupings that I added in this change are quite rudimentary, the system will allow us to add additional groups with very little overhead. I tried to make this change more or less a port of the old system to enable future work. I did include one small change of behavior, which is that we now build all extended targets if the `go.mod` or `go.sum` files change. We do this to ensure that dependency changes don't subtly result in some extended platform breakage. Signed-off-by: Ryan Cragun <me@ryan.ec>
83 lines
2.8 KiB
Go
83 lines
2.8 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 TestFileGroupCheckerDir(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
for filename, groups := range map[string]FileGroups{
|
|
".github/actions/changed-files/actions.yml": {FileGroupPipeline},
|
|
".github/workflows/build.yml": {FileGroupPipeline},
|
|
"changelog/16455.txt": {FileGroupChangelog},
|
|
"enos/Makefile": {FileGroupEnos},
|
|
"tools/pipeline/main.go": {FileGroupTools},
|
|
"ui/lib/ldap/index.js": {FileGroupWebUI},
|
|
"website/content/api-docs/index.mdx": {FileGroupDocs},
|
|
} {
|
|
t.Run(filename, func(t *testing.T) {
|
|
file := &File{File: &github.CommitFile{Filename: &filename}}
|
|
require.Equal(t, groups, FileGroupCheckerDir(context.Background(), file))
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestFileGroupCheckerFileName(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
for filename, groups := range map[string]FileGroups{
|
|
"buf.yml": {FileGroupProto},
|
|
"CHANGELOG.md": {FileGroupChangelog},
|
|
"CODEOWNERS": {FileGroupPipeline},
|
|
"go.mod": {FileGroupGoApp, FileGroupGoModules},
|
|
"go.sum": {FileGroupGoApp, FileGroupGoModules},
|
|
} {
|
|
t.Run(filename, func(t *testing.T) {
|
|
file := &File{File: &github.CommitFile{Filename: &filename}}
|
|
require.Equal(t, groups, FileGroupCheckerFileName(context.Background(), file))
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestFileGroupCheckerFileGo(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
for filename, groups := range map[string]FileGroups{
|
|
"vault/acl.go": {FileGroupGoApp},
|
|
"command/server/config.go": {FileGroupGoApp},
|
|
"tools/pipeline/main.go": {FileGroupGoApp, FileGroupPipeline},
|
|
"command/operator_raft_autopilot_state.go": {FileGroupGoApp, FileGroupAutopilot},
|
|
"physical/raft/raft_autopilot.go": {FileGroupGoApp, FileGroupAutopilot},
|
|
"http/util_stubs_oss.go": {FileGroupGoApp, FileGroupCommunity},
|
|
"audit/backend_ce.go": {FileGroupGoApp, FileGroupCommunity},
|
|
"vault/activity_log_util_ent.go": {FileGroupGoApp, FileGroupEnterprise},
|
|
} {
|
|
t.Run(filename, func(t *testing.T) {
|
|
file := &File{File: &github.CommitFile{Filename: &filename}}
|
|
require.Equal(t, groups, FileGroupCheckerFileGo(context.Background(), file))
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestFileGroupCheckerProto(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
for filename, groups := range map[string]FileGroups{
|
|
"physical/raft/types.proto": {FileGroupProto},
|
|
"helper/identity/mfa/types.proto": {FileGroupProto},
|
|
} {
|
|
t.Run(filename, func(t *testing.T) {
|
|
file := &File{File: &github.CommitFile{Filename: &filename}}
|
|
require.Equal(t, groups, FileGroupCheckerFileProto(context.Background(), file))
|
|
})
|
|
}
|
|
}
|