Skip to content

Commit 7c728c8

Browse files
authored
TOOLS-4235 Move evergreen validate to precious config (#1019)
1 parent 123cf95 commit 7c728c8

5 files changed

Lines changed: 63 additions & 52 deletions

File tree

build.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ func init() {
5151
taskRegistry.Declare("sa:modtidy").
5252
Description("runs go mod tidy").
5353
Do(buildscript.SAModTidy)
54-
taskRegistry.Declare("sa:evgvalidate").
55-
Description("runs evergreen validate").
56-
Do(buildscript.SAEvergreenValidate)
5754

5855
// Testing
5956
taskRegistry.Declare("test:unit").

buildscript/sa.go

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"fmt"
77
"os"
88
"os/exec"
9-
"strings"
109

1110
"github.com/craiggwilson/goke/pkg/sh"
1211
"github.com/craiggwilson/goke/task"
@@ -69,39 +68,3 @@ func SAModTidy(ctx *task.Context) error {
6968

7069
return nil
7170
}
72-
73-
// SAEvergreenValidate runs `evergreen validate` on common.yml and ensures the file is valid.
74-
func SAEvergreenValidate(ctx *task.Context) error {
75-
output, err := sh.RunOutput(
76-
ctx,
77-
"evergreen",
78-
"validate",
79-
"--file",
80-
"common.yml",
81-
"-p",
82-
"mongo-tools",
83-
)
84-
if err != nil {
85-
return fmt.Errorf("error from `evergreen validate`: %s: %w", output, err)
86-
}
87-
88-
if strings.HasSuffix(output, "is valid with warnings") {
89-
for _, line := range strings.Split(output, "\n") {
90-
if strings.HasPrefix(line, "WARNING: ") &&
91-
strings.HasSuffix(
92-
line,
93-
"defined but not used by any variants; consider using or disabling",
94-
) {
95-
continue
96-
}
97-
98-
if strings.HasSuffix(line, "is valid with warnings") {
99-
continue
100-
}
101-
102-
return fmt.Errorf("error from `evergreen validate`: %s", output)
103-
}
104-
}
105-
106-
return nil
107-
}

common.yml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,6 @@ functions:
229229
230230
${_set_shell_env}
231231
${_maybe_enable_devtoolset_7}
232-
# The evergreen client binary lives in $HOME, and `sa:evgvalidate` shells out to it.
233-
export PATH="$PATH:$HOME"
234232
$GO_EXEC_PREFIX go run build.go -v ${target}
235233
236234
"download mongod and shell":
@@ -2375,20 +2373,12 @@ tasks:
23752373
vars:
23762374
target: sa:modtidy
23772375

2378-
- name: evergreen-validate
2379-
commands:
2380-
- func: "fetch source"
2381-
- func: "install mise and go"
2382-
- func: "create evergreen config file"
2383-
- func: "run make target"
2384-
vars:
2385-
target: sa:evgvalidate
2386-
23872376
- name: lint
23882377
commands:
23892378
- func: "fetch source"
23902379
- func: "install mise and go"
23912380
- func: "install mise-managed tools"
2381+
- func: "create evergreen config file"
23922382
- command: shell.exec
23932383
type: test
23942384
params:
@@ -2400,6 +2390,9 @@ tasks:
24002390
set -o verbose
24012391
24022392
${_set_shell_env}
2393+
# The evergreen client binary lives in $HOME, and the evergreen-validate precious
2394+
# command shells out to it.
2395+
export PATH="$PATH:$HOME"
24032396
mise exec 'github:houseabsolute/precious' -- precious lint --all
24042397
24052398
- name: qa-tests-5.0
@@ -2691,7 +2684,6 @@ buildvariants:
26912684
tasks:
26922685
- name: lint
26932686
- name: mod-tidy
2694-
- name: evergreen-validate
26952687
- name: check-third-party-notices
26962688
- name: check-sbom-lite
26972689
- name: check-sarif-report

etc/evergreen-validate-wrapper.sh

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env bash
2+
3+
# `evergreen validate` exits 0 even when it reports warnings, and it always writes to stdout, not
4+
# stderr. We want to fail on any warning except the specific pre-existing ones listed below, but
5+
# precious's ignore-stderr can't do that: it only looks at stderr, and it's all-or-nothing (matching
6+
# one pattern suppresses the whole output, not just that line). So we do the line-by-line filtering
7+
# here instead.
8+
#
9+
# Each accepted warning is matched exactly, by task name, rather than by a wildcard "defined but
10+
# not used" pattern. A new unused-task warning is a real problem to fix or explicitly allow here,
11+
# not something to pass silently just because it looks like the others.
12+
13+
set -o pipefail
14+
15+
TEMP_FILE=$(mktemp "${TMPDIR:-/tmp}/evergreen-validate.tmp.XXXXXXXXXX")
16+
trap 'rm -f "$TEMP_FILE"' EXIT
17+
18+
# The tee lets us capture the output for filtering below while still printing it to the console, so
19+
# it shows up when precious is run in verbose mode.
20+
evergreen validate --file common.yml -p mongo-tools 2>&1 | tee "$TEMP_FILE"
21+
STATUS=${PIPESTATUS[0]}
22+
23+
if [ "$STATUS" -ne 0 ]; then
24+
exit "$STATUS"
25+
fi
26+
27+
if grep --quiet "is valid with warnings" "$TEMP_FILE"; then
28+
while IFS= read -r line; do
29+
case "$line" in
30+
"WARNING: task 'commit-queue-workaround' defined but not used by any variants; consider using or disabling")
31+
continue
32+
;;
33+
"WARNING: task 'deliberate_fail_to_test_build_baron_context_rules' defined but not used by any variants; consider using or disabling")
34+
continue
35+
;;
36+
"WARNING: task 't_resmoke_setup' defined but not used by any variants; consider using or disabling")
37+
continue
38+
;;
39+
"WARNING: task 'generate_mongodump_fuzz_tasks' defined but not used by any variants; consider using or disabling")
40+
continue
41+
;;
42+
*"is valid with warnings")
43+
continue
44+
;;
45+
*)
46+
exit 1
47+
;;
48+
esac
49+
done <"$TEMP_FILE"
50+
fi

precious.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,15 @@ ok-exit-codes = 0
169169
lint-failure-exit-codes = 1
170170
labels = [ "default", "fast-tidy" ]
171171

172+
[commands.evergreen-validate]
173+
type = "lint"
174+
invoke = "once"
175+
path-args = "none"
176+
include = [ "common.yml", "mongodump_passthrough/*.yml" ]
177+
cmd = [ "$PRECIOUS_ROOT/etc/evergreen-validate-wrapper.sh" ]
178+
ok-exit-codes = [0]
179+
lint-failure-exit-codes = [1]
180+
172181
[commands.github-codeowners]
173182
type = "lint"
174183
invoke = "once"

0 commit comments

Comments
 (0)