2020-06-11 00:54:34 +02:00
|
|
|
import glob
|
2016-10-14 00:57:08 +02:00
|
|
|
import os
|
2020-04-17 09:19:39 +02:00
|
|
|
import subprocess
|
2019-06-20 18:27:09 +02:00
|
|
|
import sys
|
2017-03-26 04:48:25 +02:00
|
|
|
from distutils.version import LooseVersion
|
2020-06-11 00:54:34 +02:00
|
|
|
from typing import Iterable, List, Optional, Tuple
|
|
|
|
|
2017-10-18 05:02:44 +02:00
|
|
|
from scripts.lib.zulip_tools import get_dev_uuid_var_path
|
2020-06-11 00:54:34 +02:00
|
|
|
from version import PROVISION_VERSION
|
2016-10-14 00:57:08 +02:00
|
|
|
|
2020-04-17 09:19:39 +02:00
|
|
|
ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
|
2020-04-17 08:46:45 +02:00
|
|
|
def get_major_version(v: str) -> int:
|
2016-10-14 00:57:08 +02:00
|
|
|
return int(v.split('.')[0])
|
|
|
|
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def get_version_file() -> str:
|
2017-10-18 05:02:44 +02:00
|
|
|
uuid_var_path = get_dev_uuid_var_path()
|
|
|
|
return os.path.join(uuid_var_path, 'provision_version')
|
2016-10-14 00:57:08 +02:00
|
|
|
|
|
|
|
PREAMBLE = '''
|
|
|
|
Before we run tests, we make sure your provisioning version
|
|
|
|
is correct by looking at var/provision_version, which is at
|
|
|
|
version %s, and we compare it to the version in source
|
|
|
|
control (version.py), which is %s.
|
|
|
|
'''
|
|
|
|
|
2020-04-17 08:46:45 +02:00
|
|
|
def preamble(version: str) -> str:
|
2016-10-14 00:57:08 +02:00
|
|
|
text = PREAMBLE % (version, PROVISION_VERSION)
|
|
|
|
text += '\n'
|
|
|
|
return text
|
|
|
|
|
|
|
|
NEED_TO_DOWNGRADE = '''
|
|
|
|
It looks like you checked out a branch that expects an older
|
|
|
|
version of dependencies than the version you provisioned last.
|
|
|
|
This may be ok, but it's likely that you either want to rebase
|
|
|
|
your branch on top of upstream/master or re-provision your VM.
|
2016-12-10 17:57:41 +01:00
|
|
|
|
2017-01-14 11:19:26 +01:00
|
|
|
Do this: `./tools/provision`
|
2016-10-14 00:57:08 +02:00
|
|
|
'''
|
|
|
|
|
|
|
|
NEED_TO_UPGRADE = '''
|
|
|
|
It looks like you checked out a branch that has added
|
2016-12-30 00:59:46 +01:00
|
|
|
dependencies beyond what you last provisioned. Your command
|
|
|
|
is likely to fail until you add dependencies by provisioning.
|
2016-12-10 17:57:41 +01:00
|
|
|
|
2017-01-14 11:19:26 +01:00
|
|
|
Do this: `./tools/provision`
|
2016-10-14 00:57:08 +02:00
|
|
|
'''
|
|
|
|
|
2020-04-17 08:46:45 +02:00
|
|
|
def get_provisioning_status() -> Tuple[bool, Optional[str]]:
|
2016-10-14 00:57:08 +02:00
|
|
|
version_file = get_version_file()
|
|
|
|
if not os.path.exists(version_file):
|
|
|
|
# If the developer doesn't have a version_file written by
|
|
|
|
# a previous provision, then we don't do any safety checks
|
|
|
|
# here on the assumption that the developer is managing
|
2017-01-14 11:19:26 +01:00
|
|
|
# their own dependencies and not running provision.
|
2016-10-14 00:57:08 +02:00
|
|
|
return True, None
|
|
|
|
|
2020-04-09 21:51:58 +02:00
|
|
|
with open(version_file) as f:
|
2019-07-14 21:37:08 +02:00
|
|
|
version = f.read().strip()
|
2016-10-14 00:57:08 +02:00
|
|
|
|
|
|
|
# Normal path for people that provision--we're all good!
|
|
|
|
if version == PROVISION_VERSION:
|
|
|
|
return True, None
|
|
|
|
|
|
|
|
# We may be more provisioned than the branch we just moved to. As
|
|
|
|
# long as the major version hasn't changed, then we should be ok.
|
2017-03-26 04:48:25 +02:00
|
|
|
if LooseVersion(version) > LooseVersion(PROVISION_VERSION):
|
2016-10-14 00:57:08 +02:00
|
|
|
if get_major_version(version) == get_major_version(PROVISION_VERSION):
|
|
|
|
return True, None
|
|
|
|
else:
|
|
|
|
return False, preamble(version) + NEED_TO_DOWNGRADE
|
|
|
|
|
|
|
|
return False, preamble(version) + NEED_TO_UPGRADE
|
2019-06-20 18:27:09 +02:00
|
|
|
|
|
|
|
|
2020-04-17 08:46:45 +02:00
|
|
|
def assert_provisioning_status_ok(force: bool) -> None:
|
2019-06-20 18:27:09 +02:00
|
|
|
if not force:
|
|
|
|
ok, msg = get_provisioning_status()
|
|
|
|
if not ok:
|
|
|
|
print(msg)
|
|
|
|
print('If you really know what you are doing, use --force to run anyway.')
|
|
|
|
sys.exit(1)
|
2020-04-17 08:51:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
def find_js_test_files(test_dir: str, files: Iterable[str]) -> List[str]:
|
|
|
|
test_files = []
|
|
|
|
for file in files:
|
|
|
|
for file_name in os.listdir(test_dir):
|
|
|
|
if file_name.startswith(file):
|
|
|
|
file = file_name
|
|
|
|
break
|
|
|
|
if not os.path.exists(file):
|
|
|
|
file = os.path.join(test_dir, file)
|
|
|
|
test_files.append(os.path.abspath(file))
|
|
|
|
|
|
|
|
if not test_files:
|
|
|
|
test_files = sorted(glob.glob(os.path.join(test_dir, '*.js')))
|
|
|
|
|
|
|
|
return test_files
|
2020-04-17 09:19:39 +02:00
|
|
|
|
|
|
|
def prepare_puppeteer_run() -> None:
|
|
|
|
os.chdir(ZULIP_PATH)
|
|
|
|
subprocess.check_call(['node', 'node_modules/puppeteer/install.js'])
|
|
|
|
os.makedirs('var/puppeteer', exist_ok=True)
|
|
|
|
for f in glob.glob('var/puppeteer/puppeteer-failure*.png'):
|
|
|
|
os.remove(f)
|