summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-03-21 13:02:03 +0200
committerLars Wirzenius <liw@liw.fi>2021-03-21 13:02:03 +0200
commitcd791b3820754c241735e00cedd6dc4a6e968765 (patch)
treefae48747b6d4e3aa8b9a2fb85aaf4915cac5f38f
parent5e36e51ca9c2daef48fb52d4b8c8463947a5ef0f (diff)
downloadick-helpers-cd791b3820754c241735e00cedd6dc4a6e968765.tar.gz
feat: add scripts to help build releases
-rwxr-xr-xbuild_release_deb.sh54
-rwxr-xr-xlist_new_release_tags60
2 files changed, 114 insertions, 0 deletions
diff --git a/build_release_deb.sh b/build_release_deb.sh
new file mode 100755
index 0000000..ec99556
--- /dev/null
+++ b/build_release_deb.sh
@@ -0,0 +1,54 @@
+#!/bin/bash
+#
+# Build an Obnam release as a Debian .deb package. Usage:
+#
+# ./build_release_deb.sh /workspace
+
+set -euo pipefail
+
+cleanup()
+{
+ rm -rf "$tmpdir"
+}
+
+if [ "$#" != 2 ]
+then
+ echo "ERROR: Usage: $0 TARGET-DIR GIT-TAG" 1>&2
+ exit 1
+fi
+
+target="$(cd "$1"; pwd)"
+tag="$2"
+
+# Create a temporary directory and arrange for it to be deleted at the
+# end.
+tmpdir="$(mktemp -d)"
+echo "$tmpdir"
+trap cleanup EXIT
+
+# Export the tag to a temporary source tarball.
+git archive "$tag" | xz > "$tmpdir/src.tar.xz"
+
+# Unpack the temporary source tarball to a new source tree.
+mkdir "$tmpdir/src"
+tar -C "$tmpdir/src" -xf "$tmpdir/src.tar.xz"
+
+# Switch to the new source tree.
+cd "$tmpdir/src"
+
+# Get name and version of source package.
+name="$(dpkg-parsechangelog -SSource)"
+version="$(dpkg-parsechangelog -SVersion)"
+
+# Get upstream version: everything before the last dash.
+uv="$(echo "$version" | sed 's/-[^-]*$//')"
+orig="${name}_${uv}.orig.tar.xz"
+
+# Rename the source tarball to what dpkg-buildpackage wants.
+mv ../src.tar.xz "../$orig"
+
+# Build the package.
+dpkg-buildpackage -us -uc
+
+# Copy the results to the desired location.
+cp ../*_* "$target"
diff --git a/list_new_release_tags b/list_new_release_tags
new file mode 100755
index 0000000..90994ac
--- /dev/null
+++ b/list_new_release_tags
@@ -0,0 +1,60 @@
+#!/usr/bin/python3
+#
+# This lists all new release tags, which need to be built. The list of
+# previously known tags is kept in a file given as the argument to this script.
+# If the file doesn't exist, all existing release tags are saved there, and
+# nothing is printed: this is so that on the first run, nothing is new and
+# nothing needs to be built.
+#
+# A release tag MUST match "vX.Y.Z", where X, Y, and Z are integers.
+
+import os
+import re
+import subprocess
+import sys
+
+
+TAG_PATTERN = re.compile(r"^v(\d+)?.(\d+)\.(\d+)$")
+
+
+def release_tags():
+ p = subprocess.run(["git", "tag", "-l"], check=True, capture_output=True)
+ lines = p.stdout.decode().splitlines()
+ return [line for line in lines if tag_sort_key(line) is not None]
+
+
+def sorted_tags(tags):
+ return list(sorted(tags, key=tag_sort_key))
+
+
+def tag_sort_key(tag):
+ m = TAG_PATTERN.match(tag)
+ if not m:
+ return None
+ return (m.group(1), m.group(2), m.group(3))
+
+
+def built_tags(filename):
+ if os.path.exists(filename):
+ return list(line.strip() for line in open(filename).readlines())
+ return []
+
+
+def save_built_tags(filename, tags):
+ return open(filename, "w").write("".join(f"{tag}\n" for tag in tags))
+
+
+tags_filename = sys.argv[1]
+
+tags = sorted_tags(release_tags())
+
+if os.path.exists(tags_filename):
+ built = built_tags(tags_filename)
+ for tag in tags:
+ if tag not in built:
+ print(tag)
+ built.append(tag)
+else:
+ built = tags
+
+save_built_tags(tags_filename, built)