Skip to content

Commit b338418

Browse files
authored
Running pre-commit in parallel (#216)
# Summary Running pre-commit commands in parallel to speed it up. To get the quickest run, execute it locally with skipping license check. Consider putting `export MDB_UPDATE_LICENSES=true` into your `private-context` to always enable generating licenses in pre-commit **Changes** - `make precommit` is no longer using EVERGREEN_MODE=true, and is skipping generating licenses by default - added `make precommit-with-licenses` for easier precommit with generating license step ## Proof of Work ### Benchmark Comparison | Scenario | Master Run | PR Run | Speedup | | :------------------------------- | :--------: | :-------: | :----------: | | **No Cache, With Licenses** | 47.519s | 31.897s | 1.49x faster | | **With Cache, With Licenses** | 24.382s | 17.291s | 1.41x faster | | **No Cache, Without Licenses** | 24.388s | 21.783s | 1.12x faster | | **With Cache, Without Licenses** | 8.229s | 4.463s | 1.84x faster | The table above is just a summary for the runs below. **No Go Cache, With Licenses, Master Run** ``` git co master Switched to branch 'master' Your branch is up to date with 'origin/master'. $ go clean -cache -modcache $ time make precommit-with-licenses 125.07s user 38.88s system 345% cpu 47.519 total ``` **With Go Cache, With Licenses, Master Run** ``` $ time make precommit-with-licenses 32.90s user 12.69s system 187% cpu 24.382 total ``` **No Go Cache, Without Licenses, Master Run** ``` # manually commented update_licenses script $ go clean -cache -modcache $ time make precommit 92.78s user 31.70s system 510% cpu 24.388 total ``` **With Go Cache, Without Licenses, Master Run** ``` # manually commented update_licenses script $ time make precommit 9.46s user 9.83s system 234% cpu 8.229 total ``` **No Go Cache, With Licenses, PR Run** ``` $ go clean -cache -modcache $ time make precommit-with-licenses 125.88s user 39.88s system 519% cpu 31.897 total ``` **With Go Cache, With Licenses, PR Run** ``` $ time make precommit-with-licenses 32.95s user 11.44s system 256% cpu 17.291 total ``` **No Go Cache, Without Licenses, PR Run** ``` $ go clean -cache -modcache $ time make precommit 92.61s user 32.05s system 572% cpu 21.783 total ``` **With Go Cache, Without Licenses, PR Run** ``` $ time make precommit 9.44s user 11.18s system 462% cpu 4.463 total ``` EVG actually running licenses as part of [check_precommit](https://parsley.mongodb.com/evergreen/mongodb_kubernetes_unit_tests_lint_repo_patch_74638f2a903e333cebf6e6f785f8eec7001c8452_6864fa46e1c4fa00071ac925_25_07_02_09_22_16/0/task?bookmarks=0%2C879&selectedLineRange=L854&shareLine=854): ``` [2025/07/02 11:26:08.685] update_licenses: update_licenses: Processing licenses for module: /data/mci/41a0c17df8b491653520d6aef7261120/src/github.com/mongodb/mongodb-kubernetes/public/tools/multicluster [2025/07/02 11:26:08.689] update_licenses: update_licenses: Processing licenses for module: /data/mci/41a0c17df8b491653520d6aef7261120/src/github.com/mongodb/mongodb-kubernetes [2025/07/02 11:27:09.129] update_licenses: update_licenses: License processing complete for all modules. ``` ## Checklist - [ ] Have you linked a jira ticket and/or is the ticket in the title? - [ ] Have you checked whether your jira ticket required DOCSP changes? - [ ] Have you checked for release_note changes? ## Reminder (Please remove this when merging) - Please try to Approve or Reject Changes the PR, keep PRs in review as short as possible - Our Short Guide for PRs: [Link](https://docs.google.com/document/d/1T93KUtdvONq43vfTfUt8l92uo4e4SEEvFbIEKOxGr44/edit?tab=t.0) - Remember the following Communication Standards - use comment prefixes for clarity: * **blocking**: Must be addressed before approval. * **follow-up**: Can be addressed in a later PR or ticket. * **q**: Clarifying question. * **nit**: Non-blocking suggestions. * **note**: Side-note, non-actionable. Example: Praise * --> no prefix is considered a question
1 parent 74638f2 commit b338418

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

.githooks/pre-commit

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -142,24 +142,27 @@ function check_incorrect_makefile_variable_brackets() {
142142
}
143143

144144
function pre_commit() {
145+
if [[ "${MDB_UPDATE_LICENSES:-""}" == "true" ]]; then
146+
( (time update_licenses) 2>&1 | prepend "update_licenses" ) &
147+
fi
148+
( (time scripts/evergreen/lint_code.sh) 2>&1 | prepend "lint_code.sh" ) &
149+
( (time start_shellcheck) 2>&1 | prepend "shellcheck" ) &
150+
145151
# Update release.json first in case there is a newer version
146152
(time update_release_json) 2>&1 | prepend "update_release_json"
147153
# We need to generate the values files first
148154
(time update_values_yaml_files) 2>&1 | prepend "update_values_yaml_files"
149155
# The values files are used for generating the standalone yaml
150156
(time generate_standalone_yaml) 2>&1 | prepend "generate_standalone_yaml"
151-
# Run black on python files that have changed
152-
(time python_formatting) 2>&1 | prepend "python_formatting"
153-
154-
(time regenerate_public_rbac_multi_cluster) 2>&1 | prepend "regenerate_public_rbac_multi_cluster"
155157

156-
(time start_shellcheck) 2>&1 | prepend "shellcheck"
158+
( (time regenerate_public_rbac_multi_cluster) 2>&1 | prepend "regenerate_public_rbac_multi_cluster" ) &
157159

158-
(time check_erroneous_kubebuilder_annotations) 2>&1 | prepend "check_erroneous_kubebuilder_annotations"
160+
# Run black and isort on python files that have changed
161+
( (time python_formatting) 2>&1 | prepend "python_formatting") &
159162

160-
(time scripts/evergreen/lint_code.sh) 2>&1 | prepend "lint_code.sh"
163+
( (time check_erroneous_kubebuilder_annotations) 2>&1 | prepend "check_erroneous_kubebuilder_annotations" ) &
161164

162-
(time update_licenses) 2>&1 | prepend "update_licenses"
165+
wait
163166
}
164167

165168
# Function to run shellcheck on a single file
@@ -196,7 +199,7 @@ if [[ "${cmd}" == "generate_standalone_yaml" ]]; then
196199
shift 1
197200
generate_standalone_yaml "$@"
198201
elif [[ "${cmd}" == "pre-commit" ]]; then
199-
pre_commit
202+
time pre_commit
200203
elif [[ "${cmd}" == "shellcheck" ]]; then
201204
start_shellcheck
202205
elif [[ "${cmd}" == "lint" ]]; then

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ prerequisites:
5757
@ scripts/dev/install.sh
5858

5959
precommit:
60-
@ EVERGREEN_MODE=true .githooks/pre-commit
60+
@ .githooks/pre-commit
61+
62+
precommit-with-licenses:
63+
@ MDB_UPDATE_LICENSE=true .githooks/pre-commit
6164

6265
switch:
6366
@ scripts/dev/switch_context.sh $(context) $(additional_override)

scripts/dev/contexts/evg-private-context

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,5 @@ export cognito_workload_federation_client_secret="${cognito_workload_federation_
120120
export cognito_user_password="${cognito_user_password}"
121121
export cognito_workload_url="${cognito_workload_url}"
122122
export cognito_workload_user_id="${cognito_workload_user_id}"
123+
124+
export MDB_UPDATE_LICENSES=true

scripts/dev/contexts/private-context-template

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,6 @@ export e2e_cloud_qa_user_owner_static_2="${OM_USER}"
9999

100100
# TODO to be removed at public preview stage of community-search
101101
export COMMUNITY_PRIVATE_PREVIEW_PULLSECRET_DOCKERCONFIGJSON="<dockerconfigjson secret>"
102+
103+
# uncomment to enable license update with pre-commit script
104+
# export MDB_UPDATE_LICENSES=true

0 commit comments

Comments
 (0)