Merge ~adam-collard/maas:2.7-release-scripts into maas:2.7

Proposed by Adam Collard
Status: Merged
Approved by: Adam Collard
Approved revision: 853f2b55e5d3ad1b240dab287b27ec03a1705eee
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~adam-collard/maas:2.7-release-scripts
Merge into: maas:2.7
Diff against target: 200 lines (+143/-10)
3 files modified
debian/changelog (+6/-0)
utilities/release-build (+24/-10)
utilities/release-upload (+113/-0)
Reviewer Review Type Date Requested Status
Alberto Donato (community) Approve
MAAS Lander unittests Pending
Review via email: mp+389707@code.launchpad.net

Commit message

Backport release scripts from master to 2.7

s/focal/bionic/

To post a comment you must log in.
Revision history for this message
Alberto Donato (ack) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/debian/changelog b/debian/changelog
2index fd75122..1b10112 100644
3--- a/debian/changelog
4+++ b/debian/changelog
5@@ -1,3 +1,9 @@
6+maas (2.7.3-0ubuntu2) bionic; urgency=medium
7+
8+ * Rebuild of MAAS 2.7.3 including UI LP: #1892542
9+
10+ -- Adam Collard <adam.collard@canonical.com> Mon, 24 Aug 2020 09:11:12 +0000
11+
12 maas (2.7.3-0ubuntu1) bionic; urgency=medium
13
14 * New upstream release, MAAS 2.7.3.
15diff --git a/utilities/release-build b/utilities/release-build
16index e87da7c..3a94f92 100755
17--- a/utilities/release-build
18+++ b/utilities/release-build
19@@ -1,17 +1,29 @@
20 #!/bin/bash -e
21+#
22+# Build release packages for specified distro releases
23+#
24+# Usage:
25+# ./release-build bionic
26+#
27+# It's possible to override the packge build revision with DEB_BUILD_REV=n (by
28+# default it's 1)
29+#
30+# If SKIP_UI_BUILD=1 is specified, the UI tree won't be rebuilt.
31+#
32
33-ROOTDIR="$(dirname "$(dirname "$(realpath "$0")")")"
34-BUILDDIR="$ROOTDIR/build_pkg"
35-PACKAGE_BUILD_AREA="$ROOTDIR/../build-area"
36+# The package build revision
37+DEB_BUILD_REV=${DEB_BUILD_REV:-1}
38+# Whether to skip the UI build
39+SKIP_UI_BUILD=${SKIP_UI_BUILD:-0}
40
41-declare -A SUPPORTED_RELEASES
42-SUPPORTED_RELEASES=(
43- [focal]=20.04
44- [eoan]=19.10
45- [disco]=19.04
46+declare -A SUPPORTED_RELEASES=(
47 [bionic]=18.04
48 )
49
50+ROOTDIR="$(dirname "$(dirname "$(realpath "$0")")")"
51+BUILDDIR="$ROOTDIR/build_pkg"
52+PACKAGE_BUILD_AREA="$ROOTDIR/../build-area"
53+
54 exit_error() {
55 echo "$@" >&2
56 exit 1
57@@ -32,6 +44,9 @@ check_releases() {
58 }
59
60 build_source_package() {
61+ if [ "$SKIP_UI_BUILD" != 1 ]; then
62+ make -C "$ROOTDIR/src/maasui" clean build # ensure the UI is updated
63+ fi
64 make -C "$ROOTDIR" package-tree
65 }
66
67@@ -44,13 +59,12 @@ ensure_changelog_author() {
68 update_changelog_version() {
69 local deb_version="$1"
70 local release="$2"
71- local new_version="${deb_version}~${SUPPORTED_RELEASES[$release]}.1"
72+ local new_version="${deb_version}~${SUPPORTED_RELEASES[$release]}.${DEB_BUILD_REV}"
73 sed -i "1 s/(.*;/($new_version) $release;/" debian/changelog
74 }
75
76
77 # Main
78-
79 check_releases "$@"
80 releases="$*"
81
82diff --git a/utilities/release-upload b/utilities/release-upload
83new file mode 100755
84index 0000000..f3610a2
85--- /dev/null
86+++ b/utilities/release-upload
87@@ -0,0 +1,113 @@
88+#!/usr/bin/env python3
89+
90+"""Validate and upload a MAAS deb release to a PPA."""
91+
92+from argparse import ArgumentParser, ArgumentTypeError, FileType, Namespace
93+from pathlib import Path
94+import re
95+from subprocess import CalledProcessError, check_output, PIPE
96+import sys
97+from typing import Optional
98+
99+from packaging.version import Version
100+
101+
102+class PPAURL:
103+ """A PPA URL."""
104+
105+ url: str
106+ release: Version
107+ pocket: Optional[str]
108+
109+ _PPA_RE = re.compile(r"^ppa:maas/(?P<release>[0-9.]+)(-(?P<pocket>.*))?$")
110+
111+ def __init__(self, url: str):
112+ match = self._PPA_RE.match(url)
113+ if not match:
114+ raise ArgumentTypeError("Invalid MAAS PPA URL")
115+
116+ self.url = url
117+ matches = match.groupdict()
118+ self.release = Version(matches["release"])
119+ self.pocket = matches["pocket"]
120+
121+ def __str__(self) -> str:
122+ return self.url
123+
124+ @property
125+ def is_stable(self) -> bool:
126+ return not self.pocket
127+
128+
129+class ChangesFile(FileType):
130+
131+ _FILE_NAME_RE = re.compile(r"^maas_(?P<version>[^-]+)-.*_source.changes$")
132+
133+ def __call__(self, path: str):
134+ fileobj = super().__call__(path)
135+ base_path = Path(path).name
136+ match = self._FILE_NAME_RE.match(base_path)
137+ if not match:
138+ raise ArgumentTypeError("Invalid changes file name.")
139+ # add version
140+ version = match.groupdict()["version"].replace("~", "")
141+ fileobj.version = Version(version)
142+ return fileobj
143+
144+
145+def parse_args() -> Namespace:
146+ parser = ArgumentParser(description=__doc__)
147+ parser.add_argument(
148+ "ppa_url",
149+ type=PPAURL,
150+ help="PPA URL, e.g. ppa:maas/2.9",
151+ metavar="PPA_URL",
152+ )
153+ parser.add_argument(
154+ "changes_file",
155+ type=ChangesFile(),
156+ help="Path to .changes file to upload",
157+ metavar="CHANGES_FILE",
158+ )
159+ parser.add_argument(
160+ "--validate-only",
161+ action="store_true",
162+ help="Dry run, don't actually upload",
163+ )
164+ return parser.parse_args()
165+
166+
167+def upload_ppa(ppa_url: str, changes_file: str):
168+ try:
169+ output = check_output(["dput", ppa_url, changes_file], stderr=PIPE)
170+ except CalledProcessError as e:
171+ sys.exit("Upload failed with message:\n" + e.stderr.decode())
172+ print(output.decode(), end="")
173+
174+
175+def release_version(version: Version):
176+ """Return version as major.minor only."""
177+ return "{}.{}".format(*version.release[:2])
178+
179+
180+if __name__ == "__main__":
181+ args = parse_args()
182+ version = args.changes_file.version
183+ ppa_version = args.ppa_url.release
184+ changes_release = release_version(version)
185+ ppa_release = release_version(ppa_version)
186+ if changes_release != ppa_release:
187+ sys.exit(
188+ f"PPA ({ppa_release}) and changes file ({changes_release}) "
189+ "versions don't match"
190+ )
191+ if (
192+ version > ppa_version
193+ and version.is_prerelease
194+ and args.ppa_url.is_stable
195+ ):
196+ sys.exit(
197+ "Can't upload prerelease version of a point release to stable PPA."
198+ )
199+ if not args.validate_only:
200+ upload_ppa(str(args.ppa_url), args.changes_file.name)

Subscribers

People subscribed via source and target branches