Skip to content

Commit 3b20937

Browse files
authored
TOOLS-3911 Add a CODEOWNERS file (#811)
This also adds linting to make sure that we never add files without an owner. But right now all files are owned by the @mongodb/tar-osap team.
1 parent 5cd467f commit 3b20937

File tree

6 files changed

+99
-27
lines changed

6 files changed

+99
-27
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @mongodb/tar-osap

buildscript/sa.go

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ const (
2828

2929
// This is the latest version to support a YAML config file. Updating to
3030
// the new config file syntax did not seem trivial.
31-
eslintVersion = "8.57.0"
32-
golangCILintVersion = "1.64.5"
33-
golinesVersion = "0.12.2"
34-
gosecVersion = "2.20.0"
35-
preciousVersion = "0.7.3"
36-
ubiVersion = "0.4.2"
37-
prettierVersion = "3.4.2"
31+
eslintVersion = "8.57.0"
32+
gitHubCodeownersVersion = "0.2.1"
33+
golangCILintVersion = "1.64.5"
34+
golinesVersion = "0.12.2"
35+
gosecVersion = "2.20.0"
36+
preciousVersion = "0.7.3"
37+
ubiVersion = "0.4.2"
38+
prettierVersion = "3.4.2"
3839
)
3940

4041
func SAInstallDevTools(ctx *task.Context) error {
@@ -268,33 +269,44 @@ func installBinaryTool(
268269
// execution wipes the entire `node_modules` directory, so we only end up with one tool (the last
269270
// one) installed.
270271
func installJSTools(ctx *task.Context) error {
271-
eslint, err := eslintPath()
272+
eslint, err := npmPath("eslint")
272273
if err != nil {
273274
return err
274275
}
275276

276-
exists, err := executableExistsWithVersion(ctx, eslint, eslintVersion)
277+
prettier, err := npmPath("prettier")
277278
if err != nil {
278279
return err
279280
}
280-
if !exists {
281-
return runNPMInstall(ctx)
281+
282+
for _, tool := range [][]string{
283+
{eslint, eslintVersion},
284+
{prettier, prettierVersion},
285+
} {
286+
exists, err := executableExistsWithVersion(ctx, tool[0], tool[1])
287+
if err != nil {
288+
return err
289+
}
290+
if !exists {
291+
return runNPMInstall(ctx)
292+
}
282293
}
283294

284-
prettier, err := prettierPath()
295+
gitHubCodeowners, err := npmPath("github-codeowners")
285296
if err != nil {
286297
return err
287298
}
288299

289-
exists, err = executableExistsWithVersion(ctx, prettier, prettierVersion)
300+
// This program doesn't have any way to print its version. :(
301+
exists, err := fileExists(gitHubCodeowners)
290302
if err != nil {
291303
return err
292304
}
293-
if exists {
294-
return nil
305+
if !exists {
306+
return runNPMInstall(ctx)
295307
}
296308

297-
return runNPMInstall(ctx)
309+
return nil
298310
}
299311

300312
func runNPMInstall(ctx *task.Context) error {
@@ -304,22 +316,13 @@ func runNPMInstall(ctx *task.Context) error {
304316
)
305317
}
306318

307-
func eslintPath() (string, error) {
308-
root, err := repoRoot()
309-
if err != nil {
310-
return "", err
311-
}
312-
313-
return filepath.Join(root, "node_modules", ".bin", "eslint"), nil
314-
}
315-
316-
func prettierPath() (string, error) {
319+
func npmPath(exe string) (string, error) {
317320
root, err := repoRoot()
318321
if err != nil {
319322
return "", err
320323
}
321324

322-
return filepath.Join(root, "node_modules", ".bin", "prettier"), nil
325+
return filepath.Join(root, "node_modules", ".bin", exe), nil
323326
}
324327

325328
func SAPreciousLint(ctx *task.Context) error {

etc/github-codeowners-wrapper.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit
4+
set -o pipefail
5+
6+
STATUS=0
7+
8+
OUTPUT=$(./node_modules/.bin/github-codeowners audit --unloved --only-git)
9+
10+
if [ -n "$OUTPUT" ]; then
11+
echo "The repo contains unowned files. Please update the '.github/CODEOWNERS' file to include these files:"
12+
echo ""
13+
echo "$OUTPUT"
14+
echo ""
15+
STATUS=1
16+
fi
17+
18+
OUTPUT=$(./node_modules/.bin/github-codeowners validate 2>&1)
19+
if [ -n "$OUTPUT" ]; then
20+
echo "The '.github/CODEOWNERS' file is not valid:"
21+
echo ""
22+
echo "$OUTPUT"
23+
echo ""
24+
STATUS=1
25+
fi
26+
27+
exit $STATUS

package-lock.json

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"devDependencies": {
33
"eslint": "8.57.0",
4+
"github-codeowners": "0.2.1",
45
"prettier": "3.4.2"
56
}
67
}

precious.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,15 @@ cmd = "$PRECIOUS_ROOT/node_modules/.bin/eslint"
123123
tidy-flags = "--fix"
124124
ok-exit-codes = [0]
125125
lint-failure-exit-codes = [1]
126+
127+
[commands.github-codeowners]
128+
type = "lint"
129+
invoke = "once"
130+
path-args = "none"
131+
# We need to run this whenever new files are added to make sure they have an owner, so it's easiest
132+
# to just apply this linter to all files.
133+
include = "**/*"
134+
cmd = [ "$PRECIOUS_ROOT/etc/github-codeowners-wrapper.sh" ]
135+
ok_exit_codes = 0
136+
lint_failure_exit_codes = 1
137+
labels = [ "default", "fast-tidy" ]

0 commit comments

Comments
 (0)