Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

ci: only run go steps if only changing go #12321

Merged
merged 2 commits into from
Jul 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions enterprise/dev/ci/ci/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ type Config struct {
// in the branch. If empty, then no check is enforced.
mustIncludeCommit []string

// changedFiles is the list of files that have changed since the
// merge-base with origin/master.
changedFiles []string

taggedRelease bool
releaseBranch bool
isBextReleaseBranch bool
Expand Down Expand Up @@ -78,12 +82,21 @@ func ComputeConfig() Config {
mustIncludeCommits[i] = strings.TrimSpace(mustIncludeCommits[i])
}
}

var changedFiles []string
if output, err := exec.Command("git", "diff", "--name-only", "origin/master...").Output(); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the merge target is not master?

Copy link
Member Author

@keegancsmith keegancsmith Jul 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that is fine, this will then just include more files than necessary. As an optimization if people have long lived dev branches we can make this smarter.

Note: this is the same check we have for docs changes.

panic(err)
} else {
changedFiles = strings.Split(strings.TrimSpace(string(output)), "\n")
}

return Config{
now: now,
branch: branch,
version: version,
commit: commit,
mustIncludeCommit: mustIncludeCommits,
changedFiles: changedFiles,

taggedRelease: taggedRelease,
releaseBranch: lazyregexp.New(`^[0-9]+\.[0-9]+$`).MatchString(branch),
Expand Down Expand Up @@ -131,13 +144,18 @@ func (c Config) isPR() bool {
!strings.HasPrefix(c.branch, "docker-images-patch/")
}

func isDocsOnly() bool {
output, err := exec.Command("git", "diff", "--name-only", "origin/master...").Output()
if err != nil {
panic(err)
func (c Config) isDocsOnly() bool {
for _, p := range c.changedFiles {
if !strings.HasPrefix(p, "doc/") && p != "CHANGELOG.md" {
return false
}
}
for _, line := range strings.Split(strings.TrimSpace(string(output)), "\n") {
if !strings.HasPrefix(line, "doc/") && line != "CHANGELOG.md" {
return true
}

func (c Config) isGoOnly() bool {
for _, p := range c.changedFiles {
if !strings.HasSuffix(p, ".go") {
return false
}
}
Expand Down
12 changes: 11 additions & 1 deletion enterprise/dev/ci/ci/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,21 @@ func GeneratePipeline(c Config) (*bk.Pipeline, error) {
// Generate pipeline steps. This statement outlines the pipeline steps for each CI case.
var pipelineOperations []func(*bk.Pipeline)
switch {
case c.isPR() && isDocsOnly():
case c.isPR() && c.isDocsOnly():
// If this is a docs-only PR, run only the steps necessary to verify the docs.
pipelineOperations = []func(*bk.Pipeline){
addDocs,
}

case c.isPR() && c.isGoOnly():
// If this is a go-only PR, run only the steps necessary to verify the go code.
pipelineOperations = []func(*bk.Pipeline){
addGoTests, // ~1.5m
addCheck, // ~1m
addGoBuild, // ~0.5m
addPostgresBackcompat, // ~0.25m
}

case c.patchNoTest:
// If this is a no-test branch, then run only the Docker build. No tests are run.
app := c.branch[27:]
Expand Down