Signal-iOS/Scripts/reverse_integration_check.py
Evan Hahn 5be42da750 Change references from master to main
_I recommend reviewing this with whitespace changes disabled._

Signal has renamed its primary branch to `main`. This updates references
to the old name, `master`, to either reference `main` or a specific
commit hash.

I also fixed a couple of small whitespace issues in a file I was
editing.
2022-05-02 10:30:40 -05:00

209 lines
5.8 KiB
Python
Executable File

#!/usr/bin/env python3
# When we make a hotfix, we need to reverse integrate our hotfix back into
# main. After committing to main, this script audits that all tags have been
# reverse integrated.
import subprocess
import logging
import argparse
import re
# logging.basicConfig(level=logging.DEBUG)
class Version:
def __init__(self, version_string):
self.parts = []
for part_string in version_string.split("."):
matches = re.findall("^[0-9]+", part_string)
if len(matches) == 0:
continue
just_digits = matches[0]
self.parts.append(int(just_digits))
def __gt__(self, other_version):
for part, other_part in zip(self.parts, other_version.parts):
if part > other_part:
return True
if part < other_part:
return False
return False
def is_on_main():
output = subprocess.check_output(
["git", "rev-parse", "--abbrev-ref", "HEAD"], text=True
).strip()
logging.debug("branch output: %s" % output)
return output == "main"
def main():
parser = argparse.ArgumentParser(description="Check for unmerged tags.")
parser.add_argument(
"--current-branch",
action="store_true",
help="if unspecified, the check is only run when on the main branch",
)
args = parser.parse_args()
if not is_on_main():
# Don't interfere while on a feature or hotfix branch
logging.debug("not on main branch")
if not args.current_branch:
return
else:
logging.debug("on main branch")
unmerged_tags_output = subprocess.check_output(
["git", "tag", "--no-merged", "HEAD"], text=True
)
unmerged_tags = [
line.strip() for line in unmerged_tags_output.split("\n") if len(line) > 0
]
logging.debug("All unmerged tags: %s" % unmerged_tags)
# Before this point we weren't always reverse integrating our tags. As we
# audit old tags, we can ratchet this version number back.
epoch_tag = "2.21.0"
logging.debug("ignoring tags before epoch_tag: %s" % epoch_tag)
tags_of_concern = [
tag for tag in unmerged_tags if Version(tag) > Version(epoch_tag)
]
# Don't reverse integrate tags for adhoc builds
tags_of_concern = [tag for tag in tags_of_concern if "adhoc" not in tag]
tags_to_ignore = [
"2.23.3.0",
"2.23.3.1",
"2.26.0.6",
"2.26.0.7",
"2.26.0.15",
"2.26.0.16",
"2.29.0.7",
"2.29.0.8",
"2.29.0.9",
"2.29.0.11",
"2.30.0.0",
"2.30.0.1",
"2.30.2.0",
"2.46.0.26",
"3.0",
"3.0.1",
"3.0.2",
"3.3.1.0",
# These tags were from unmerged branches investigating an issue that only reproduced when installed from TF.
"2.34.0.10",
"2.34.0.11",
"2.34.0.12",
"2.34.0.13",
"2.34.0.15",
"2.34.0.16",
"2.34.0.17",
"2.34.0.18",
"2.34.0.19",
"2.34.0.20",
"2.34.0.6",
"2.34.0.7",
"2.34.0.8",
"2.34.0.9",
"2.37.3.0",
"2.37.4.0",
# these were internal release only tags, now we include "-internal" in the tag name to avoid this
"2.38.0.2.1",
"2.38.0.3.1",
"2.38.0.4.1",
# the work in these tags was moved to the 2.38.1 release instead
"2.38.0.12",
"2.38.0.13",
"2.38.0.14",
"2.38.1.3",
# Looks like this tag was erroneously applied before rebasing.
# After rebasing, HEAD was retagged with 2.40.0.20
"2.40.0.19",
# Looks like this tag was erroneously applied before rebasing.
# After rebasing, HEAD was retagged with 2.41.0.2
"2.41.0.1",
# internal builds, not marked as such
"2.44.0.0",
"2.44.0.3",
"2.42.0.6",
"2.43.1.0",
"2.43.1.1",
"2.44.0.1",
"2.44.0.2",
"2.44.1.1",
"3.4.0.8",
"2.42.2.1",
"2.44.0.14",
"2.44.0.4",
"2.46.0.22",
"2.46.0.23",
"2.46.0.24",
"2.46.0.5",
"3.13.3.11",
"3.13.3.4",
"3.13.4.0",
"3.14.0.26",
"3.14.3.0",
"3.17.0.3",
"3.17.0.5",
"3.21.3.0",
"3.21.3.1",
"3.22.2.0",
"3.8.0.10",
"3.8.0.29",
"3.8.0.31",
"3.8.0.32",
"3.8.0.9",
"3.8.2.2",
"3.8.2.4",
"5.0.0.29",
"5.0.0.73",
"5.6.0.10",
"3.1.1.0",
"3.13.3.6",
"3.13.3.8",
"5.7.0.0",
"5.1.0.0",
"5.13.0.14",
"5.20.0.27-nightly",
"5.21.0.59-beta",
"5.23.0.22-beta",
"5.36.0.29",
"5.36.0.30-beta"
]
tags_of_concern = [tag for tag in tags_of_concern if tag not in tags_to_ignore]
# Internal Builds
#
# If you want to tag a build which is not intended to be reverse
# integrated, include the text "internal" somewhere in the tag name, such as
#
# 1.2.3.4.5-internal
# 1.2.3.4.5-internal-mkirk
#
# NOTE: that if you upload the build to test flight, you still need to give testflight
# a numeric build number - so tag won't match the build number exactly as they do
# with production build tags. That's fine.
#
# To avoid collision with "production" build numbers, use at least a 5
# digit build number.
tags_of_concern = [tag for tag in tags_of_concern if "internal" not in tag]
if len(tags_of_concern) > 0:
logging.debug("Found unmerged tags newer than epoch: %s" % tags_of_concern)
raise RuntimeError("💥 Found unmerged tags: %s" % tags_of_concern)
else:
logging.debug("No unmerged tags newer than epoch. All good!")
if __name__ == "__main__":
main()