Skip to content

Commit 7d79371

Browse files
nammnfealebenpae
authored andcommitted
CLOUDP-267029 - auto bump on publish variants (#4147)
# Summary - adds a new variant that always runs - but it only pushes changes under certain circumstances as defined below - unpacking has been moved to `project/tmp` to ensure we don't commit them ## When to run the pre-commit hook and push changes - Dependabot: Branch starts with dependabot/ - Agent bump: Branch ends with _version_bump - Release: Branch starts with operator-release ## How - A new Task and variant that runs on every PR - Name: Pre-commit - Gets current branch - Runs: Pre-commit and pushes (only if changes are there) - Conditions when to do the commit and push: - Easy: Only when specific branch name, otherwise just cancel (implemented) - Better: create.tasks based on above information ## Proof of Work ### Pre-Commit skipped - https://spruce.mongodb.com/task/ops_manager_kubernetes_run_pre_commit_run_precommit_and_push_patch_1706841847f03ed296470183d275f66ac908295f_67c81c321a5ca40007e2985d_25_03_05_09_41_11/logs?execution=0 ### Pre-Commit not skipped - dependabot: 10gen/ops-manager-kubernetes#4151 ``` [2025/03/05 11:22:36.503] To https://github.com/10gen/ops-manager-kubernetes.git [2025/03/05 11:22:36.503] fd8d787e1..4ef668655 dependabot/go_modules/golang.org/x/crypto-0.35.0 -> dependabot/go_modules/golang.org/x/crypto-0.35.0 [2025/03/05 11:22:36.506] finished ``` ![Screenshot 2025-03-05 at 11 31 36](https://github.com/user-attachments/assets/b19eea8b-baa9-46f0-9c15-7f65a778a985) - after the commit it runs again in the next commit, but will be skipped because no changes are staged: https://spruce.mongodb.com/version/67c83cb67e26fb0007bb9a23/tasks?variant=^run_pre_commit$ ## Checklist - [x] Have you linked a jira ticket and/or is the ticket in the title? - [x] Have you checked whether your jira ticket required DOCSP changes? - [x] Have you checked for release_note changes?
1 parent 3afb1b1 commit 7d79371

File tree

7 files changed

+106
-14
lines changed

7 files changed

+106
-14
lines changed

.evergreen.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ github_pr_aliases:
194194
task_tags: [ "unit_tests" ]
195195
- variant_tags: [ "e2e_test_suite" ]
196196
task_tags: [ "patch-run" ]
197+
- variant_tags: [ "auto_bump" ]
198+
task_tags: [ "patch-run" ]
197199

198200
# Allows to see evergreen checks in GitHub commits
199201
# https://github.com/10gen/ops-manager-kubernetes/commits/master/
@@ -316,6 +318,24 @@ tasks:
316318
image_name: agent-pct
317319
include_tags: release
318320

321+
- name: run_precommit_and_push
322+
tags: ["patch-run"]
323+
commands:
324+
- func: clone
325+
- func: python_venv
326+
- func: download_kube_tools
327+
- func: setup_shellcheck
328+
- command: github.generate_token
329+
params:
330+
expansion_name: GH_TOKEN
331+
- command: subprocess.exec
332+
type: setup
333+
params:
334+
include_expansions_in_env:
335+
- GH_TOKEN
336+
working_dir: src/github.com/10gen/ops-manager-kubernetes
337+
binary: scripts/evergreen/precommit_bump.sh
338+
319339
# Pct only triggers this variant once a new agent image is out
320340
# these releases the agent with the operator suffix (not patch id) on ecr to allow for digest pinning to pass.
321341
# For this to work, we rely on skip_tags which is used to determine whether
@@ -1510,6 +1530,16 @@ buildvariants:
15101530
tasks:
15111531
- name: release_agents_on_ecr_conditional
15121532

1533+
- name: run_pre_commit
1534+
priority: 70
1535+
display_name: run_pre_commit
1536+
allowed_requesters: [ "patch", "github_pr" ]
1537+
tags: [ "auto_bump" ]
1538+
run_on:
1539+
- ubuntu2204-small
1540+
tasks:
1541+
- name: run_precommit_and_push
1542+
15131543
- name: init_tests_with_olm
15141544
display_name: init_tests_with_olm
15151545
depends_on:

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ cache
2121
**/env*/
2222
*.bak
2323
**/pytest_cache/
24+
tmp/*
2425
bin/*
2526
**/*.iml
2627
helm_out
@@ -89,3 +90,4 @@ docker/mongodb-enterprise-tests/.test_identifiers*
8990

9091
logs-debug/
9192
/ssdlc-report/*
93+
.gocache/

docker/mongodb-enterprise-tests/kubetester/omtester.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,7 @@ def should_include_tag(version: Optional[Dict[str, str]]) -> bool:
769769
Manager.
770770
771771
"""
772+
772773
feature_controls_enabled_version = "4.2.2"
773774
if version is None:
774775
return True

scripts/evergreen/precommit_bump.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env bash
2+
3+
set -Eeou pipefail
4+
source scripts/dev/set_env_context.sh
5+
6+
export GOLANGCI_LINT_CACHE="${HOME}/.cache/golangci-lint"
7+
8+
# Detect the original branch (same commit, but not the evg-pr-test-* branch which evg creates)
9+
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)
10+
11+
if [[ -z "${ORIGINAL_BRANCH}" ]]; then
12+
echo "Error: Could not determine the original branch."
13+
exit 1
14+
fi
15+
echo "Detected original branch: ${ORIGINAL_BRANCH}"
16+
17+
REQUIRED_PATTERNS=(
18+
"^dependabot/"
19+
"_version_bump$"
20+
"^enterprise-operator-release-"
21+
)
22+
23+
echo "Checking branch '${ORIGINAL_BRANCH}' against required patterns:"
24+
25+
MATCH_FOUND=false
26+
for pattern in "${REQUIRED_PATTERNS[@]}"; do
27+
if [[ "${ORIGINAL_BRANCH}" =~ ${pattern} ]]; then
28+
MATCH_FOUND=true
29+
echo "✅ Match found: '${ORIGINAL_BRANCH}' matches pattern '${pattern}'"
30+
break
31+
fi
32+
done
33+
34+
if [[ "${MATCH_FOUND}" == false ]]; then
35+
echo "❌ Branch '${ORIGINAL_BRANCH}' does not match any required patterns. Exiting."
36+
printf " - %s\n" "${REQUIRED_PATTERNS[@]}"
37+
exit 0
38+
fi
39+
40+
echo "Detected a branch that should be bumped."
41+
42+
git checkout "${ORIGINAL_BRANCH}"
43+
44+
EVERGREEN_MODE=true .githooks/pre-commit
45+
46+
git add .
47+
48+
if [[ -z $(git diff --name-only --cached) ]]; then
49+
echo "No staged changes to commit. Exiting."
50+
exit 0
51+
fi
52+
53+
git commit -m "Run pre-commit hook"
54+
git remote set-url origin https://x-access-token:"${GH_TOKEN}"@github.com/10gen/ops-manager-kubernetes.git
55+
56+
echo "changes detected, pushing them"
57+
git push origin "${ORIGINAL_BRANCH}"

scripts/evergreen/retry-evergreen.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ EVERGREEN_API="https://evergreen.mongodb.com/api"
3838
MAX_RETRIES="${EVERGREEN_MAX_RETRIES:-3}"
3939

4040
# shellcheck disable=SC2207
41-
BUILD_IDS=($(curl -s -H "Api-User: ${EVERGREEN_USER}" -H "Api-Key: ${EVERGREEN_API_KEY}" ${EVERGREEN_API}/rest/v2/versions/"${VERSION}" | jq -r '.build_variants_status[] | select(.build_variant!="unit_tests") | .build_id'))
41+
BUILD_IDS=($(curl -s -H "Api-User: ${EVERGREEN_USER}" -H "Api-Key: ${EVERGREEN_API_KEY}" ${EVERGREEN_API}/rest/v2/versions/"${VERSION}" | jq -r '.build_variants_status[] | select(.build_variant != "unit_tests" and .build_variant != "run_pre_commit") | .build_id'))
4242

4343
for BUILD_ID in "${BUILD_IDS[@]}"; do
4444
echo "Finding failed tasks in BUILD ID: ${BUILD_ID}"

scripts/evergreen/setup_kubectl.sh

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ set -Eeou pipefail
44
source scripts/dev/set_env_context.sh
55

66
bindir="${PROJECT_DIR}/bin"
7-
mkdir -p "${bindir}"
7+
tmpdir="${PROJECT_DIR}/tmp"
8+
mkdir -p "${bindir}" "${tmpdir}"
89

910
echo "Downloading latest kubectl"
1011
curl -s --retry 3 -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
@@ -14,9 +15,9 @@ echo "kubectl version --client"
1415
mv kubectl "${bindir}"
1516

1617
echo "Downloading helm"
17-
helm=helm.tgz
18-
helm_version="v3.13.0"
19-
curl -s https://get.helm.sh/helm-${helm_version}-linux-amd64.tar.gz --output "${helm}"
20-
tar xfz "${helm}" &> /dev/null
21-
mv linux-amd64/helm "${bindir}"
22-
rm "${helm}"
18+
helm_archive="${tmpdir}/helm.tgz"
19+
helm_version="v3.17.1"
20+
curl -s https://get.helm.sh/helm-${helm_version}-linux-amd64.tar.gz --output "${helm_archive}"
21+
22+
tar xfz "${helm_archive}" -C "${tmpdir}" &> /dev/null
23+
mv "${tmpdir}/linux-amd64/helm" "${bindir}"

scripts/evergreen/setup_shellcheck.sh

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ set -Eeou pipefail
44
source scripts/dev/set_env_context.sh
55

66
bindir="${PROJECT_DIR:?}/bin"
7-
mkdir -p "${PROJECT_DIR}/bin/"
7+
tmpdir="${PROJECT_DIR:?}/tmp"
8+
mkdir -p "${bindir}" "${tmpdir}"
89

910
echo "Downloading shellcheck"
10-
shellcheck=shellcheck.tar.xz
11+
shellcheck_archive="${tmpdir}/shellcheck.tar.xz"
1112
shellcheck_version="v0.9.0"
12-
curl --retry 3 --silent -L "https://github.com/koalaman/shellcheck/releases/download/${shellcheck_version}/shellcheck-${shellcheck_version}.linux.x86_64.tar.xz" -o ${shellcheck}
13-
tar xf "${shellcheck}"
14-
mv shellcheck-"${shellcheck_version}"/shellcheck "${bindir}"
15-
rm "${shellcheck}"
13+
curl --retry 3 --silent -L "https://github.com/koalaman/shellcheck/releases/download/${shellcheck_version}/shellcheck-${shellcheck_version}.linux.x86_64.tar.xz" -o "${shellcheck_archive}"
14+
tar -xf "${shellcheck_archive}" -C "${tmpdir}"
15+
mv "${tmpdir}/shellcheck-${shellcheck_version}/shellcheck" "${bindir}"
16+
rm "${shellcheck_archive}"

0 commit comments

Comments
 (0)