Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix lp copy packages arbitrary lookback (infra) #1067

Merged
merged 3 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading