build: add gazelle checks to Aspect Workflows (#58568)

Co-authored-by: William Bezuidenhout <william.bezuidenhout@sourcegraph.com>
This commit is contained in:
Greg Magolan 2023-11-27 01:50:46 -08:00 committed by GitHub
parent 5a70adce92
commit 9b8d25a5fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 1 deletions

View File

@ -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

View File

@ -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 = [

View File

@ -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"],

32
dev/ci/bazel-configure.sh Executable file
View File

@ -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