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
diff --git a/debian/changelog b/debian/changelog
index fd75122..1b10112 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
1maas (2.7.3-0ubuntu2) bionic; urgency=medium
2
3 * Rebuild of MAAS 2.7.3 including UI LP: #1892542
4
5 -- Adam Collard <adam.collard@canonical.com> Mon, 24 Aug 2020 09:11:12 +0000
6
1maas (2.7.3-0ubuntu1) bionic; urgency=medium7maas (2.7.3-0ubuntu1) bionic; urgency=medium
28
3 * New upstream release, MAAS 2.7.3.9 * New upstream release, MAAS 2.7.3.
diff --git a/utilities/release-build b/utilities/release-build
index e87da7c..3a94f92 100755
--- a/utilities/release-build
+++ b/utilities/release-build
@@ -1,17 +1,29 @@
1#!/bin/bash -e1#!/bin/bash -e
2#
3# Build release packages for specified distro releases
4#
5# Usage:
6# ./release-build bionic
7#
8# It's possible to override the packge build revision with DEB_BUILD_REV=n (by
9# default it's 1)
10#
11# If SKIP_UI_BUILD=1 is specified, the UI tree won't be rebuilt.
12#
213
3ROOTDIR="$(dirname "$(dirname "$(realpath "$0")")")"14# The package build revision
4BUILDDIR="$ROOTDIR/build_pkg"15DEB_BUILD_REV=${DEB_BUILD_REV:-1}
5PACKAGE_BUILD_AREA="$ROOTDIR/../build-area"16# Whether to skip the UI build
17SKIP_UI_BUILD=${SKIP_UI_BUILD:-0}
618
7declare -A SUPPORTED_RELEASES19declare -A SUPPORTED_RELEASES=(
8SUPPORTED_RELEASES=(
9 [focal]=20.04
10 [eoan]=19.10
11 [disco]=19.04
12 [bionic]=18.0420 [bionic]=18.04
13)21)
1422
23ROOTDIR="$(dirname "$(dirname "$(realpath "$0")")")"
24BUILDDIR="$ROOTDIR/build_pkg"
25PACKAGE_BUILD_AREA="$ROOTDIR/../build-area"
26
15exit_error() {27exit_error() {
16 echo "$@" >&228 echo "$@" >&2
17 exit 129 exit 1
@@ -32,6 +44,9 @@ check_releases() {
32}44}
3345
34build_source_package() {46build_source_package() {
47 if [ "$SKIP_UI_BUILD" != 1 ]; then
48 make -C "$ROOTDIR/src/maasui" clean build # ensure the UI is updated
49 fi
35 make -C "$ROOTDIR" package-tree50 make -C "$ROOTDIR" package-tree
36}51}
3752
@@ -44,13 +59,12 @@ ensure_changelog_author() {
44update_changelog_version() {59update_changelog_version() {
45 local deb_version="$1"60 local deb_version="$1"
46 local release="$2"61 local release="$2"
47 local new_version="${deb_version}~${SUPPORTED_RELEASES[$release]}.1"62 local new_version="${deb_version}~${SUPPORTED_RELEASES[$release]}.${DEB_BUILD_REV}"
48 sed -i "1 s/(.*;/($new_version) $release;/" debian/changelog63 sed -i "1 s/(.*;/($new_version) $release;/" debian/changelog
49}64}
5065
5166
52# Main67# Main
53
54check_releases "$@"68check_releases "$@"
55releases="$*"69releases="$*"
5670
diff --git a/utilities/release-upload b/utilities/release-upload
57new file mode 10075571new file mode 100755
index 0000000..f3610a2
--- /dev/null
+++ b/utilities/release-upload
@@ -0,0 +1,113 @@
1#!/usr/bin/env python3
2
3"""Validate and upload a MAAS deb release to a PPA."""
4
5from argparse import ArgumentParser, ArgumentTypeError, FileType, Namespace
6from pathlib import Path
7import re
8from subprocess import CalledProcessError, check_output, PIPE
9import sys
10from typing import Optional
11
12from packaging.version import Version
13
14
15class PPAURL:
16 """A PPA URL."""
17
18 url: str
19 release: Version
20 pocket: Optional[str]
21
22 _PPA_RE = re.compile(r"^ppa:maas/(?P<release>[0-9.]+)(-(?P<pocket>.*))?$")
23
24 def __init__(self, url: str):
25 match = self._PPA_RE.match(url)
26 if not match:
27 raise ArgumentTypeError("Invalid MAAS PPA URL")
28
29 self.url = url
30 matches = match.groupdict()
31 self.release = Version(matches["release"])
32 self.pocket = matches["pocket"]
33
34 def __str__(self) -> str:
35 return self.url
36
37 @property
38 def is_stable(self) -> bool:
39 return not self.pocket
40
41
42class ChangesFile(FileType):
43
44 _FILE_NAME_RE = re.compile(r"^maas_(?P<version>[^-]+)-.*_source.changes$")
45
46 def __call__(self, path: str):
47 fileobj = super().__call__(path)
48 base_path = Path(path).name
49 match = self._FILE_NAME_RE.match(base_path)
50 if not match:
51 raise ArgumentTypeError("Invalid changes file name.")
52 # add version
53 version = match.groupdict()["version"].replace("~", "")
54 fileobj.version = Version(version)
55 return fileobj
56
57
58def parse_args() -> Namespace:
59 parser = ArgumentParser(description=__doc__)
60 parser.add_argument(
61 "ppa_url",
62 type=PPAURL,
63 help="PPA URL, e.g. ppa:maas/2.9",
64 metavar="PPA_URL",
65 )
66 parser.add_argument(
67 "changes_file",
68 type=ChangesFile(),
69 help="Path to .changes file to upload",
70 metavar="CHANGES_FILE",
71 )
72 parser.add_argument(
73 "--validate-only",
74 action="store_true",
75 help="Dry run, don't actually upload",
76 )
77 return parser.parse_args()
78
79
80def upload_ppa(ppa_url: str, changes_file: str):
81 try:
82 output = check_output(["dput", ppa_url, changes_file], stderr=PIPE)
83 except CalledProcessError as e:
84 sys.exit("Upload failed with message:\n" + e.stderr.decode())
85 print(output.decode(), end="")
86
87
88def release_version(version: Version):
89 """Return version as major.minor only."""
90 return "{}.{}".format(*version.release[:2])
91
92
93if __name__ == "__main__":
94 args = parse_args()
95 version = args.changes_file.version
96 ppa_version = args.ppa_url.release
97 changes_release = release_version(version)
98 ppa_release = release_version(ppa_version)
99 if changes_release != ppa_release:
100 sys.exit(
101 f"PPA ({ppa_release}) and changes file ({changes_release}) "
102 "versions don't match"
103 )
104 if (
105 version > ppa_version
106 and version.is_prerelease
107 and args.ppa_url.is_stable
108 ):
109 sys.exit(
110 "Can't upload prerelease version of a point release to stable PPA."
111 )
112 if not args.validate_only:
113 upload_ppa(str(args.ppa_url), args.changes_file.name)

Subscribers

People subscribed via source and target branches