aboutsummaryrefslogtreecommitdiff
path: root/releng/gitutils.xsh
diff options
context:
space:
mode:
authorJade Lovelace <lix@jade.fyi>2024-06-09 00:50:40 -0700
committerJade Lovelace <lix@jade.fyi>2024-06-09 20:33:24 -0700
commitce71d0e9abe347147f50fba4bf11eac97b2a90ef (patch)
tree9d5dadf0a4b8232963e642fb4c95fb531f2255b1 /releng/gitutils.xsh
parent9aeb314e6a8276d3bd29f968c2baa44d5d19ca37 (diff)
releng: automatically figure out if we should tag latest for docker
For example, when releasing from release-2.90, if `main` has a 2.91 tag ancestor, we know that 2.91 was released, so we should *not* tag latest. Change-Id: Ia56b17a2ee03bbec74b7c271c742858c690d450d
Diffstat (limited to 'releng/gitutils.xsh')
-rw-r--r--releng/gitutils.xsh37
1 files changed, 37 insertions, 0 deletions
diff --git a/releng/gitutils.xsh b/releng/gitutils.xsh
new file mode 100644
index 000000000..3352a6b21
--- /dev/null
+++ b/releng/gitutils.xsh
@@ -0,0 +1,37 @@
+import subprocess
+import json
+
+
+def version_compare(v1: str, v2: str):
+ return json.loads($(nix-instantiate --eval --json --argstr v1 @(v1) --argstr v2 @(v2) --expr '{v1, v2}: builtins.compareVersions v1 v2'))
+
+
+def latest_tag_on_branch(branch: str) -> str:
+ return $(git describe --abbrev=0 @(branch) e>/dev/null).strip()
+
+
+def is_maintenance_branch(branch: str) -> bool:
+ try:
+ main_tag = latest_tag_on_branch('main')
+ current_tag = latest_tag_on_branch(branch)
+
+ return version_compare(current_tag, main_tag) < 0
+ except subprocess.CalledProcessError:
+ # This is the case before Lix releases 2.90, since main *has* no
+ # release tag on it.
+ # FIXME: delete this case after 2.91
+ return False
+
+
+def verify_are_on_tag():
+ current_tag = $(git describe --tag).strip()
+ assert current_tag == VERSION
+
+
+def git_preconditions():
+ # verify there is nothing in index ready to stage
+ proc = !(git diff-index --quiet --cached HEAD --)
+ assert proc.rtn == 0
+ # verify there is nothing *stageable* and tracked
+ proc = !(git diff-files --quiet)
+ assert proc.rtn == 0