Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

hooks: Resolve version strings to commit SHAs, and pass in via the env.

Alex Vandiverf4d70a2e372d
diff --git a/puppet/zulip/files/hooks/pre-deploy.d/sentry.hook b/puppet/zulip/files/hooks/pre-deploy.d/sentry.hook
index f692c363aa2..e23fd66a97f 100755
--- a/puppet/zulip/files/hooks/pre-deploy.d/sentry.hook
+++ b/puppet/zulip/files/hooks/pre-deploy.d/sentry.hook
@@ -40,19 +40,6 @@ if ! which sentry-cli >/dev/null; then
exit 0
fi
-merge_base=""
-if [ "$(git rev-parse --is-inside-work-tree 2>/dev/null || true)" = "true" ]; then
- # Extract the merge-base that tools/cache-zulip-git-version
- # encoded into ./zulip-git-version, and turn it from a `git
- # describe` into a commit hash
- merge_base_described=$(head -n2 ./zulip-git-version | tail -1)
- if [[ "$merge_base_described" =~ ^.*-g([0-9a-f]{7,})$ ]]; then
- merge_base=$(git rev-parse "${BASH_REMATCH[1]}")
- else
- merge_base=$(git rev-parse "$merge_base_described")
- fi
-fi
-
sentry_release="zulip-server@$ZULIP_NEW_VERSION"
echo "$sentry_release" >./sentry-release
@@ -71,6 +58,7 @@ curl "https://sentry.io/api/0/organizations/$sentry_org/releases/" \
-d "$json" \
--silent -o /dev/null
+merge_base="${ZULIP_NEW_MERGE_BASE_COMMIT:-}"
if [ -n "$merge_base" ]; then
echo "sentry: Setting commit range based on merge-base to upstream of $merge_base"
sentry-cli releases --org="$sentry_org" set-commits "$sentry_release" --commit="zulip/zulip@$merge_base"
diff --git a/scripts/lib/upgrade-zulip-stage-2 b/scripts/lib/upgrade-zulip-stage-2
index 67a39e0e98c..3cfbb74ae4f 100755
--- a/scripts/lib/upgrade-zulip-stage-2
+++ b/scripts/lib/upgrade-zulip-stage-2
@@ -150,11 +150,14 @@ if args.from_git:
logging.info("Caching Zulip Git version...")
subprocess.check_call(["./tools/cache-zulip-git-version"], preexec_fn=su_to_zulip)
+from version import ZULIP_MERGE_BASE as NEW_ZULIP_MERGE_BASE
from version import ZULIP_VERSION as NEW_ZULIP_VERSION
old_version = parse_version_from(DEPLOYMENTS_DIR + "/current")
logging.info("Upgrading from %s to %s, in %s", old_version, NEW_ZULIP_VERSION, deploy_path)
-
+old_merge_base = (
+ parse_version_from(DEPLOYMENTS_DIR + "/current", merge_base=True) if args.from_git else ""
+)
# Check if rabbitmq port 25672 is listening on anything except 127.0.0.1
rabbitmq_dist_listen = listening_publicly(25672)
@@ -456,6 +459,23 @@ def run_hooks(kind: Literal["pre-deploy", "post-deploy"]) -> None:
# env overrides that
env["HOME"] = get_zulip_pwent().pw_dir
+ def resolve_version_string(version: str) -> str:
+ matches = re.search(r"-\d+-g([a-f0-9]{7,})$", version)
+ to_parse = version
+ if matches is not None:
+ to_parse = matches.group(1)
+ return subprocess.check_output(
+ ["git", "rev-parse", to_parse], cwd=deploy_path, preexec_fn=su_to_zulip, text=True
+ ).strip()
+
+ if args.from_git:
+ # If we have a git repo, we also resolve those `git describe`
+ # values to full commit hashes, as well as provide the
+ # merge-base of the old/new commits with mainline.
+ env["ZULIP_OLD_COMMIT"] = resolve_version_string(old_version)
+ env["ZULIP_NEW_COMMIT"] = resolve_version_string(NEW_ZULIP_VERSION)
+ env["ZULIP_OLD_MERGE_BASE_COMMIT"] = resolve_version_string(old_merge_base)
+ env["ZULIP_NEW_MERGE_BASE_COMMIT"] = resolve_version_string(NEW_ZULIP_MERGE_BASE)
for script_name in sorted(f for f in os.listdir(path) if f.endswith(".hook")):
subprocess.check_call(
[os.path.join(path, script_name)],
diff --git a/scripts/lib/zulip_tools.py b/scripts/lib/zulip_tools.py
index bbdd7be89a5..70e1a234e66 100755
--- a/scripts/lib/zulip_tools.py
+++ b/scripts/lib/zulip_tools.py
@@ -107,10 +107,11 @@ def get_deploy_root() -> str:
)
-def parse_version_from(deploy_path: str) -> str:
+def parse_version_from(deploy_path: str, merge_base: bool = False) -> str:
try:
+ varname = "ZULIP_MERGE_BASE" if merge_base else "ZULIP_VERSION"
return subprocess.check_output(
- [sys.executable, "-c", "from version import ZULIP_VERSION; print(ZULIP_VERSION)"],
+ [sys.executable, "-c", f"from version import {varname}; print({varname})"],
cwd=deploy_path,
text=True,
).strip()