summaryrefslogtreecommitdiff
path: root/buildscripts/feature_flag_tags_check.py
diff options
context:
space:
mode:
authorMikhail Shchatko <mikhail.shchatko@mongodb.com>2021-08-06 10:30:58 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-08-09 07:39:25 +0000
commitc86c0d8ce815f8119d2483c6f744be6691aa1e6f (patch)
tree5bd3ea85df9b9a48b67e3f4a33263e687e9152eb /buildscripts/feature_flag_tags_check.py
parent55c6be83b023eb011931166c3e09d5823f628296 (diff)
downloadmongo-c86c0d8ce815f8119d2483c6f744be6691aa1e6f.tar.gz
SERVER-58793 Update check_feature_flag_tags task to use git diff and git apply
Diffstat (limited to 'buildscripts/feature_flag_tags_check.py')
-rwxr-xr-xbuildscripts/feature_flag_tags_check.py55
1 files changed, 30 insertions, 25 deletions
diff --git a/buildscripts/feature_flag_tags_check.py b/buildscripts/feature_flag_tags_check.py
index 6142e658eab..fe3bed82cb1 100755
--- a/buildscripts/feature_flag_tags_check.py
+++ b/buildscripts/feature_flag_tags_check.py
@@ -5,6 +5,7 @@ Check that on changing feature flag from disabled to enabled by default in all j
had that feature flag in tags there is a tag that requires the latest FCV.
"""
+import argparse
import os
import subprocess
import sys
@@ -15,31 +16,25 @@ if __name__ == "__main__" and __package__ is None:
# pylint: disable=wrong-import-position
from buildscripts.resmokelib import selector
-from buildscripts.resmokelib.multiversionconstants import LATEST_FCV
+from buildscripts.resmokelib.multiversionconstants import REQUIRES_FCV_TAG_LATEST
from buildscripts.resmokelib.utils import jscomment
-REQUIRES_FCV_TAG = f"requires_fcv_{LATEST_FCV}".replace(".", "")
-ENTERPRISE_DIR = "src/mongo/db/modules/enterprise"
+def _run_git_cmd(cmd_args, cwd=None, silent=True):
+ """Run git command."""
+ run_args = {}
+ if cwd:
+ run_args["cwd"] = cwd
+ if silent:
+ run_args["stdout"] = subprocess.DEVNULL
+ run_args["stderr"] = subprocess.DEVNULL
+ subprocess.run(["git"] + cmd_args, **run_args, check=False)
-def _run_git_stash_cmd(args, cwd=None):
- """Run git stash command."""
- git_cmd = ["git", "stash"] + args
- proc = subprocess.Popen(git_cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=cwd)
- proc.communicate()
-
-def _git_stash(args):
- """Run git stash command in he current and enterprise directory."""
- _run_git_stash_cmd(args)
- if os.path.isdir(ENTERPRISE_DIR):
- _run_git_stash_cmd(args, cwd=ENTERPRISE_DIR)
-
-
-def get_tests_with_feature_flag_tags(feature_flags):
+def get_tests_with_feature_flag_tags(feature_flags, ent_path):
"""Get the list of tests with feature flag tag."""
selector_config = {
- "roots": ["jstests/**/*.js", f"{ENTERPRISE_DIR}/jstests/**/*.js"],
+ "roots": ["jstests/**/*.js", f"{ent_path}/jstests/**/*.js"],
"include_with_any_tags": feature_flags,
}
tests, _ = selector.filter_tests("js_test", selector_config)
@@ -55,12 +50,12 @@ def get_tests_missing_fcv_tag(tests):
except FileNotFoundError:
continue
else:
- if REQUIRES_FCV_TAG not in test_tags:
+ if REQUIRES_FCV_TAG_LATEST not in test_tags:
found_tests.append(test)
return found_tests
-def main():
+def main(diff_file, ent_path):
"""Run the main function."""
with open("base_all_feature_flags.txt", "r") as fh:
base_feature_flags = fh.read().split()
@@ -69,18 +64,28 @@ def main():
enabled_feature_flags = [flag for flag in base_feature_flags if flag not in patch_feature_flags]
if not enabled_feature_flags:
+ print(
+ "No feature flags were enabled by default in this patch/commit; skipping feature flag checks"
+ )
sys.exit(0)
- _git_stash(["--", "jstests"])
- tests_with_feature_flag_tag = get_tests_with_feature_flag_tags(enabled_feature_flags)
- _git_stash(["pop"])
+ tests_with_feature_flag_tag = get_tests_with_feature_flag_tags(enabled_feature_flags, ent_path)
+
+ _run_git_cmd(["apply", diff_file])
+ _run_git_cmd(["apply", diff_file], cwd=ent_path)
tests_missing_fcv_tag = get_tests_missing_fcv_tag(tests_with_feature_flag_tag)
if tests_missing_fcv_tag:
- print(f"Found tests missing `{REQUIRES_FCV_TAG}` tag:\n" + "\n".join(tests_missing_fcv_tag))
+ print(f"Found tests missing `{REQUIRES_FCV_TAG_LATEST}` tag:\n" +
+ "\n".join(tests_missing_fcv_tag))
sys.exit(1)
sys.exit(0)
if __name__ == "__main__":
- main()
+ parser = argparse.ArgumentParser()
+ parser.add_argument("--diff-file-name", type=str,
+ help="Name of the file containing the git diff")
+ parser.add_argument("--enterprise-path", type=str, help="Path to the enterprise module")
+ args = parser.parse_args()
+ main(args.diff_file_name, args.enterprise_path)