Skip to content

Commit

Permalink
ci: report failure to generate code as a test failure to teamcity
Browse files Browse the repository at this point in the history
Closes #78368.

Release note: None
  • Loading branch information
rickystewart committed Mar 28, 2022
1 parent fe42be5 commit 37d3c8c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
14 changes: 9 additions & 5 deletions build/teamcity-check-genfiles.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ tc_prepare

tc_start_block "Ensure generated code is up-to-date"

begin_check_generated_code_tests

# NOTE(ricky): Please make sure any changes to the Bazel-related checks here are
# propagated to build/teamcity/cockroach/ci/tests/check_generated_code_impl.sh
# as well.
Expand All @@ -29,24 +31,26 @@ if grep TODO DEPS.bzl; then
echo "Missing TODO comment in DEPS.bzl. Did you run \`./dev generate bazel --mirror\`?"
exit 1
fi
check_workspace_clean "Run \`./dev generate bazel\` to automatically regenerate these."
check_workspace_clean 'dev_generate_bazel' "Run \`./dev generate bazel\` to automatically regenerate these."
run build/builder.sh make generate &> artifacts/generate.log || (cat artifacts/generate.log && false)
rm artifacts/generate.log
check_workspace_clean "Run \`make generate\` to automatically regenerate these."
check_workspace_clean 'make_generate' "Run \`make generate\` to automatically regenerate these."
run build/builder.sh make buildshort &> artifacts/buildshort.log || (cat artifacts/buildshort.log && false)
rm artifacts/buildshort.log
check_workspace_clean "Run \`make buildshort\` to automatically regenerate these."
check_workspace_clean 'make_buildshort' "Run \`make buildshort\` to automatically regenerate these."
tc_end_block "Ensure generated code is up-to-date"

# generated code can generate new dependencies; check dependencies after generated code.
tc_start_block "Ensure dependencies are up-to-date"
# Run go mod tidy and `make -k vendor_rebuild` and ensure nothing changes.
run build/builder.sh go mod tidy
check_workspace_clean "Run \`go mod tidy\` and \`make -k vendor_rebuild\` to automatically regenerate these."
check_workspace_clean 'go_mod_tidy' "Run \`go mod tidy\` and \`make -k vendor_rebuild\` to automatically regenerate these."
run build/builder.sh make -k vendor_rebuild
cd vendor
check_workspace_clean "Run \`make -k vendor_rebuild\` to automatically regenerate these."
check_workspace_clean 'vendor_rebuild' "Run \`make -k vendor_rebuild\` to automatically regenerate these."
cd ..

end_check_generated_code_tests
tc_end_block "Ensure dependencies are up-to-date"

tc_start_block "Test web UI"
Expand Down
18 changes: 15 additions & 3 deletions build/teamcity-support.sh
Original file line number Diff line number Diff line change
Expand Up @@ -307,17 +307,29 @@ generate_ssh_key() {
fi
}

# Call this function with one argument, the error message to print if the
# workspace is dirty.
begin_check_generated_code_tests() {
echo "##teamcity[testSuiteStarted name='CheckGeneratedCode']"
}

end_check_generated_code_tests() {
echo "##teamcity[testSuiteFinished name='CheckGeneratedCode']"
}

# Call this function with two arguments: the name of the "test" that will be
# reported to teamcity and the error message to print if the workspace is dirty.
check_workspace_clean() {
echo "##teamcity[testStarted name='CheckGeneratedCode/$1' captureStandardOutput='true']"
# The workspace is clean iff `git status --porcelain` produces no output. Any
# output is either an error message or a listing of an untracked/dirty file.
if [[ "$(git status --porcelain 2>&1)" != "" ]]; then
git status >&2 || true
git diff -a >&2 || true
echo "====================================================" >&2
echo "Some automatically generated code is not up to date." >&2
echo $1 >&2
echo $2 >&2
echo "##teamcity[testFailed name='CheckGeneratedCode/$1']"
echo "##teamcity[testFinished name='CheckGeneratedCode/$1']"
exit 1
fi
echo "##teamcity[testFinished name='CheckGeneratedCode/$1']"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ source "$dir/teamcity-support.sh" # For $root, check_workspace_clean

mkdir -p artifacts

begin_check_generated_code_tests

# Buffer noisy output and only print it on failure.
if ! (./build/bazelutil/check.sh &> artifacts/buildshort.log || (cat artifacts/buildshort.log && false)); then
# The command will output instructions on how to fix the error.
Expand All @@ -24,11 +26,13 @@ if grep TODO DEPS.bzl; then
echo "Missing TODO comment in DEPS.bzl. Did you run \`./dev generate bazel --mirror\`?"
exit 1
fi
check_workspace_clean "Run \`./dev generate bazel\` to automatically regenerate these."
check_workspace_clean 'dev_generate_bazel' "Run \`./dev generate bazel\` to automatically regenerate these."

# Run go mod tidy and ensure nothing changes.
# NB: If files are missing from any packages then `go mod tidy` will
# fail. So we need to make sure that `.pb.go` sources are populated.
bazel run //pkg/gen:go_proto
bazel run @go_sdk//:bin/go --ui_event_filters=-DEBUG,-info,-stdout,-stderr --noshow_progress mod tidy
check_workspace_clean "Run \`go mod tidy\` to automatically regenerate these."
check_workspace_clean 'go_mod_tidy' "Run \`go mod tidy\` to automatically regenerate these."

end_check_generated_code_tests

0 comments on commit 37d3c8c

Please sign in to comment.