Skip to content

Commit

Permalink
codeowners,team: fix Bazel test builds
Browse files Browse the repository at this point in the history
The default locations for the `CODEOWNERS` and `TEAMS.yaml` files were
not correct when built with `bazel test`. This commit updates the
default locations to the proper ones for Bazel-based test builds.

Release note: None
  • Loading branch information
erikgrinaker committed Mar 15, 2021
1 parent 15fb8ad commit 4ca46bf
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .github/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
exports_files([
"CODEOWNERS",
])
4 changes: 4 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,7 @@ gazelle(
name = "gazelle",
prefix = "github.com/cockroachdb/cockroach",
)

exports_files([
"TEAMS.yaml",
])
6 changes: 5 additions & 1 deletion pkg/internal/codeowners/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ go_test(
name = "codeowners_test",
size = "small",
srcs = ["codeowners_test.go"],
data = [
"//:TEAMS.yaml",
"//.github:CODEOWNERS",
],
embed = [":codeowners"],
tags = ["broken_in_bazel"],
deps = [
"//pkg/build/bazel",
"//pkg/internal/team",
"@com_github_stretchr_testify//require",
],
Expand Down
18 changes: 18 additions & 0 deletions pkg/internal/codeowners/codeowners_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,31 @@
package codeowners

import (
"log"
"strings"
"testing"

"github.com/cockroachdb/cockroach/pkg/build/bazel"
"github.com/cockroachdb/cockroach/pkg/internal/team"
"github.com/stretchr/testify/require"
)

func init() {
if bazel.BuiltWithBazel() {
codeOwnersFile, err := bazel.Runfile(".github/CODEOWNERS")
if err != nil {
log.Fatal(err)
}
DefaultCodeOwnersLocation = codeOwnersFile

teamFile, err := bazel.Runfile("TEAMS.yaml")
if err != nil {
log.Fatal(err)
}
team.DefaultTeamsYAMLLocation = teamFile
}
}

func TestMatch(t *testing.T) {
owners := `
/a/ @cockroachdb/team-a
Expand Down
9 changes: 7 additions & 2 deletions pkg/internal/team/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ go_test(
name = "team_test",
size = "small",
srcs = ["team_test.go"],
data = [
"//:TEAMS.yaml",
],
embed = [":team"],
tags = ["broken_in_bazel"],
deps = ["@com_github_stretchr_testify//require"],
deps = [
"//pkg/build/bazel",
"@com_github_stretchr_testify//require",
],
)
12 changes: 12 additions & 0 deletions pkg/internal/team/team_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,23 @@ package team

import (
"bytes"
"log"
"testing"

"github.com/cockroachdb/cockroach/pkg/build/bazel"
"github.com/stretchr/testify/require"
)

func init() {
if bazel.BuiltWithBazel() {
teamFile, err := bazel.Runfile("TEAMS.yaml")
if err != nil {
log.Fatal(err)
}
DefaultTeamsYAMLLocation = teamFile
}
}

func TestLoadTeams(t *testing.T) {
yamlFile := []byte(`
sql:
Expand Down

0 comments on commit 4ca46bf

Please sign in to comment.