From aef13e05842fbabf6af262d019c85b7d61d9ceda Mon Sep 17 00:00:00 2001 From: Zack Winter <3457246+zackwintermdb@users.noreply.github.com> Date: Tue, 28 Apr 2026 16:20:06 -0700 Subject: [PATCH] SERVER-120949: Remove Tag Based FCV Generation (#49061) GitOrigin-RevId: 71d11d29d6e9077edbedf4a95bc6b1977666d358 --- .bazelrc | 9 ++++-- .bazelrc.target_mongo_version | 4 +++ .../write_wrapper_hook_bazelrc.py | 8 ----- .../resmokelib/multiversionconstants.py | 29 ++++++++++++++----- buildscripts/utils.py | 13 --------- docs/evergreen-testing/multiversion.md | 4 +-- evergreen/bazel_evergreen_shutils.sh | 4 ++- evergreen/fcv_test_git_tag.sh | 8 ++--- .../functions/version_expansions_generate.sh | 24 +++++++++++++-- evergreen/generate_evergreen_bazelrc.sh | 10 +++++-- evergreen/papertrail_generate_expansions.sh | 9 +++++- .../db/repl/FCV_AND_FEATURE_FLAG_README.md | 14 ++++----- 12 files changed, 84 insertions(+), 52 deletions(-) create mode 100644 .bazelrc.target_mongo_version diff --git a/.bazelrc b/.bazelrc index 5a18815f546..4418b2fc3af 100644 --- a/.bazelrc +++ b/.bazelrc @@ -660,9 +660,6 @@ try-import %workspace%/.bazelrc.common_bes # Settings unconditionally written by the wrapper hook try-import %workspace%/.bazelrc.wrapper_hook -# local git version info -try-import %workspace%/.bazelrc.git - # Used for build profiles and any settings a user wants to consistently use try-import %workspace%/.bazelrc.local @@ -678,6 +675,12 @@ try-import %workspace%/.bazelrc.engflow_creds # Flags for fuzztest try-import %workspace%/.bazelrc.fuzztest +# Default mongo version +try-import %workspace%/.bazelrc.target_mongo_version + +# local git version info (after target_mongo_version so its MONGO_VERSION override wins) +try-import %workspace%/.bazelrc.git + # Repository root absolute path to set --execution_log_compact_file #try-import %workspace%/.bazelrc.exec_log_file diff --git a/.bazelrc.target_mongo_version b/.bazelrc.target_mongo_version new file mode 100644 index 00000000000..023e229f859 --- /dev/null +++ b/.bazelrc.target_mongo_version @@ -0,0 +1,4 @@ +# Default Mongo Version if a version is not specified. This should point at the next release version +# that master branch is targeting. The Server Triage and Release (STAR) team will upgrade this +# version on the master branch after every release. +common --define=MONGO_VERSION=9.0.0-alpha0 diff --git a/bazel/wrapper_hook/write_wrapper_hook_bazelrc.py b/bazel/wrapper_hook/write_wrapper_hook_bazelrc.py index e0f156e5e9c..57374559aab 100644 --- a/bazel/wrapper_hook/write_wrapper_hook_bazelrc.py +++ b/bazel/wrapper_hook/write_wrapper_hook_bazelrc.py @@ -2,7 +2,6 @@ import hashlib import os import pathlib import platform -import subprocess import sys ARCH_NORMALIZE_MAP = { @@ -23,13 +22,7 @@ def get_mongo_arch(args): return arch -def get_mongo_version(args): - proc = subprocess.run(["git", "describe", "--abbrev=0"], capture_output=True, text=True) - return proc.stdout.strip()[1:] - - def write_wrapper_hook_bazelrc(args): - mongo_version = get_mongo_version(args) mongo_arch = get_mongo_arch(args) python = sys.executable @@ -50,7 +43,6 @@ def write_wrapper_hook_bazelrc(args): bazelrc_contents = f""" common --define=MONGO_ARCH={mongo_arch} -common --define=MONGO_VERSION={mongo_version} build --workspace_status_command="{python} {workspace_status}" """ diff --git a/buildscripts/resmokelib/multiversionconstants.py b/buildscripts/resmokelib/multiversionconstants.py index 447589a738e..8885e0a08ff 100644 --- a/buildscripts/resmokelib/multiversionconstants.py +++ b/buildscripts/resmokelib/multiversionconstants.py @@ -4,7 +4,7 @@ import glob import http import os import shutil -from subprocess import DEVNULL, STDOUT, CalledProcessError, call, check_output +from subprocess import DEVNULL, STDOUT, call, check_output import requests import structlog @@ -35,18 +35,31 @@ MASTER_RELEASES_REMOTE_FILE = ( LOGGER = structlog.getLogger(__name__) +BAZELRC_DEFAULT_MONGO_VERSION = ".bazelrc.target_mongo_version" + + def generate_mongo_version_file(): """Generate the mongo version data file. Should only be called in the root of the mongo directory.""" + # Read the MONGO_VERSION from .bazelrc.target_mongo_version + # The file contains a line like: common --define=MONGO_VERSION=8.2.2 try: - res = check_output("git describe", shell=True, text=True) - except CalledProcessError as exp: - raise ChildProcessError("Failed to run git describe to get the latest tag") from exp + with open(BAZELRC_DEFAULT_MONGO_VERSION, "r") as f: + for line in f: + if "MONGO_VERSION=" in line: + # Extract the version after "MONGO_VERSION=" + version = line.split("MONGO_VERSION=")[1].strip() + break + else: + raise ValueError(f"MONGO_VERSION not found in {BAZELRC_DEFAULT_MONGO_VERSION}") + except FileNotFoundError as exp: + raise FileNotFoundError( + f"Failed to read version from {BAZELRC_DEFAULT_MONGO_VERSION}" + ) from exp # Write the current MONGO_VERSION to a data file. - with open(_config.MONGO_VERSION_FILE, "w") as mongo_version_fh: - # E.g. res = 'r5.1.0-alpha-597-g8c345c6693\n' - res = res[1:] # Remove the leading "r" character. - mongo_version_fh.write("mongo_version: " + res) + with open(_config.MONGO_VERSION_FILE, "w", encoding="utf-8") as mongo_version_fh: + # E.g. version = '8.2.2' + mongo_version_fh.write("mongo_version: " + version + "\n") @retry(tries=5, delay=3) diff --git a/buildscripts/utils.py b/buildscripts/utils.py index e0284a6f6cd..52a51a36aeb 100644 --- a/buildscripts/utils.py +++ b/buildscripts/utils.py @@ -53,19 +53,6 @@ def get_git_version(): return open(git_ver, "r").read().strip() -def get_git_describe(): - """Return 'git describe --abbrev=7'.""" - with open(os.devnull, "r+") as devnull: - proc = subprocess.Popen( - "git describe --abbrev=7", - stdout=subprocess.PIPE, - stderr=devnull, - stdin=devnull, - shell=True, - ) - return proc.communicate()[0].strip().decode("utf-8") - - def execsys(args): """Execute a subprocess of 'args'.""" if isinstance(args, str): diff --git a/docs/evergreen-testing/multiversion.md b/docs/evergreen-testing/multiversion.md index 5ee5888e3f8..e17af2f2e4b 100644 --- a/docs/evergreen-testing/multiversion.md +++ b/docs/evergreen-testing/multiversion.md @@ -40,8 +40,8 @@ For some of the versions we are using such generic names as `latest`, `last-lts` - `last-continuous` - the latest Rapid release version. In Evergreen, the version that was downloaded from the Rapid release branch project. It resolves to the entry in `featureCompatibilityVersions` of [releases.yml](../../src/mongo/util/version/releases.yml) that - looks older than the output of `git describe`. Will not be tested against if it is listed in - `eolVersions` as being end of life. + looks older than the version specified in `.bazelrc.target_mongo_version`. Will not be tested + against if it is listed in `eolVersions` as being end of life. Note: The latest release.yml file from master is always used, even fetched remotely when on another branch. diff --git a/evergreen/bazel_evergreen_shutils.sh b/evergreen/bazel_evergreen_shutils.sh index e969261ac4b..385ff9b5fb0 100644 --- a/evergreen/bazel_evergreen_shutils.sh +++ b/evergreen/bazel_evergreen_shutils.sh @@ -126,7 +126,9 @@ bazel_evergreen_shutils::extract_config_flags() { # Adds --config=public-release-rbe or --config=public-release-local if this is a release-ish build. bazel_evergreen_shutils::maybe_release_flag() { local local_arg="$1" - if [[ "${release_rbe:-}" == "true" ]]; then + if [[ -n "${MONGO_VERSION_OVERRIDE:-}" ]]; then + echo "$local_arg --config=public-release" + elif [[ "${release_rbe:-}" == "true" ]]; then echo "$local_arg --config=public-release-rbe" # release with RBE (Remote Build Execution) elif [[ "${is_patch:-}" == "true" || -z "${push_bucket:-}" || "${compiling_for_test:-}" == "true" ]]; then echo "$local_arg" # non-release diff --git a/evergreen/fcv_test_git_tag.sh b/evergreen/fcv_test_git_tag.sh index aff686e4e82..0155aab8500 100644 --- a/evergreen/fcv_test_git_tag.sh +++ b/evergreen/fcv_test_git_tag.sh @@ -1,13 +1,11 @@ #!/bin/bash # For FCV testing only. -# Tag the local branch with the new tag before running tests. +# Output the version from .bazelrc.target_mongo_version before running tests. set -o errexit set -o verbose cd src -git config user.name "Evergreen patch build" -git config user.email "evergreen@mongodb.com" -git tag -a r5.1.0-alpha -m 5.1.0-alpha -git describe +echo "common --define=MONGO_VERSION=5.1.0-alpha" >.bazelrc.target_mongo_version +echo "r$(grep -oP '(?<=MONGO_VERSION=)[^\s]+' .bazelrc.target_mongo_version)" diff --git a/evergreen/functions/version_expansions_generate.sh b/evergreen/functions/version_expansions_generate.sh index 0fa1180b11c..48615ce0192 100755 --- a/evergreen/functions/version_expansions_generate.sh +++ b/evergreen/functions/version_expansions_generate.sh @@ -5,8 +5,9 @@ cd src set -o errexit set -o verbose -# We get the raw version string (r1.2.3-45-gabcdef) from git -MONGO_VERSION=$(git describe --abbrev=7) + +# Extract version from .bazelrc.target_mongo_version (e.g., "common --define=MONGO_VERSION=8.3.0-rc1003") +MONGO_VERSION="r$(grep -oP '(?<=MONGO_VERSION=)[^\s]+' .bazelrc.target_mongo_version)" # If the project is sys-perf (or related), add the string -sys-perf to the version if [[ "${project}" == sys-perf* ]]; then @@ -18,6 +19,25 @@ fi if [ "${is_patch}" = "true" ]; then MONGO_VERSION="$MONGO_VERSION-patch-${version_id}" fi + +# Forcefully override the version for purposes of testing against a different version than the +# branch is targeting. +# +# This disables all remote caching, since we're bypassing the check above that would mark the +# build as a development build. +# +# Artifacts from runs with this enabled still should not be used for a final (non-rc) public release +# unless the associated `test_packages` task has completed successfully. +if [[ -n "${MONGO_VERSION_OVERRIDE}" ]]; then + MONGO_VERSION="${MONGO_VERSION_OVERRIDE}" +fi + +# For commit builds, append the last 8 characters of the git revision to the version string. +if [[ "${requester}" == "commit" ]]; then + GIT_REV=$(git rev-parse HEAD) + MONGO_VERSION="${MONGO_VERSION}-${GIT_REV: -8}" +fi + echo "MONGO_VERSION = ${MONGO_VERSION}" activate_venv diff --git a/evergreen/generate_evergreen_bazelrc.sh b/evergreen/generate_evergreen_bazelrc.sh index e42fd8665ce..f06fcf36894 100644 --- a/evergreen/generate_evergreen_bazelrc.sh +++ b/evergreen/generate_evergreen_bazelrc.sh @@ -26,11 +26,17 @@ if [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "win32" ]]; then echo "common --action_env=TMP=Z:/b" >>.bazelrc.evergreen echo "common --action_env=TEMP=Z:/b" >>.bazelrc.evergreen echo "BAZELISK_HOME=${abs_path}/bazelisk_home" >>.bazeliskrc - echo "common --define GIT_COMMIT_HASH=$(git rev-parse HEAD)" >>.bazelrc.git + GIT_REV=$(git rev-parse HEAD) + echo "common --define GIT_COMMIT_HASH=${GIT_REV}" >>.bazelrc.git else echo "startup --output_user_root=${TMPDIR}/bazel-output-root" >.bazelrc.evergreen echo "BAZELISK_HOME=${TMPDIR}/bazelisk_home" >>.bazeliskrc - echo "common --define GIT_COMMIT_HASH=$(git rev-parse HEAD)" >>.bazelrc.git + GIT_REV=$(git rev-parse HEAD) + echo "common --define GIT_COMMIT_HASH=${GIT_REV}" >>.bazelrc.git +fi + +if [[ "${requester}" == "commit" ]]; then + echo "common --define MONGO_VERSION=$(grep -oP 'MONGO_VERSION=\K.*' .bazelrc.target_mongo_version)-${GIT_REV: -8}" >>.bazelrc.git fi if [[ "${evergreen_remote_exec}" != "on" ]]; then diff --git a/evergreen/papertrail_generate_expansions.sh b/evergreen/papertrail_generate_expansions.sh index 1215aea7d9b..eec77a96fdf 100755 --- a/evergreen/papertrail_generate_expansions.sh +++ b/evergreen/papertrail_generate_expansions.sh @@ -3,7 +3,14 @@ cd src set -o errexit set -o verbose -version=$(git describe --tags --always --dirty) +# Extract version from .bazelrc.target_mongo_version (e.g., "common --define=MONGO_VERSION=8.2.2") +version="r$(grep -oP '(?<=MONGO_VERSION=)[^\s]+' .bazelrc.target_mongo_version)" + +# For commit builds, append the last 8 characters of the git revision to the version string. +if [[ "${requester:-}" == "commit" ]]; then + GIT_REV=$(git rev-parse HEAD) + version="${version}-${GIT_REV: -8}" +fi if [ ${IS_RELEASE} = 'true' ]; then version="${version#r}" diff --git a/src/mongo/db/repl/FCV_AND_FEATURE_FLAG_README.md b/src/mongo/db/repl/FCV_AND_FEATURE_FLAG_README.md index c2069be56d7..c8730a7ba2b 100644 --- a/src/mongo/db/repl/FCV_AND_FEATURE_FLAG_README.md +++ b/src/mongo/db/repl/FCV_AND_FEATURE_FLAG_README.md @@ -642,14 +642,14 @@ The logic for determining our generic FCVs is: ## Branch Cut and Upgrading FCVs -Since the FCV generation logic is entirely dependent on the git tag, the Server Triage and Release -(STAR) team will upgrade the git tag on the master branch after every release. When this happens, to -correctly build mongo after every release, developers will need to pull the new git tag. +Since the FCV generation logic is entirely dependent on the version specified in +`.bazelrc.target_mongo_version`, the Server Triage and Release (STAR) team will upgrade this version +on the master branch after every release. When this happens, to correctly build mongo after every +release, developers will need to pull the new git tag. -This can be done by using the `--tags` option (i.e., running `git fetch --tags`) after the STAR team -has introduced the new git tag. Developers may also see what their latest git tag is by running -`git describe`. After fetching the latest git tag, it will be necessary to recompile so that the new -`releases.h` file can be generated. +Developers may see what the current version is by checking `.bazelrc.target_mongo_version`. After +pulling the latest version changes, it will be necessary to recompile so that the new `releases.h` +file can be generated. # Feature Flags