Skip to content

Commit 2b49974

Browse files
committed
Running conditionally precommit_and_push job
1 parent 13cf357 commit 2b49974

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

.evergreen.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,16 @@ tasks:
335335
working_dir: src/github.com/mongodb/mongodb-kubernetes
336336
binary: scripts/evergreen/precommit_bump.sh
337337

338+
- name: run_conditionally_precommit_and_push
339+
tags: [ "patch-run" ]
340+
commands:
341+
- func: clone
342+
- func: run_task_conditionally
343+
vars:
344+
condition_script: scripts/evergreen/should_run_precommit_and_push.sh
345+
variant: run_pre_commit
346+
task: run_precommit_and_push
347+
338348
- name: rebuild_all_agents
339349
# this enables us to run this manually (patch) and rebuild all agent versions to verify
340350
# Dockerfile, script changes etc.
@@ -1831,7 +1841,7 @@ buildvariants:
18311841
run_on:
18321842
- ubuntu2404-small
18331843
tasks:
1834-
- name: run_precommit_and_push
1844+
- name: run_conditionally_precommit_and_push
18351845

18361846
- name: init_tests_with_olm
18371847
display_name: init_tests_with_olm
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env bash
2+
3+
# This file is a condition script used for conditionally executing evergreen task for running precommit and pushing (run_precommit_and_push).
4+
# It checks if the branch matches patterns that require auto-bump functionality.
5+
# Exit code 0 means the task should run, exit code != 0 means it should be skipped.
6+
7+
set -Eeou pipefail
8+
source scripts/dev/set_env_context.sh
9+
10+
ORIGINAL_BRANCH=""
11+
# Detect the original branch (same commit, but not the evg-pr-test-* branch which evg creates)
12+
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)
13+
14+
if [[ -z "${ORIGINAL_BRANCH}" ]]; then
15+
echo "Fork: Could not determine the original branch. Skipping precommit_and_push task."
16+
exit 1
17+
fi
18+
echo "Detected original branch: ${ORIGINAL_BRANCH}"
19+
20+
REQUIRED_PATTERNS=(
21+
"^dependabot/"
22+
"_version_bump$"
23+
"^enterprise-operator-release-"
24+
)
25+
26+
echo "Checking branch '${ORIGINAL_BRANCH}' against required patterns:"
27+
28+
MATCH_FOUND=false
29+
for pattern in "${REQUIRED_PATTERNS[@]}"; do
30+
if [[ "${ORIGINAL_BRANCH}" =~ ${pattern} ]]; then
31+
MATCH_FOUND=true
32+
echo "Match found: '${ORIGINAL_BRANCH}' matches pattern '${pattern}'"
33+
break
34+
fi
35+
done
36+
37+
if [[ "${MATCH_FOUND}" == false ]]; then
38+
echo "Branch '${ORIGINAL_BRANCH}' does not match any required patterns. Skipping precommit_and_push task."
39+
printf " - %s\n" "${REQUIRED_PATTERNS[@]}"
40+
exit 1
41+
fi
42+
43+
echo "Branch matches required patterns. Precommit and push task should run."
44+
exit 0

0 commit comments

Comments
 (0)