2017-12-08 19:37:49 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use Robo\Result;
|
|
|
|
|
|
|
|
class RoboFile extends \Robo\Tasks {
|
|
|
|
const BASE = __DIR__.\DIRECTORY_SEPARATOR;
|
|
|
|
const BASE_TEST = self::BASE."tests".\DIRECTORY_SEPARATOR;
|
|
|
|
|
2019-01-25 21:56:05 +00:00
|
|
|
/** Runs the typical test suite
|
2017-12-22 16:41:54 +00:00
|
|
|
*
|
|
|
|
* Arguments passed to the task are passed on to PHPUnit. Thus one may, for
|
2017-12-17 16:37:07 +00:00
|
|
|
* example, run the following command and get the expected results:
|
2017-12-22 16:41:54 +00:00
|
|
|
*
|
|
|
|
* ./robo test --testsuite TTRSS --exclude-group slow --testdox
|
|
|
|
*
|
|
|
|
* Please see the PHPUnit documentation for available options.
|
2017-12-17 16:37:07 +00:00
|
|
|
*/
|
2017-12-08 19:37:49 +00:00
|
|
|
public function test(array $args): Result {
|
2019-01-22 22:49:14 +00:00
|
|
|
return $this->runTests(escapeshellarg(\PHP_BINARY), "typical", $args);
|
2017-12-17 15:27:34 +00:00
|
|
|
}
|
|
|
|
|
2019-01-25 21:56:05 +00:00
|
|
|
/** Runs the full test suite
|
2017-12-22 16:41:54 +00:00
|
|
|
*
|
2018-08-15 13:59:07 +00:00
|
|
|
* This includes pedantic tests which may help to identify problems.
|
|
|
|
* See help for the "test" task for more details.
|
2017-12-17 16:37:07 +00:00
|
|
|
*/
|
|
|
|
public function testFull(array $args): Result {
|
2019-01-22 22:49:14 +00:00
|
|
|
return $this->runTests(escapeshellarg(\PHP_BINARY), "full", $args);
|
2017-12-17 16:37:07 +00:00
|
|
|
}
|
|
|
|
|
2017-12-22 16:41:54 +00:00
|
|
|
/**
|
|
|
|
* Runs a quick subset of the test suite
|
|
|
|
*
|
|
|
|
* See help for the "test" task for more details.
|
2017-12-17 16:37:07 +00:00
|
|
|
*/
|
2017-12-17 15:27:34 +00:00
|
|
|
public function testQuick(array $args): Result {
|
2019-01-22 22:49:14 +00:00
|
|
|
return $this->runTests(escapeshellarg(\PHP_BINARY), "quick", $args);
|
2017-12-08 19:37:49 +00:00
|
|
|
}
|
|
|
|
|
2017-12-22 16:41:54 +00:00
|
|
|
/** Produces a code coverage report
|
|
|
|
*
|
2017-12-17 16:37:07 +00:00
|
|
|
* By default this task produces an HTML-format coverage report in
|
2018-08-15 13:59:07 +00:00
|
|
|
* tests/coverage/. Additional reports may be produced by passing
|
2017-12-17 16:37:07 +00:00
|
|
|
* arguments to this task as one would to PHPUnit.
|
2017-12-22 16:41:54 +00:00
|
|
|
*
|
2017-12-17 16:37:07 +00:00
|
|
|
* Robo first tries to use phpdbg and will fall back to Xdebug if available.
|
2017-12-22 16:41:54 +00:00
|
|
|
* Because Xdebug slows down non-coverage tasks, however, phpdbg is highly
|
2018-08-15 13:59:07 +00:00
|
|
|
* recommended if debugging facilities are not otherwise needed.
|
2017-12-17 16:37:07 +00:00
|
|
|
*/
|
2017-12-08 19:37:49 +00:00
|
|
|
public function coverage(array $args): Result {
|
2018-12-05 22:07:47 +00:00
|
|
|
// run tests with code coverage reporting enabled
|
|
|
|
$exec = $this->findCoverageEngine();
|
|
|
|
return $this->runTests($exec, "coverage", array_merge(["--coverage-html", self::BASE_TEST."coverage"], $args));
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Produces a code coverage report, with redundant tests
|
|
|
|
*
|
|
|
|
* Depending on the environment, some tests that normally provide
|
|
|
|
* coverage may be skipped, while working alternatives are normally
|
|
|
|
* suppressed for reasons of time. This coverage report will try to
|
|
|
|
* run all tests which may cover code.
|
2018-12-05 22:28:11 +00:00
|
|
|
*
|
2018-12-05 22:07:47 +00:00
|
|
|
* See also help for the "coverage" task for more details.
|
|
|
|
*/
|
|
|
|
public function coverageFull(array $args): Result {
|
2017-12-17 15:27:34 +00:00
|
|
|
// run tests with code coverage reporting enabled
|
|
|
|
$exec = $this->findCoverageEngine();
|
2018-08-15 13:59:07 +00:00
|
|
|
return $this->runTests($exec, "typical", array_merge(["--coverage-html", self::BASE_TEST."coverage"], $args));
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Runs the coding standards fixer */
|
|
|
|
public function clean($opts = ['demo|d' => false]): Result {
|
|
|
|
$t = $this->taskExec(realpath(self::BASE."vendor/bin/php-cs-fixer"));
|
|
|
|
$t->arg("fix");
|
|
|
|
if ($opts['demo']) {
|
|
|
|
$t->args("--dry-run", "--diff")->option("--diff-format", "udiff");
|
|
|
|
}
|
|
|
|
return $t->run();
|
2017-12-08 19:37:49 +00:00
|
|
|
}
|
|
|
|
|
2017-12-17 15:27:34 +00:00
|
|
|
protected function findCoverageEngine(): string {
|
2018-12-08 01:03:04 +00:00
|
|
|
if ($this->isWindows()) {
|
|
|
|
$dbg = dirname(\PHP_BINARY)."\\phpdbg.exe";
|
|
|
|
$dbg = file_exists($dbg) ? $dbg : "";
|
2017-12-17 15:27:34 +00:00
|
|
|
} else {
|
2019-03-21 02:25:00 +00:00
|
|
|
$dbg = trim(`which phpdbg`);
|
2018-12-08 01:03:04 +00:00
|
|
|
}
|
|
|
|
if ($dbg) {
|
|
|
|
return escapeshellarg($dbg)." -qrr";
|
|
|
|
} else {
|
|
|
|
return escapeshellarg(\PHP_BINARY);
|
2017-12-17 15:27:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-06 17:32:28 +00:00
|
|
|
protected function isWindows(): bool {
|
|
|
|
return defined("PHP_WINDOWS_VERSION_MAJOR");
|
|
|
|
}
|
|
|
|
|
2019-03-25 13:53:06 +00:00
|
|
|
protected function blackhole(bool $all = false): string {
|
|
|
|
$hole = $this->isWindows() ? "nul" : "/dev/null";
|
|
|
|
return $all ? ">$hole 2>&1" : "2>$hole";
|
|
|
|
}
|
|
|
|
|
2018-08-15 13:59:07 +00:00
|
|
|
protected function runTests(string $executor, string $set, array $args) : Result {
|
|
|
|
switch ($set) {
|
|
|
|
case "typical":
|
|
|
|
$set = ["--exclude-group", "optional"];
|
|
|
|
break;
|
|
|
|
case "quick":
|
|
|
|
$set = ["--exclude-group", "optional,slow"];
|
|
|
|
break;
|
2018-12-05 22:07:47 +00:00
|
|
|
case "coverage":
|
2018-12-10 17:39:09 +00:00
|
|
|
$set = ["--exclude-group", "optional,coverageOptional"];
|
2018-12-05 22:07:47 +00:00
|
|
|
break;
|
2018-08-15 13:59:07 +00:00
|
|
|
case "full":
|
|
|
|
$set = [];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new \Exception;
|
|
|
|
}
|
|
|
|
$execpath = realpath(self::BASE."vendor-bin/phpunit/vendor/phpunit/phpunit/phpunit");
|
|
|
|
$confpath = realpath(self::BASE_TEST."phpunit.xml");
|
2019-03-25 13:53:06 +00:00
|
|
|
$this->taskServer(8000)->host("localhost")->dir(self::BASE_TEST."docroot")->rawArg("-n")->arg(self::BASE_TEST."server.php")->rawArg($this->blackhole())->background()->run();
|
2018-12-08 01:03:04 +00:00
|
|
|
return $this->taskExec($executor)->arg($execpath)->option("-c", $confpath)->args(array_merge($set, $args))->run();
|
2018-08-15 13:59:07 +00:00
|
|
|
}
|
|
|
|
|
2017-12-22 16:41:54 +00:00
|
|
|
/** Packages a given commit of the software into a release tarball
|
|
|
|
*
|
2017-12-17 16:37:07 +00:00
|
|
|
* The version 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".
|
2017-12-22 16:41:54 +00:00
|
|
|
*
|
2017-12-17 16:37:07 +00:00
|
|
|
* Note that while it is possible to re-package old versions, the resultant tarball
|
2017-12-22 16:41:54 +00:00
|
|
|
* may not be equivalent due to subsequent changes in the exclude list, or because
|
2017-12-17 16:37:07 +00:00
|
|
|
* of new tooling.
|
|
|
|
*/
|
|
|
|
public function package(string $version = null): Result {
|
2017-12-08 19:37:49 +00:00
|
|
|
// establish which commit to package
|
2017-12-17 16:37:07 +00:00
|
|
|
$version = $version ?? $this->askDefault("Commit to package:", "head");
|
2017-12-08 19:37:49 +00:00
|
|
|
$archive = self::BASE."arsse-$version.tar.gz";
|
|
|
|
// start a collection
|
|
|
|
$t = $this->collectionBuilder();
|
|
|
|
// create a temporary directory
|
|
|
|
$dir = $t->tmpDir().\DIRECTORY_SEPARATOR;
|
|
|
|
// create a Git worktree for the selected commit in the temp location
|
|
|
|
$t->taskExec("git worktree add ".escapeshellarg($dir)." ".escapeshellarg($version));
|
|
|
|
// perform Composer installation in the temp location
|
|
|
|
$t->taskComposerInstall()->dir($dir)->noDev()->optimizeAutoloader()->arg("--no-scripts");
|
|
|
|
// delete unwanted files
|
|
|
|
$t->taskFilesystemStack()->remove([
|
|
|
|
$dir.".git",
|
|
|
|
$dir.".gitignore",
|
|
|
|
$dir.".gitattributes",
|
|
|
|
$dir."composer.json",
|
|
|
|
$dir."composer.lock",
|
|
|
|
$dir.".php_cs.dist",
|
|
|
|
$dir."phpdoc.dist.xml",
|
|
|
|
$dir."build.xml",
|
|
|
|
$dir."RoboFile.php",
|
|
|
|
$dir."CONTRIBUTING.md",
|
|
|
|
$dir."tests",
|
|
|
|
$dir."vendor-bin",
|
2017-12-08 20:22:37 +00:00
|
|
|
$dir."robo",
|
|
|
|
$dir."robo.bat",
|
2017-12-08 19:37:49 +00:00
|
|
|
]);
|
|
|
|
// generate a sample configuration file
|
2019-01-22 22:49:14 +00:00
|
|
|
$t->taskExec(escapeshellarg(\PHP_BINARY)." arsse.php conf save-defaults config.defaults.php")->dir($dir);
|
2017-12-08 19:37:49 +00:00
|
|
|
// package it all up
|
|
|
|
$t->taskPack($archive)->addDir("arsse", $dir);
|
|
|
|
// execute the collection
|
|
|
|
$out = $t->run();
|
|
|
|
// clean the Git worktree list
|
|
|
|
$this->_exec("git worktree prune");
|
|
|
|
return $out;
|
|
|
|
}
|
2019-01-22 22:49:14 +00:00
|
|
|
|
2019-01-25 21:56:05 +00:00
|
|
|
/** Generates static manual pages in the "manual" directory
|
|
|
|
*
|
|
|
|
* The resultant files are suitable for offline viewing and inclusion into release builds
|
|
|
|
*/
|
2019-01-22 22:49:14 +00:00
|
|
|
public function manual(array $args): Result {
|
|
|
|
$execpath = escapeshellarg(realpath(self::BASE."vendor/bin/daux"));
|
|
|
|
return $this->taskExec($execpath)->arg("generate")->option("-d", self::BASE."manual")->args($args)->run();
|
|
|
|
}
|
2019-01-25 21:56:05 +00:00
|
|
|
|
|
|
|
/** Serves a live view of the manual using PHP's built-in Web server */
|
|
|
|
public function manualLive(array $args): Result {
|
|
|
|
$execpath = escapeshellarg(realpath(self::BASE."vendor/bin/daux"));
|
|
|
|
return $this->taskExec($execpath)->arg("serve")->args($args)->run();
|
|
|
|
}
|
2019-08-02 15:15:48 +00:00
|
|
|
|
|
|
|
/** Rebuilds the manual theme
|
|
|
|
*
|
|
|
|
* This requires Node and Yarn to be installed, and only needs to be done when
|
|
|
|
* Daux's theme changes
|
|
|
|
*/
|
|
|
|
public function manualTheme(array $args): Result {
|
2019-08-04 14:57:05 +00:00
|
|
|
$languages = ["php", "bash", "shell", "xml", "nginx", "apache"];
|
|
|
|
$themesrc = realpath(self::BASE."docs/theme/src/").\DIRECTORY_SEPARATOR;
|
|
|
|
$themeout = realpath(self::BASE."docs/theme/arsse/").\DIRECTORY_SEPARATOR;
|
|
|
|
$dauxjs = realpath(self::BASE."vendor-bin/daux/vendor/daux/daux.io/themes/daux/js/").\DIRECTORY_SEPARATOR;
|
|
|
|
$dauxout = realpath(self::BASE."docs/theme/daux/js/").\DIRECTORY_SEPARATOR;
|
2019-08-03 02:34:41 +00:00
|
|
|
// start a collection; this stops after the first failure
|
|
|
|
$t = $this->collectionBuilder();
|
|
|
|
$tmp = $t->tmpDir().\DIRECTORY_SEPARATOR;
|
2019-08-04 15:02:33 +00:00
|
|
|
// rebuild the stylesheet
|
|
|
|
$t->addCode([$this, "manualCss"]);
|
2019-08-04 14:57:05 +00:00
|
|
|
// copy JavaScript files from the Daux theme
|
|
|
|
foreach(glob($dauxjs."daux*") as $file) {
|
|
|
|
$t->taskFilesystemStack()->copy($file, $themeout.basename($file), true);
|
|
|
|
}
|
|
|
|
foreach(glob($dauxjs."jquery*") as $file) {
|
|
|
|
$t->taskFilesystemStack()->copy($file, $themeout.basename("jquery.min.js"), true);
|
|
|
|
}
|
|
|
|
foreach(glob($dauxjs."html5shiv*") as $file) {
|
|
|
|
$t->taskFilesystemStack()->copy($file, $dauxout.basename($file), true);
|
|
|
|
}
|
2019-08-03 02:34:41 +00:00
|
|
|
// download highlight.js
|
2019-08-04 14:57:05 +00:00
|
|
|
$t->addCode(function() use ($languages, $tmp, $themeout) {
|
2019-08-04 02:06:57 +00:00
|
|
|
$post = http_build_query((function($langs) {
|
|
|
|
$out = [];
|
|
|
|
foreach($langs as $l) {
|
|
|
|
$out[$l.".js"] = "on";
|
2019-08-03 02:34:41 +00:00
|
|
|
}
|
2019-08-04 02:06:57 +00:00
|
|
|
return $out;
|
|
|
|
})($languages));
|
|
|
|
$conn = @fopen("https://highlightjs.org/download/", "r");
|
|
|
|
if ($conn === false) {
|
|
|
|
throw new Exception("Unable to download Highlight.js");
|
|
|
|
}
|
|
|
|
foreach (stream_get_meta_data($conn)['wrapper_data'] as $field) {
|
|
|
|
if (preg_match("/^Set-Cookie: csrftoken=([^;]+)/i", $field, $cookie)) {
|
|
|
|
break;
|
2019-08-03 02:34:41 +00:00
|
|
|
}
|
2019-08-04 02:06:57 +00:00
|
|
|
}
|
|
|
|
$token = stream_get_contents($conn);
|
|
|
|
preg_match("/<input type='hidden' name='csrfmiddlewaretoken' value='([^']*)'/", $token, $token);
|
|
|
|
$post = "csrfmiddlewaretoken={$token[1]}&$post";
|
|
|
|
$hljs = @file_get_contents("https://highlightjs.org/download/", false, stream_context_create(['http' => [
|
|
|
|
'method' => "POST",
|
|
|
|
'content' => $post,
|
|
|
|
'header' => [
|
|
|
|
"Referer: https://highlightjs.org/download/",
|
|
|
|
"Cookie: csrftoken={$cookie[1]}",
|
|
|
|
"Content-Type: application/x-www-form-urlencoded",
|
|
|
|
],
|
|
|
|
]]));
|
|
|
|
if ($hljs === false) {
|
|
|
|
throw new Exception("Unable to download Highlight.js");
|
|
|
|
} else {
|
|
|
|
file_put_contents($tmp."highlightjs.zip", $hljs);
|
|
|
|
}
|
|
|
|
$this->taskExtract($tmp."highlightjs.zip")->to($tmp."hljs")->run();
|
2019-08-04 14:57:05 +00:00
|
|
|
$this->taskFilesystemStack()->copy($tmp."hljs".\DIRECTORY_SEPARATOR."highlight.pack.js", $themeout."highlight.pack.js")->run();
|
2019-08-04 02:06:57 +00:00
|
|
|
}, "downloadHighlightjs");
|
2019-08-03 02:34:41 +00:00
|
|
|
// execute the collection
|
|
|
|
return $t->run();
|
2019-08-02 15:15:48 +00:00
|
|
|
}
|
2019-08-04 15:02:33 +00:00
|
|
|
|
|
|
|
/** Rebuilds the manual theme's stylesheet only
|
|
|
|
*
|
|
|
|
* This requires Node and Yarn to be installed.
|
|
|
|
*/
|
|
|
|
public function manualCss(): Result {
|
|
|
|
$postcss = escapeshellarg(realpath(self::BASE."node_modules/.bin/postcss"));
|
|
|
|
$themesrc = realpath(self::BASE."docs/theme/src/").\DIRECTORY_SEPARATOR;
|
|
|
|
$themeout = realpath(self::BASE."docs/theme/arsse/").\DIRECTORY_SEPARATOR;
|
|
|
|
// start a collection; this stops after the first failure
|
|
|
|
$t = $this->collectionBuilder();
|
|
|
|
$tmp = $t->tmpDir().\DIRECTORY_SEPARATOR;
|
|
|
|
// install dependencies via Yarn
|
|
|
|
$t->taskExec("yarn install");
|
|
|
|
// compile the stylesheet
|
|
|
|
$t->taskExec($postcss)->arg($themesrc."arsse.scss")->option("-o", $themeout."arsse.css");
|
|
|
|
// execute the collection
|
|
|
|
return $t->run();
|
|
|
|
}
|
2017-12-22 16:41:54 +00:00
|
|
|
}
|