Skip to content

Instantly share code, notes, and snippets.

@iammattcoleman
Last active February 23, 2018 17:42
Show Gist options
  • Save iammattcoleman/88013cb5f92105b15a66ee2ada442a16 to your computer and use it in GitHub Desktop.
Save iammattcoleman/88013cb5f92105b15a66ee2ada442a16 to your computer and use it in GitHub Desktop.
Check if retriggers are needed for packages listed on the 'excuses...' page
<?php
declare(strict_types=1);
if (!isset($argv[1])) {
echo 'USAGE: ', $argv[0], ' [package name]', PHP_EOL;
exit(1);
}
$packageName = $argv[1];
$excusesUrl = 'http://people.canonical.com/~ubuntu-archive/proposed-migration/update_excuses.html';
$excusesDocument = new DOMDocument();
@$excusesDocument->loadHTMLFile($excusesUrl, LIBXML_PARSEHUGE);
$xpath = new DOMXPath($excusesDocument);
$query = '/html/body/ul/li/a[@name="' . $packageName . '"]/../ul/li';
$details = $xpath->query($query);
$retriggerPackages = [];
$format = "%s (%s -> %s)%s\n";
printf($format, 'Package name', 'excuses', 'repository', '');
foreach ($details as $detail) {
$package = extractPackageInfo($detail);
if ($package === false) {
continue;
}
$needsRetriggerText = '';
if ($package['hasRegressions']) {
$needsRetriggerText = "\t\t[regressions]";
$newerVersionAvailable = $package['availableVersion'] !== 'N/A'
&& $package['version'] !== $package['availableVersion'];
if ($newerVersionAvailable) {
$needsRetriggerText .= "\t<--- NEEDS RETRIGGER";
$retriggerPackages[] = $package;
}
}
printf($format, $package['name'], $package['version'], $package['availableVersion'], $needsRetriggerText);
}
if (!empty($retriggerPackages)) {
echo PHP_EOL, 'The following require a retrigger for ', $packageName, ':', PHP_EOL;
foreach ($retriggerPackages as $retriggerPackage) {
echo ' • ';
printf($format, $retriggerPackage['name'], $retriggerPackage['version'], $retriggerPackage['availableVersion'], '');
}
}
function extractPackageInfo($detail)
{
$regex = '/^autopkgtest for (?P<name>[^\/]+)\/(?P<version>.+): amd64/';
if (preg_match($regex, $detail->textContent, $matches)) {
return [
'name' => $matches['name'],
'version' => $matches['version'],
'availableVersion' => getAvailableVersion($matches['name']),
'hasRegressions' => strpos($detail->textContent, 'Regression') !== false
];
}
return false;
}
function getAvailableVersion($name)
{
return trim(shell_exec(
'apt-cache policy ' . $name . " | grep -A1 'Version table:$' | tail -1 | tr -d '*' | awk '{print $1}'"
) ?? 'N/A');
}
#!/bin/sh
if [ $# -lt 1 ]; then
echo "USAGE: $0 [package-name]"
exit 1
fi
if which gsed &>/dev/null; then
readonly SED=gsed
else
readonly SED=sed
fi
readonly container=${2:-bionic-runner}
readonly packageName=$1
readonly runDateTime=$(date +%Y-%m-%d_%H%M%S)
readonly outputFileName=${runDateTime}_${packageName}.txt
git mv *${packageName}.txt $outputFileName
docker run -v $(realpath $(dirname $0)):/script -i $container /bin/bash -c " \
grep -v -e '^$' -e '^#' -e 'bionic-' /etc/apt/sources.list \
| sed 's/bionic/bionic-proposed/' \
| sudo tee /etc/apt/sources.list.d/bionic-proposed.list &>/dev/null; \
sudo apt update &>/dev/null; \
date; \
php /script/checkPackagesNeedingRetrigger.php $packageName
" | tee $outputFileName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment