diff --git a/.bazelrc.ci b/.bazelrc.ci index dd8f392a8552b0c0ed9d2eb1e11f10f36fd1bf91..3c6fb87e1623b8915e8d8e309f996c1b6f6cee0a 100644 --- a/.bazelrc.ci +++ b/.bazelrc.ci @@ -34,3 +34,8 @@ build --repository_cache=${CI_PROJECT_DIR}/.cache/bazel/repo # Here to dogfood the `ruleset` component build:local --enable_bzlmod + +# Version-specific .bazelrc +try-import %workspace%/.bazelrc.ci.${BAZEL_MAJOR_MINOR_PATCH_VERSION} +try-import %workspace%/.bazelrc.ci.${BAZEL_MAJOR_MINOR_VERSION} +try-import %workspace%/.bazelrc.ci.${BAZEL_MAJOR_VERSION} diff --git a/.bazelrc.ci.7.4.0 b/.bazelrc.ci.7.4.0 new file mode 100644 index 0000000000000000000000000000000000000000..d80cb8e01413dcfafe3ab332d882efacbf10c14e --- /dev/null +++ b/.bazelrc.ci.7.4.0 @@ -0,0 +1,2 @@ +# Here to validate the file is loaded +build --enable_bzlmod diff --git a/templates/bazelisk/template.yml b/templates/bazelisk/template.yml index ba9285665c2465f1d56d72cff525c8c546018b2c..1ae40abedcb7542bf02ac44ac8fe9ce3d1549698 100644 --- a/templates/bazelisk/template.yml +++ b/templates/bazelisk/template.yml @@ -34,26 +34,42 @@ spec: default: | CI_PROJECT_DIR CI_PROJECT_ID + BAZEL_MAJOR_VERSION + BAZEL_MAJOR_MINOR_VERSION + BAZEL_MAJOR_MINOR_PATCH_VERSION + BAZEL_VERSION description: "Variables to perform environment variable replacement in the Bazel run commands." --- .bazelisk-fragment: rc: - | - # Copying Bazel run commands set -euo pipefail - VARIABLES="${VARIABLES-$[[inputs.variables]]}" - while IFS= read -r LINE; do - for VARIABLE in ${VARIABLES}; do + # Determine Bazel version for run commands subtitutions + "$[[inputs.bazelisk]]" --version | while IFS=' .' read -r PREFIX MAJOR MINOR PATCH; do + test "${PREFIX}" == "bazel" + test "${MAJOR}" -ge 0 + test "${MINOR}" -ge 0 + test "${PATCH}" -ge 0 + BAZEL_MAJOR_VERSION="${MAJOR}" + BAZEL_MAJOR_MINOR_VERSION="${MAJOR}.${MINOR}" + BAZEL_MAJOR_MINOR_PATCH_VERSION="${MAJOR}.${MINOR}.${PATCH}" + BAZEL_VERSION="${BAZEL_MAJOR_MINOR_PATCH_VERSION}" + unset PREFIX MAJOR MINOR PATCH + # Copying Bazel run commands + VARIABLES="${VARIABLES-$[[inputs.variables]]}" + while IFS= read -r LINE; do + for VARIABLE in ${VARIABLES}; do if test -z ${!VARIABLE+x}; then - if test "${LINE/\$\{${VARIABLE}\}/}" != "${LINE}"; then - printf >&2 '\e[1;33mWarning:\e[0m `\e[1;35m%s\e[0m` is not available in the environment for run commands replacement: \e[1;35m%s\e[0m\n' "${VARIABLE}" "${LINE}" - fi - continue + if test "${LINE/\$\{${VARIABLE}\}/}" != "${LINE}"; then + printf >&2 '\e[1;33mWarning:\e[0m `\e[1;35m%s\e[0m` is not available in the environment for run commands replacement: \e[1;35m%s\e[0m\n' "${VARIABLE}" "${LINE}" + fi + continue fi LINE="${LINE//\$\{${VARIABLE}\}/${!VARIABLE}}" - done - printf '%s\n' "${LINE}" >> "${ROOT}/$[[inputs.dst]]" - done < "${ROOT}/$[[inputs.src]]" + done + printf '%s\n' "${LINE}" >> "${ROOT}/$[[inputs.dst]]" + done < "${ROOT}/$[[inputs.src]]" + done execute: - cd "${ROOT}"; "$[[inputs.bazelisk]]" "$[[inputs.command]]" "$[[inputs.target]]" testlogs: # https://gitlab.com/gitlab-org/gitlab/-/issues/19746 diff --git a/templates/ruleset/.job.yml b/templates/ruleset/.job.yml index 60479f5398f897838fd9e6222bc4b6351d416799..90b4cf95100aa0ce5632c20fca8385db360cdaf2 100644 --- a/templates/ruleset/.job.yml +++ b/templates/ruleset/.job.yml @@ -38,6 +38,10 @@ include: CI_COMMIT_SHA CI_SERVER_HOST CI_LOCKFILE_MODE + BAZEL_MAJOR_VERSION + BAZEL_MAJOR_MINOR_VERSION + BAZEL_MAJOR_MINOR_PATCH_VERSION + BAZEL_VERSION .job: extends: .bazelisk