Skip to content
Draft
Show file tree
Hide file tree
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
12 changes: 11 additions & 1 deletion .evergreen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,16 @@ tasks:
working_dir: src/github.com/mongodb/mongodb-kubernetes
binary: scripts/evergreen/precommit_bump.sh

- name: run_conditionally_precommit_and_push
tags: [ "patch-run" ]
commands:
- func: clone
- func: run_task_conditionally
vars:
condition_script: scripts/evergreen/should_run_precommit_and_push.sh
variant: run_pre_commit
task: run_precommit_and_push

- name: rebuild_all_agents
# this enables us to run this manually (patch) and rebuild all agent versions to verify
# Dockerfile, script changes etc.
Expand Down Expand Up @@ -1831,7 +1841,7 @@ buildvariants:
run_on:
- ubuntu2404-small
tasks:
- name: run_precommit_and_push
- name: run_conditionally_precommit_and_push

- name: init_tests_with_olm
display_name: init_tests_with_olm
Expand Down
44 changes: 44 additions & 0 deletions scripts/evergreen/should_run_precommit_and_push.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash

# This file is a condition script used for conditionally executing evergreen task for running precommit and pushing (run_precommit_and_push).
# It checks if the branch matches patterns that require auto-bump functionality.
# Exit code 0 means the task should run, exit code != 0 means it should be skipped.

set -Eeou pipefail
source scripts/dev/set_env_context.sh

ORIGINAL_BRANCH=""
# Detect the original branch (same commit, but not the evg-pr-test-* branch which evg creates)
ORIGINAL_BRANCH=$(git for-each-ref --format='%(refname:short) %(objectname)' refs/remotes/origin | grep "$(git rev-parse HEAD)" | grep -v "evg-pr-test-" | awk '{print $1}' | sed 's|^origin/||' | head -n 1 || true)

if [[ -z "${ORIGINAL_BRANCH}" ]]; then
echo "Fork: Could not determine the original branch. Skipping precommit_and_push task."
exit 1
fi
echo "Detected original branch: ${ORIGINAL_BRANCH}"

REQUIRED_PATTERNS=(
"^dependabot/"
"_version_bump$"
"^enterprise-operator-release-"
)

echo "Checking branch '${ORIGINAL_BRANCH}' against required patterns:"

MATCH_FOUND=false
for pattern in "${REQUIRED_PATTERNS[@]}"; do
if [[ "${ORIGINAL_BRANCH}" =~ ${pattern} ]]; then
MATCH_FOUND=true
echo "Match found: '${ORIGINAL_BRANCH}' matches pattern '${pattern}'"
break
fi
done

if [[ "${MATCH_FOUND}" == false ]]; then
echo "Branch '${ORIGINAL_BRANCH}' does not match any required patterns. Skipping precommit_and_push task."
printf " - %s\n" "${REQUIRED_PATTERNS[@]}"
exit 1
fi

echo "Branch matches required patterns. Precommit and push task should run."
exit 0