mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
Run multi-module check during presubmit
This commit is contained in:
13
Makefile
13
Makefile
@@ -6,6 +6,7 @@
|
|||||||
MYGOBIN := $(shell go env GOPATH)/bin
|
MYGOBIN := $(shell go env GOPATH)/bin
|
||||||
SHELL := /bin/bash
|
SHELL := /bin/bash
|
||||||
export PATH := $(MYGOBIN):$(PATH)
|
export PATH := $(MYGOBIN):$(PATH)
|
||||||
|
MODULES := "cmd/config" "api/" "kustomize/" "kyaml/"
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
all: verify-kustomize
|
all: verify-kustomize
|
||||||
@@ -23,6 +24,7 @@ verify-kustomize: \
|
|||||||
.PHONY: prow-presubmit-check
|
.PHONY: prow-presubmit-check
|
||||||
prow-presubmit-check: \
|
prow-presubmit-check: \
|
||||||
lint-kustomize \
|
lint-kustomize \
|
||||||
|
test-multi-module \
|
||||||
test-unit-kustomize-all \
|
test-unit-kustomize-all \
|
||||||
test-unit-cmd-all \
|
test-unit-cmd-all \
|
||||||
test-go-mod \
|
test-go-mod \
|
||||||
@@ -226,6 +228,17 @@ test-unit-cmd-all:
|
|||||||
test-go-mod:
|
test-go-mod:
|
||||||
./travis/check-go-mod.sh
|
./travis/check-go-mod.sh
|
||||||
|
|
||||||
|
# Environment variables are defined at
|
||||||
|
# https://github.com/kubernetes/test-infra/blob/master/prow/jobs.md#job-environment-variables
|
||||||
|
.PHONY: test-multi-module
|
||||||
|
test-multi-module:
|
||||||
|
go install github.com/google/go-github/github
|
||||||
|
go run ./cmd/prchecker \
|
||||||
|
-owner=$(REPO_OWNER) \
|
||||||
|
-repo=$(REPO_NAME) \
|
||||||
|
-pr=$(PR_NUM) \
|
||||||
|
$(MODULES)
|
||||||
|
|
||||||
.PHONY:
|
.PHONY:
|
||||||
test-examples-e2e-kustomize: $(MYGOBIN)/mdrip $(MYGOBIN)/kind
|
test-examples-e2e-kustomize: $(MYGOBIN)/mdrip $(MYGOBIN)/kind
|
||||||
( \
|
( \
|
||||||
|
|||||||
@@ -27,9 +27,8 @@ import (
|
|||||||
|
|
||||||
// splitCommitsHelp is a help message displayed when a PR has commits which
|
// splitCommitsHelp is a help message displayed when a PR has commits which
|
||||||
// span modules.
|
// span modules.
|
||||||
const splitCommitsHelp = "\nModifications to multiple restricted directories occurred.\n" +
|
const splitCommitsHelp = "\nCommits that include multiple Go modules must be split into multiple commits that each touch no more than one module.\n" +
|
||||||
"To resolve this please limit code changes in a commit to a single go module.\n\n" +
|
"Splitting instructions: https://git-scm.com/docs/git-rebase#_splitting_commits\n"
|
||||||
"You may learn more about how to split your existing commits at: https://git-scm.com/docs/git-rebase#_splitting_commits\n"
|
|
||||||
|
|
||||||
// Ignore span pattern defines a regular expression pattern that, when matched,
|
// Ignore span pattern defines a regular expression pattern that, when matched,
|
||||||
// causes this check to be ignored.
|
// causes this check to be ignored.
|
||||||
@@ -62,16 +61,33 @@ type GitHubService interface {
|
|||||||
ListCommits(prId int, options *github.ListOptions) ([]*github.RepositoryCommit, *github.Response, error)
|
ListCommits(prId int, options *github.ListOptions) ([]*github.RepositoryCommit, *github.Response, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository GitHubRepository) GetPullRequest(prId int) (*github.PullRequest, *github.Response, error) {
|
// GetPullRequest retrieves details about a pull request from GitHub API
|
||||||
return repository.client.PullRequests.Get(context.Background(), *repository.owner, *repository.repo, prId)
|
func (repository GitHubRepository) GetPullRequest(prId int) (
|
||||||
|
*github.PullRequest, *github.Response, error) {
|
||||||
|
return repository.client.PullRequests.Get(
|
||||||
|
context.Background(),
|
||||||
|
*repository.owner,
|
||||||
|
*repository.repo,
|
||||||
|
prId)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository GitHubRepository) GetCommit(commitSha string) (*github.RepositoryCommit, *github.Response, error) {
|
// GetCommit retrieves commit details from GitHub API
|
||||||
return repository.client.Repositories.GetCommit(context.Background(), *repository.owner, *repository.repo, commitSha)
|
func (repository GitHubRepository) GetCommit(commitSha string) (
|
||||||
|
*github.RepositoryCommit, *github.Response, error) {
|
||||||
|
return repository.client.Repositories.GetCommit(context.Background(),
|
||||||
|
*repository.owner,
|
||||||
|
*repository.repo,
|
||||||
|
commitSha)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repository GitHubRepository) ListCommits(prId int, options *github.ListOptions) ([]*github.RepositoryCommit, *github.Response, error) {
|
// ListCommits lists commits in a PR via GitHub API
|
||||||
return repository.client.PullRequests.ListCommits(context.Background(), *repository.owner, *repository.repo, prId, options)
|
func (repository GitHubRepository) ListCommits(prId int, options *github.ListOptions) (
|
||||||
|
[]*github.RepositoryCommit, *github.Response, error) {
|
||||||
|
return repository.client.PullRequests.ListCommits(context.Background(),
|
||||||
|
*repository.owner,
|
||||||
|
*repository.repo,
|
||||||
|
prId,
|
||||||
|
options)
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -145,7 +161,7 @@ func StringAllowsModuleSpan(body string) (bool, error) {
|
|||||||
return regexp.MatchString(ignoreSpanPattern, body)
|
return regexp.MatchString(ignoreSpanPattern, body)
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsModuleSpanAllowed tests a Pull Requests description for a regular
|
// ModuleSpanAllowed tests a Pull Requests description for a regular
|
||||||
// expression. If the expression matches then spanning modules are allowed.
|
// expression. If the expression matches then spanning modules are allowed.
|
||||||
func ModuleSpanAllowed(repository GitHubService, pullId int) (bool, error) {
|
func ModuleSpanAllowed(repository GitHubService, pullId int) (bool, error) {
|
||||||
|
|
||||||
@@ -163,9 +179,6 @@ func ModuleSpanAllowed(repository GitHubService, pullId int) (bool, error) {
|
|||||||
// GetCommitChanges looks up a github commit by SHA and returns a Changeset
|
// GetCommitChanges looks up a github commit by SHA and returns a Changeset
|
||||||
// containing the modified files in the specified commit.
|
// containing the modified files in the specified commit.
|
||||||
func GetCommitChanges(repository GitHubService, commitSha string) (*Changeset, error) {
|
func GetCommitChanges(repository GitHubService, commitSha string) (*Changeset, error) {
|
||||||
|
|
||||||
// Note: There are multiple ways to pull a github commit object
|
|
||||||
// we want a RepositoryCommit.
|
|
||||||
commit, _, err := repository.GetCommit(commitSha)
|
commit, _, err := repository.GetCommit(commitSha)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -210,7 +223,7 @@ func GetPullRequestCommits(repository GitHubService, pullrequest int) ([]*Change
|
|||||||
return changesetResults, nil
|
return changesetResults, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsPullRequestSpanningPathList tests if a pull request spans multiple
|
// PullRequestSpanningPathList tests if a pull request spans multiple
|
||||||
// directory paths
|
// directory paths
|
||||||
func PullRequestSpanningPathList(repository GitHubService, pullrequest int, paths []string) (bool, []*Changeset, error) {
|
func PullRequestSpanningPathList(repository GitHubService, pullrequest int, paths []string) (bool, []*Changeset, error) {
|
||||||
// Create a buffer for commits
|
// Create a buffer for commits
|
||||||
@@ -237,7 +250,7 @@ func PullRequestSpanningPathList(repository GitHubService, pullrequest int, path
|
|||||||
return spanningChangesExist, changesets, nil
|
return spanningChangesExist, changesets, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsChangesetSpanningPathList tests if a changeset is spanning
|
// ChangesetSpanningPathList tests if a changeset is spanning
|
||||||
// multiple directory paths.
|
// multiple directory paths.
|
||||||
func ChangesetSpanningPathList(changeset *Changeset, paths []string) bool {
|
func ChangesetSpanningPathList(changeset *Changeset, paths []string) bool {
|
||||||
matchedPath := ""
|
matchedPath := ""
|
||||||
@@ -254,6 +267,5 @@ func ChangesetSpanningPathList(changeset *Changeset, paths []string) bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If more than 1 matched paths then the changeset spans paths
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user