From 8ae167dc05441cd8ac44b2cc42fa88388f291054 Mon Sep 17 00:00:00 2001 From: Alex Vandiver Date: Fri, 14 Apr 2023 18:36:34 +0000 Subject: [PATCH] upgrade-zulip-from-git: We may need to fill in a zulip-git-version file. Installs which are upgrading to current `main`, and are upgrading for the very first time from an install which was originally from git, have a `/home/zulip/deployments/current` which, unlike all later upgrades, is not a `git worktree` of `/srv/zulip.git`, but rather a direct `git clone` of some arbitrary URL. As such, it does not have an `upstream` remote, nor a cached `zulip-git-version` file. This makes later attempts to determine the pre-upgrade revision of git (for pre-deploy hooks) fail, as without a `zulip-git-version` file, `ZULIP_VERSION` is insufficiently-specific (e.g. `6.1+git`), and there is no guarantee the necessary tags exist either. While we can make fresh git installs set up an `upstream` and run `./tools/cache-zulip-git-version` going forward (see subsequent commit), that does not address the issue for deploys which already exist. For those, we must configure and fetch a `remote` in the old checkout, followed by re-generating a cached `zulip-git-version`. Fixes: #25076. --- scripts/lib/zulip_tools.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/scripts/lib/zulip_tools.py b/scripts/lib/zulip_tools.py index 70e1a234e6..b2d879ab5b 100755 --- a/scripts/lib/zulip_tools.py +++ b/scripts/lib/zulip_tools.py @@ -108,6 +108,23 @@ def get_deploy_root() -> str: def parse_version_from(deploy_path: str, merge_base: bool = False) -> str: + if not os.path.exists(os.path.join(deploy_path, "zulip-git-version")): + try: + # Pull this tool from _our_ deploy root, since it may not + # exist historically, but run it the cwd of the old + # deploy, so we set up its remote. + subprocess.check_call( + [os.path.join(get_deploy_root(), "scripts", "lib", "update-git-upstream")], + cwd=deploy_path, + preexec_fn=su_to_zulip, + ) + subprocess.check_call( + [os.path.join(deploy_path, "tools", "cache-zulip-git-version")], + cwd=deploy_path, + preexec_fn=su_to_zulip, + ) + except subprocess.CalledProcessError: + pass try: varname = "ZULIP_MERGE_BASE" if merge_base else "ZULIP_VERSION" return subprocess.check_output(