Skip to content

Fix master builds #331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Aug 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions scripts/release/build_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,36 @@ class BuildScenario(str, Enum):
@classmethod
def infer_scenario_from_environment(cls) -> "BuildScenario":
"""Infer the build scenario from environment variables."""
# triggered_by_git_tag is the name of the tag that triggered this version, if applicable. It will be None for
# all patches except when tagging a commit on GitHub
git_tag = os.getenv("triggered_by_git_tag")
# is_patch is passed automatically by Evergreen.
# It is "true" if the running task is in a patch build and undefined if it is not.
# A patch build is a version not triggered by a commit to a repository.
# It either runs tasks on a base commit plus some diff if submitted by the CLI or on a git branch if created by
# a GitHub pull request.
is_patch = os.getenv("is_patch", "false").lower() == "true"
# RUNNING_IN_EVG is set by us in evg-private-context
is_evg = os.getenv("RUNNING_IN_EVG", "false").lower() == "true"
# version_id is the id of the task's version. It is generated automatically for each task run.
# For example: `6899b7e35bfaee00077db986` for a manual/PR patch,
# or `mongodb_kubernetes_5c5a3accb47bb411682b8c67f225b61f7ad5a619` for a master merge
patch_id = os.getenv("version_id")

logger.debug(
f"Collected environment variables: git tag {git_tag}, is_patch {is_patch}, is_evg {is_evg}, patch_id {patch_id}"
)

if git_tag:
# Release scenario and the git tag will be used for promotion process only
scenario = BuildScenario.RELEASE
logger.info(f"Build scenario: {scenario} (git_tag: {git_tag})")
logger.info(f"Build scenario: {scenario}, git_tag: {git_tag}")
elif is_patch:
scenario = BuildScenario.PATCH
logger.info(f"Build scenario: {scenario} (patch_id: {patch_id})")
logger.info(f"Build scenario: {scenario}, patch_id: {patch_id}")
elif is_evg:
scenario = BuildScenario.STAGING
logger.info(f"Build scenario: {scenario} (patch_id: {patch_id})")
logger.info(f"Build scenario: {scenario}, patch_id: {patch_id}")
else:
scenario = BuildScenario.DEVELOPMENT
logger.info(f"Build scenario: {scenario}")
Expand Down Expand Up @@ -70,11 +85,15 @@ def get_version(self) -> str:
if self.scenario == BuildScenario.RELEASE:
return self.git_tag
if self.scenario == BuildScenario.STAGING:
# On master merges, always use "latest" (preserving legacy behavior)
return "latest"
# On master merges, we need to build images with the patch_id as they are expected by tests. Later on,
# we will use commit SHA. Optionally, we may want to continue pushing to ECR registry with "latest", for
# local dev purposes.
return self.patch_id
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment is not valid anymore, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct, good catch
Fixed

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whole version calculation based on variables will be soon extracted outside of build_context and pipeline in general. It is not a proper place and it hides a lot of details

if self.patch_id:
return self.patch_id
# Alternatively, we can fail here if no ID is explicitly defined
# When working locally, "version_id" env variable is defined in the generated context file. It is "latest" by
# default, and can be overridden with OVERRIDE_VERSION_ID
return "latest"

def get_base_registry(self) -> str:
Expand Down