From 9b8d25a5fbd5c9072ceb9352451d078fd367b928 Mon Sep 17 00:00:00 2001 From: Greg Magolan Date: Mon, 27 Nov 2023 01:50:46 -0800 Subject: [PATCH] build: add gazelle checks to Aspect Workflows (#58568) Co-authored-by: William Bezuidenhout --- .aspect/workflows/config.yaml | 4 +++- BUILD.bazel | 7 +++++++ dev/ci/BUILD.bazel | 4 ++++ dev/ci/bazel-configure.sh | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100755 dev/ci/bazel-configure.sh diff --git a/.aspect/workflows/config.yaml b/.aspect/workflows/config.yaml index 95725c7650e..05f1c7c1c93 100644 --- a/.aspect/workflows/config.yaml +++ b/.aspect/workflows/config.yaml @@ -13,7 +13,9 @@ env: GIT_PAGER: '' tasks: # Checks that BUILD file content is up-to-date with sources - # gazelle: + gazelle: + target: //:configure + fix_target: //:configure # Checks that all tests are passing test: include_eternal_tests: true diff --git a/BUILD.bazel b/BUILD.bazel index f4d61f64c1b..b5661737c32 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -201,6 +201,13 @@ gazelle( gazelle = ":gazelle-buf", ) +sh_binary( + name = "configure", + srcs = ["//dev/ci:bazel-configure.sh"], + data = ["@go_sdk//:bin/go"], + env = {"GO": "$(rootpath @go_sdk//:bin/go)"}, +) + go_library( name = "sourcegraph", srcs = [ diff --git a/dev/ci/BUILD.bazel b/dev/ci/BUILD.bazel index f37785fe2a0..3a724bde6bb 100644 --- a/dev/ci/BUILD.bazel +++ b/dev/ci/BUILD.bazel @@ -1,5 +1,9 @@ load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") +exports_files([ + "bazel-configure.sh", +]) + go_library( name = "ci_lib", srcs = ["gen-pipeline.go"], diff --git a/dev/ci/bazel-configure.sh b/dev/ci/bazel-configure.sh new file mode 100755 index 00000000000..25816def674 --- /dev/null +++ b/dev/ci/bazel-configure.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +set -o errexit -o nounset -o pipefail + +# Add go to PATH +readonly runfiles_dir="${PWD}" +PATH="$(dirname "${runfiles_dir}/${GO}"):${PATH}" +# Remove bazelisk from path +PATH=$(echo "${PATH}" | awk -v RS=: -v ORS=: '/bazelisk/ {next} {print}') +export PATH +# Allow Aspect to re-enter again +export ASPECT_REENTRANT= + +cd "${BUILD_WORKSPACE_DIRECTORY}" + +bazel configure + +if [ "${CI:-}" ]; then + git ls-files --exclude-standard --others | grep -v .aspect/bazelrc/ci.generated.bazelrc | xargs git add --intent-to-add || true + + diff_file=$(mktemp) + trap 'rm -f "${diff_file}"' EXIT + + EXIT_CODE=0 + git diff --color=never --output="${diff_file}" --exit-code || EXIT_CODE=$? + + # if we have a diff, BUILD files were updated so we notify people + if [[ $EXIT_CODE -ne 0 ]]; then + cat "${diff_file}" + exit 1 + fi +fi