1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-22 21:22:40 +00:00

Abandon automation of binary packaging for now

This commit is contained in:
J. King 2022-04-04 14:19:53 -04:00
parent 144a41e061
commit 1b0256d6ce

View file

@ -187,7 +187,10 @@ class RoboFile extends \Robo\Tasks {
} }
// establish which commit to package // establish which commit to package
[$commit, $version] = $this->commitVersion($commit); [$commit, $version] = $this->commitVersion($commit);
$archVersion = preg_replace('/^([^-]+)-(\d+)-(\w+)$/', "$1.r$2.$3", $version); preg_match('/^([^-]+)(?:-(\d+)-(\w+))?$/', $version, $m);
$archVersion = $m[1].($m[2] ? ".r$m[2].$m[3]" : "");
$baseVersion = $m[1];
$release = $m[2];
// name the generic release tarball // name the generic release tarball
$tarball = BASE."release/$version/arsse-$version.tar.gz"; $tarball = BASE."release/$version/arsse-$version.tar.gz";
// start a collection // start a collection
@ -200,22 +203,37 @@ class RoboFile extends \Robo\Tasks {
return $result; return $result;
} }
try { try {
if (file_exists($dir."dist/debian")) { // Perform Arch-specific tasks
// generate the Debian changelog; this also validates our original changelog
$debianChangelog = $this->changelogDebian($this->changelogParse(file_get_contents($dir."CHANGELOG"), $version), $version);
// save the Debian-format changelog
$t->addTask($this->taskWriteToFile($dir."dist/debian/changelog")->text($debianChangelog));
}
if (file_exists($dir."dist/arch")) { if (file_exists($dir."dist/arch")) {
// patch the Arch PKGBUILD file with the correct version string // patch the Arch PKGBUILD file with the correct version string
$t->addTask($this->taskReplaceInFile($dir."dist/arch/PKGBUILD")->regex('/^pkgver=.*$/m')->to("pkgver=$archVersion")); $t->addTask($this->taskReplaceInFile($dir."dist/arch/PKGBUILD")->regex('/^pkgver=.*$/m')->to("pkgver=$archVersion"));
// patch the Arch PKGBUILD file with the correct source file // patch the Arch PKGBUILD file with the correct source file
$t->addTask($this->taskReplaceInFile($dir."dist/arch/PKGBUILD")->regex('/^source=\("arsse-[^"]+"\)$/m')->to('source=("'.basename($tarball).'")')); $t->addTask($this->taskReplaceInFile($dir."dist/arch/PKGBUILD")->regex('/^source=\("arsse-[^"]+"\)$/m')->to('source=("'.basename($tarball).'")'));
} }
// perform Debian-specific tasks
if (file_exists($dir."dist/debian")) {
// generate the Debian changelog; this also validates our original changelog
$changelog = $this->changelogParse(file_get_contents($dir."CHANGELOG"), $version);
$debianChangelog = $this->changelogDebian($changelog, $version);
// save the Debian-format changelog
$t->addTask($this->taskWriteToFile($dir."dist/debian/changelog")->text($debianChangelog));
}
// perform RPM-specific tasks
if (file_exists($dir."dist/rpm")) {
// patch the spec file with the correct version and release
$t->addTask($this->taskReplaceInFile($dir."dist/rpm/arsse.spec")->regex('/^Version: .*$/m')->to("Version: $baseVersion"));
$t->addTask($this->taskReplaceInFile($dir."dist/rpm/arsse.spec")->regex('/^Release: .*$/m')->to("Release: $release"));
// patch the spec file with the correct tarball name
$t->addTask($this->taskReplaceInFile($dir."dist/rpm/arsse.spec")->regex('/^Source0: .*$/m')->to("Source0: arsse-$version.tar.gz"));
// append the RPM changelog to the spec file
$t->addTask($this->taskWriteToFile($dir."dist/rpm/arsse.spec")->append(true)->text("\n\n%changelog\n".$this->changelogRPM($changelog, $version)));
}
// save commit description to VERSION file for reference // save commit description to VERSION file for reference
$t->addTask($this->taskWriteToFile($dir."VERSION")->text($version)); $t->addTask($this->taskWriteToFile($dir."VERSION")->text($version));
// perform Composer installation in the temp location with dev dependencies if (file_exists($dir."docs") || file_exists($dir."manpages")) {
$t->addTask($this->taskComposerInstall()->arg("-q")->dir($dir)); // perform Composer installation in the temp location with dev dependencies to include Robo and Daux
$t->addTask($this->taskExec("composer install")->arg("-q")->dir($dir));
}
if (file_exists($dir."manpages")) { if (file_exists($dir."manpages")) {
// generate manpages // generate manpages
$t->addTask($this->taskExec("./robo manpage")->dir($dir)); $t->addTask($this->taskExec("./robo manpage")->dir($dir));
@ -225,7 +243,7 @@ class RoboFile extends \Robo\Tasks {
$t->addTask($this->taskExec("./robo manual -q")->dir($dir)); $t->addTask($this->taskExec("./robo manual -q")->dir($dir));
} }
// perform Composer installation in the temp location for final output // perform Composer installation in the temp location for final output
$t->addTask($this->taskComposerInstall()->dir($dir)->noDev()->optimizeAutoloader()->arg("--no-scripts")->arg("-q")); $t->addTask($this->taskExec("composer install")->dir($dir)->arg("--no-dev")->arg("-o")->arg("--no-scripts")->arg("-q"));
// delete unwanted files // delete unwanted files
$t->addTask($this->taskFilesystemStack()->remove([ $t->addTask($this->taskFilesystemStack()->remove([
$dir.".git", $dir.".git",
@ -277,79 +295,6 @@ class RoboFile extends \Robo\Tasks {
return $result; return $result;
} }
/** Packages a given commit of the software into an Arch package
*
* The commit to package may be any Git tree-ish identifier: a tag, a branch,
* or any commit hash. If none is provided on the command line, Robo will prompt
* for a commit to package; the default is "HEAD".
*
* The Arch base-devel group should be installed for this.
*/
public function packageArch(string $commit = null): Result {
if (!$this->toolExists("git", "makepkg", "updpkgsums")) {
throw new \Exception("Git, makepkg, and updpkgsums are required in PATH to produce Arch packages");
}
// establish which commit to package
[$commit, $version] = $this->commitVersion($commit);
$tarball = BASE."release/$version/arsse-$version.tar.gz";
$dir = dirname($tarball).\DIRECTORY_SEPARATOR;
// start a collection
$t = $this->collectionBuilder();
// build the generic release tarball if it doesn't exist
if (!file_exists($tarball)) {
$t->addTask($this->taskExec(BASE."robo package:generic $commit"));
}
// extract the PKGBUILD from the tarball
$t->addCode(function() use ($tarball, $dir) {
// because Robo doesn't support extracting a single file we have to do it ourselves
(new \Archive_Tar($tarball))->extractList("arsse/dist/arch/PKGBUILD", $dir, "arsse/dist/arch/", false);
// perform a do-nothing filesystem operation since we need a Robo task result
return $this->taskFilesystemStack()->chmod($dir."PKGBUILD", 0644)->run();
})->completion($this->taskFilesystemStack()->remove($dir."PKGBUILD"));
// build the package
$t->addTask($this->taskExec("makepkg -Ccf")->dir($dir));
return $t->run();
}
/** Packages a given commit of the software a binary Debian package
*
* The commit to package may be any Git tree-ish identifier: a tag, a branch,
* or any commit hash. If none is provided on the command line, Robo will prompt
* for a commit to package; the default is "HEAD".
*
* The pbuilder tool should be installed for this.
*/
public function packageDeb(string $commit = null): Result {
if (!$this->toolExists("git", "sudo", "pbuilder")) {
throw new \Exception("Git, sudo, and pbuilder are required in PATH to produce Debian packages");
}
// establish which commit to package
[$commit, $version] = $this->commitVersion($commit);
$tarball = BASE."release/$version/arsse-$version.tar.gz";
// define some more variables
$tgz = BASE."release/pbuilder-arsse.tgz";
$bind = dirname($tarball);
$script = BASE."dist/debian/pbuilder.sh";
$user = trim(`id -un`);
$group = trim(`id -gn`);
// start a task collection
$t = $this->collectionBuilder();
// check that the pbuilder base exists and create it if it does not
if (!file_exists($tgz)) {
$t->addTask($this->taskFilesystemStack()->mkdir(BASE."release"));
$t->addTask($this->taskExec('sudo pbuilder create --basetgz '.escapeshellarg($tgz).' --mirror http://ftp.ca.debian.org/debian/ --extrapackages "debhelper devscripts lintian"'));
}
// build the generic release tarball if it doesn't exist
if (!file_exists($tarball)) {
$t->addTask($this->taskExec(BASE."robo package:generic $commit"));
}
// build the packages
$t->addTask($this->taskExec('sudo pbuilder execute --basetgz '.escapeshellarg($tgz).' --bindmounts '.escapeshellarg($bind).' -- '.escapeshellarg($script).' '.escapeshellarg("$bind/".basename($tarball))));
// take ownership of the output files
$t->addTask($this->taskExec("sudo chown -R $user:$group ".escapeshellarg($bind)));
return $t->run();
}
/** Packages a release tarball into a Debian source package /** Packages a release tarball into a Debian source package
* *
* The commit to package may be any Git tree-ish identifier: a tag, a branch, * The commit to package may be any Git tree-ish identifier: a tag, a branch,
@ -381,7 +326,7 @@ class RoboFile extends \Robo\Tasks {
// re-pack the tarball using a specific name special to Debian // re-pack the tarball using a specific name special to Debian
$t->addTask($this->taskPack($dir."arsse_$baseVersion.orig.tar.gz")->addDir("arsse-$baseVersion", $base)); $t->addTask($this->taskPack($dir."arsse_$baseVersion.orig.tar.gz")->addDir("arsse-$baseVersion", $base));
// pack the debian tarball // pack the debian tarball
$t->addTask($this->taskPack($dir."arsse_$debVersion.debian.tar.gz")->addDir("debian", $base."dist")); $t->addTask($this->taskPack($dir."arsse_$debVersion.debian.tar.gz")->addDir("debian", $base."dist/debian"));
// generate the DSC file // generate the DSC file
$t->addCode(function() use ($t, $debVersion, $baseVersion, $dir, $base) { $t->addCode(function() use ($t, $debVersion, $baseVersion, $dir, $base) {
try { try {
@ -393,49 +338,66 @@ class RoboFile extends \Robo\Tasks {
return $this->taskWriteToFile($dir."arsse_$debVersion.dsc")->text($dsc)->run(); return $this->taskWriteToFile($dir."arsse_$debVersion.dsc")->text($dsc)->run();
}); });
// delete any existing files // delete any existing files
$t->AddTask($this->taskFilesystemStack()->remove(BASE."release/$version/arsse_$baseVersion.orig.tar.gz")->remove(BASE."release/$version/arsse_$debVersion.debian.tar.gz")->remove(BASE."release/$version/arsse_$debVersion.dsc")); $t->AddTask($this->taskFilesystemStack()->remove([BASE."release/$version/arsse_$baseVersion.orig.tar.gz", BASE."release/$version/arsse_$debVersion.debian.tar.gz", BASE."release/$version/arsse_$debVersion.dsc"]));
// copy the new files over
$t->addTask($this->taskFilesystemStack()->copy($dir."arsse_$baseVersion.orig.tar.gz", BASE."release/$version/arsse_$baseVersion.orig.tar.gz")->copy($dir."arsse_$debVersion.debian.tar.gz", BASE."release/$version/arsse_$debVersion.debian.tar.gz")->copy($dir."arsse_$debVersion.dsc", BASE."release/$version/arsse_$debVersion.dsc")); $t->addTask($this->taskFilesystemStack()->copy($dir."arsse_$baseVersion.orig.tar.gz", BASE."release/$version/arsse_$baseVersion.orig.tar.gz")->copy($dir."arsse_$debVersion.debian.tar.gz", BASE."release/$version/arsse_$debVersion.debian.tar.gz")->copy($dir."arsse_$debVersion.dsc", BASE."release/$version/arsse_$debVersion.dsc"));
return $t->run(); return $t->run();
} }
/** Generates all possible package types for a given commit of the software /** Packages a given commit of the software and produces all relevant release files
* *
* The commit to package may be any Git tree-ish identifier: a tag, a branch, * The commit to package may be any Git tree-ish identifier: a tag, a branch,
* or any commit hash. If none is provided on the command line, Robo will prompt * or any commit hash. If none is provided on the command line, Robo will prompt
* for a commit to package; the default is "HEAD". * for a commit to package; the default is "HEAD".
* *
* Generic release tarballs will always be generated, but distribution-specific * In addition to the release tarball, a Debian source package, Arch PKGBUILD,
* packages are skipped when the required tools are not available * and RPM spec file are output as well. These are suitable for use with Open
* Build Service instances and with slight modification the Arch User Repository.
* Use for Launchpad PPAs has not been tested.
*/ */
public function package(string $commit = null): Result { public function package(string $commit = null): Result {
if (!$this->toolExists("git")) { if (!$this->toolExists("git")) {
throw new \Exception("Git is required in PATH to produce packages"); throw new \Exception("Git is required in PATH to produce packages");
} }
[$commit,] = $this->commitVersion($commit); [$commit, $version] = $this->commitVersion($commit);
// determine whether the distribution-specific packages can be built $tarball = BASE."release/$version/arsse-$version.tar.gz";
$dist = [ // build the generic release tarball
'Arch' => $this->toolExists("git", "makepkg", "updpkgsums"), $result = $this->taskExec(BASE."robo package:generic $commit")->run();
'Deb' => $this->toolExists("git", "sudo", "pbuilder"), if (!$result->wasSuccessful()) {
]; return $result;
}
// if the generic tarball could be built, try to produce Arch, Debian, and RPM files; these might legitimately not exist in old releases
// start by getting the list of files from the tarball
$archive = new \Archive_Tar($tarball);
$filelist = array_flip(array_column($archive->listContent(), "filename"));
// start a collection // start a collection
$t = $this->collectionBuilder(); $t = $this->collectionBuilder();
// build the generic release tarball // Produce an Arch PKGBUILD if appropriate
$t->addTask($this->taskExec(BASE."robo package:generic $commit")); if (isset($filelist['arsse/dist/arch/PKGBUILD'])) {
// build other packages $t->addCode(function() use ($tarball, $archive) {
foreach ($dist as $distro => $run) { $dir = dirname($tarball).\DIRECTORY_SEPARATOR;
if ($run) { $archive->extractList("arsse/dist/arch/PKGBUILD", $dir, "arsse/dist/arch/", false);
$subcmd = strtolower($distro); // update the tarball's checksum
$t->addTask($this->taskExec(BASE."robo package:$subcmd $commit")); $sums = [
} 'md5' => hash_file("md5", $tarball),
];
return $this->taskReplaceInFile($dir."PKGBUILD")->regex('/^md5sums=\("SKIP"\)$/m')->to('md5sums=("'.$sums['md5'].'")')->run();
});
} }
$out = $t->run(); // Produce a Debian source package if appropriate
// note any packages which were not built if (isset($filelist['arsse/dist/debian/control']) && isset($filelist['arsse/dist/debian/source/format'])) {
foreach ($dist as $distro => $run) { $t->addTask($this->taskExec(BASE."robo package:debsrc $commit"));
if (!$run) {
$this->say("Packages for $distro skipped");
}
} }
return $out; // Produce an RPM spec file if appropriate
if (isset($filelist['arsse/dist/rpm/arsse.spec'])) {
$t->addCode(function() use ($tarball, $archive) {
$dir = dirname($tarball).\DIRECTORY_SEPARATOR;
$archive->extractList("arsse/dist/rpm/arsse.spec", $dir, "arsse/dist/rpm/", false);
// perform a do-nothing filesystem operation since we need a Robo task result
return $this->taskFilesystemStack()->chmod($dir."arsse.spec", 0644)->run();
});
}
return $t->run();
} }
/** Generates static manual pages in the "manual" directory /** Generates static manual pages in the "manual" directory