Skip to content

Commit

Permalink
Fix lp copy packages arbitrary lookback (infra) (#1067)
Browse files Browse the repository at this point in the history
* Use date_superseeded and order_by_date instead of time

* Update testing also filtering

* black test_lp_copy_packages.py
  • Loading branch information
Hook25 authored and fernando79513 committed Mar 18, 2024
1 parent 43f7300 commit fbc6c0c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
28 changes: 23 additions & 5 deletions tools/release/lp_copy_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import sys
import datetime
import argparse
import itertools

from utils import get_launchpad_client

Expand All @@ -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
)


Expand Down
10 changes: 8 additions & 2 deletions tools/release/test_lp_copy_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@ 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"]
Expand Down

0 comments on commit fbc6c0c

Please sign in to comment.