From f10da2d8fd599dc39d245ffa6b387dcd33bf49ed Mon Sep 17 00:00:00 2001 From: Hook25 Date: Thu, 14 Mar 2024 15:34:12 +0100 Subject: [PATCH 1/3] Use date_superseeded and order_by_date instead of time --- tools/release/lp_copy_packages.py | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/tools/release/lp_copy_packages.py b/tools/release/lp_copy_packages.py index 47c8c0fd33..2d1761bbff 100755 --- a/tools/release/lp_copy_packages.py +++ b/tools/release/lp_copy_packages.py @@ -28,6 +28,7 @@ import sys import datetime import argparse +import itertools from utils import get_launchpad_client @@ -48,11 +49,28 @@ def get_ppa(lp, ppa_name: str, ppa_owner: str): def get_checkbox_packages(ppa): - since_date = datetime.datetime.now() - datetime.timedelta(weeks=4) - # The time ago is needed because else LP api will choke trying to - # return the full history including any published source in the ppa - return ppa.getPublishedSources( - created_since_date=since_date, source_name="checkbox" + """ + Get all the most recent checkbox packages on the PPA that are still current + + A source package is still current when it has not been superseeded by + another. The filtering here is done to avoid copying over outdated + packages to the target PPA + """ + # Note: this is not the same as ppa.getPublishedSources(status="Published") + # the reason is that if a package is Published but for a not + # supported distribution, say Lunar, copying it over will trigger an + # error. When a distribution support is dropped, Launchpad will + # automatically stop building for it and start a grace period for + # updates. This ensures there will always be a pocket of Superseeded + # packages between Published packages for unsupported distro and + # current ones + all_published_sources = ppa.getPublishedSources( + source_name="checkbox", order_by_date=True + ) + # this filters out superseeded packages AND Published packages that are no + # longer current (as they are not being built anymore by Launchpad) + return itertools.takewhile( + lambda x: x.date_superseded is None, all_published_sources ) From c49d6676e7f06b15a44cb2dbed438d79888d2ade Mon Sep 17 00:00:00 2001 From: Hook25 Date: Thu, 14 Mar 2024 15:39:19 +0100 Subject: [PATCH 2/3] Update testing also filtering --- tools/release/test_lp_copy_packages.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/release/test_lp_copy_packages.py b/tools/release/test_lp_copy_packages.py index da760c088b..3edc24c8d5 100644 --- a/tools/release/test_lp_copy_packages.py +++ b/tools/release/test_lp_copy_packages.py @@ -12,9 +12,12 @@ def test_main(self, get_launchpad_client_mock): checkbox_dev_user = MagicMock() lp_client.people = {"checkbox-dev": checkbox_dev_user} - source = MagicMock() + source_to_copy = MagicMock(date_superseded=None) + source_no_copy_superseeded = MagicMock(date_superseded="some date") + source_no_copy_outdated_distro = MagicMock(date_superseded=None) + ppas = checkbox_dev_user.getPPAByName() - ppas.getPublishedSources.return_value = [source] * 5 + ppas.getPublishedSources.return_value = [source_to_copy] * 5 + [source_no_copy_superseeded, source_no_copy_outdated_distro] lp_copy_packages.main( ["checkbox-dev", "beta", "checkbox-dev", "stable"] From 08cad09a0147b9a50707422a2bda5c15173c2524 Mon Sep 17 00:00:00 2001 From: Hook25 Date: Thu, 14 Mar 2024 16:38:16 +0100 Subject: [PATCH 3/3] black test_lp_copy_packages.py --- tools/release/test_lp_copy_packages.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/release/test_lp_copy_packages.py b/tools/release/test_lp_copy_packages.py index 3edc24c8d5..21545a4bae 100644 --- a/tools/release/test_lp_copy_packages.py +++ b/tools/release/test_lp_copy_packages.py @@ -17,7 +17,10 @@ def test_main(self, get_launchpad_client_mock): source_no_copy_outdated_distro = MagicMock(date_superseded=None) ppas = checkbox_dev_user.getPPAByName() - ppas.getPublishedSources.return_value = [source_to_copy] * 5 + [source_no_copy_superseeded, source_no_copy_outdated_distro] + ppas.getPublishedSources.return_value = [source_to_copy] * 5 + [ + source_no_copy_superseeded, + source_no_copy_outdated_distro, + ] lp_copy_packages.main( ["checkbox-dev", "beta", "checkbox-dev", "stable"]