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

This commit is contained in:
Alex Vandiver 2023-04-05 02:16:30 +00:00 committed by Alex Vandiver
parent ecfb12404a
commit f4d70a2e37
3 changed files with 25 additions and 16 deletions

View File

@ -40,19 +40,6 @@ if ! which sentry-cli >/dev/null; then
exit 0 exit 0
fi 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" sentry_release="zulip-server@$ZULIP_NEW_VERSION"
echo "$sentry_release" >./sentry-release echo "$sentry_release" >./sentry-release
@ -71,6 +58,7 @@ curl "https://sentry.io/api/0/organizations/$sentry_org/releases/" \
-d "$json" \ -d "$json" \
--silent -o /dev/null --silent -o /dev/null
merge_base="${ZULIP_NEW_MERGE_BASE_COMMIT:-}"
if [ -n "$merge_base" ]; then if [ -n "$merge_base" ]; then
echo "sentry: Setting commit range based on merge-base to upstream of $merge_base" 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" sentry-cli releases --org="$sentry_org" set-commits "$sentry_release" --commit="zulip/zulip@$merge_base"

View File

@ -150,11 +150,14 @@ if args.from_git:
logging.info("Caching Zulip Git version...") logging.info("Caching Zulip Git version...")
subprocess.check_call(["./tools/cache-zulip-git-version"], preexec_fn=su_to_zulip) 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 from version import ZULIP_VERSION as NEW_ZULIP_VERSION
old_version = parse_version_from(DEPLOYMENTS_DIR + "/current") old_version = parse_version_from(DEPLOYMENTS_DIR + "/current")
logging.info("Upgrading from %s to %s, in %s", old_version, NEW_ZULIP_VERSION, deploy_path) 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 # Check if rabbitmq port 25672 is listening on anything except 127.0.0.1
rabbitmq_dist_listen = listening_publicly(25672) rabbitmq_dist_listen = listening_publicly(25672)
@ -456,6 +459,23 @@ def run_hooks(kind: Literal["pre-deploy", "post-deploy"]) -> None:
# env overrides that # env overrides that
env["HOME"] = get_zulip_pwent().pw_dir 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")): for script_name in sorted(f for f in os.listdir(path) if f.endswith(".hook")):
subprocess.check_call( subprocess.check_call(
[os.path.join(path, script_name)], [os.path.join(path, script_name)],

View File

@ -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: try:
varname = "ZULIP_MERGE_BASE" if merge_base else "ZULIP_VERSION"
return subprocess.check_output( 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, cwd=deploy_path,
text=True, text=True,
).strip() ).strip()