The clean & modern RSS server that doesn't give you any crap. https://thearsse.com/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RoboFile.php 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php
  2. use Robo\Result;
  3. class RoboFile extends \Robo\Tasks {
  4. const BASE = __DIR__.\DIRECTORY_SEPARATOR;
  5. const BASE_TEST = self::BASE."tests".\DIRECTORY_SEPARATOR;
  6. /**
  7. * Runs the typical test suite
  8. *
  9. * Arguments passed to the task are passed on to PHPUnit. Thus one may, for
  10. * example, run the following command and get the expected results:
  11. *
  12. * ./robo test --testsuite TTRSS --exclude-group slow --testdox
  13. *
  14. * Please see the PHPUnit documentation for available options.
  15. */
  16. public function test(array $args): Result {
  17. return $this->runTests("php", "typical", $args);
  18. }
  19. /**
  20. * Runs the full test suite
  21. *
  22. * This includes pedantic tests which may help to identify problems.
  23. * See help for the "test" task for more details.
  24. */
  25. public function testFull(array $args): Result {
  26. return $this->runTests("php", "full", $args);
  27. }
  28. /**
  29. * Runs a quick subset of the test suite
  30. *
  31. * See help for the "test" task for more details.
  32. */
  33. public function testQuick(array $args): Result {
  34. return $this->runTests("php", "quick", $args);
  35. }
  36. /** Produces a code coverage report
  37. *
  38. * By default this task produces an HTML-format coverage report in
  39. * tests/coverage/. Additional reports may be produced by passing
  40. * arguments to this task as one would to PHPUnit.
  41. *
  42. * Robo first tries to use phpdbg and will fall back to Xdebug if available.
  43. * Because Xdebug slows down non-coverage tasks, however, phpdbg is highly
  44. * recommended if debugging facilities are not otherwise needed.
  45. */
  46. public function coverage(array $args): Result {
  47. // run tests with code coverage reporting enabled
  48. $exec = $this->findCoverageEngine();
  49. return $this->runTests($exec, "coverage", array_merge(["--coverage-html", self::BASE_TEST."coverage"], $args));
  50. }
  51. /** Produces a code coverage report, with redundant tests
  52. *
  53. * Depending on the environment, some tests that normally provide
  54. * coverage may be skipped, while working alternatives are normally
  55. * suppressed for reasons of time. This coverage report will try to
  56. * run all tests which may cover code.
  57. *
  58. * See also help for the "coverage" task for more details.
  59. */
  60. public function coverageFull(array $args): Result {
  61. // run tests with code coverage reporting enabled
  62. $exec = $this->findCoverageEngine();
  63. return $this->runTests($exec, "typical", array_merge(["--coverage-html", self::BASE_TEST."coverage"], $args));
  64. }
  65. /** Runs the coding standards fixer */
  66. public function clean($opts = ['demo|d' => false]): Result {
  67. $t = $this->taskExec(realpath(self::BASE."vendor/bin/php-cs-fixer"));
  68. $t->arg("fix");
  69. if ($opts['demo']) {
  70. $t->args("--dry-run", "--diff")->option("--diff-format", "udiff");
  71. }
  72. return $t->run();
  73. }
  74. protected function findCoverageEngine(): string {
  75. $null = null;
  76. $code = 0;
  77. exec("phpdbg --version", $null, $code);
  78. if (!$code) {
  79. return "phpdbg -qrr";
  80. } else {
  81. return "php";
  82. }
  83. }
  84. protected function isWindows(): bool {
  85. return defined("PHP_WINDOWS_VERSION_MAJOR");
  86. }
  87. protected function runTests(string $executor, string $set, array $args) : Result {
  88. switch ($set) {
  89. case "typical":
  90. $set = ["--exclude-group", "optional"];
  91. break;
  92. case "quick":
  93. $set = ["--exclude-group", "optional,slow"];
  94. break;
  95. case "coverage":
  96. $set = ["--exclude-group", "optional,excludeFromCoverage"];
  97. break;
  98. case "full":
  99. $set = [];
  100. break;
  101. default:
  102. throw new \Exception;
  103. }
  104. $execpath = realpath(self::BASE."vendor-bin/phpunit/vendor/phpunit/phpunit/phpunit");
  105. $confpath = realpath(self::BASE_TEST."phpunit.xml");
  106. $blackhole = $this->isWindows() ? "nul" : "/dev/null";
  107. $this->taskServer(8000)->host("localhost")->dir(self::BASE_TEST."docroot")->rawArg("-n")->arg(self::BASE_TEST."server.php")->background()->run();
  108. return $this->taskExec($executor)->arg($execpath)->option("-c", $confpath)->args(array_merge($set, $args))->rawArg("2>$blackhole")->run();
  109. }
  110. /** Packages a given commit of the software into a release tarball
  111. *
  112. * The version to package may be any Git tree-ish identifier: a tag, a branch,
  113. * or any commit hash. If none is provided on the command line, Robo will prompt
  114. * for a commit to package; the default is "head".
  115. *
  116. * Note that while it is possible to re-package old versions, the resultant tarball
  117. * may not be equivalent due to subsequent changes in the exclude list, or because
  118. * of new tooling.
  119. */
  120. public function package(string $version = null): Result {
  121. // establish which commit to package
  122. $version = $version ?? $this->askDefault("Commit to package:", "head");
  123. $archive = self::BASE."arsse-$version.tar.gz";
  124. // start a collection
  125. $t = $this->collectionBuilder();
  126. // create a temporary directory
  127. $dir = $t->tmpDir().\DIRECTORY_SEPARATOR;
  128. // create a Git worktree for the selected commit in the temp location
  129. $t->taskExec("git worktree add ".escapeshellarg($dir)." ".escapeshellarg($version));
  130. // perform Composer installation in the temp location
  131. $t->taskComposerInstall()->dir($dir)->noDev()->optimizeAutoloader()->arg("--no-scripts");
  132. // delete unwanted files
  133. $t->taskFilesystemStack()->remove([
  134. $dir.".git",
  135. $dir.".gitignore",
  136. $dir.".gitattributes",
  137. $dir."composer.json",
  138. $dir."composer.lock",
  139. $dir.".php_cs.dist",
  140. $dir."phpdoc.dist.xml",
  141. $dir."build.xml",
  142. $dir."RoboFile.php",
  143. $dir."CONTRIBUTING.md",
  144. $dir."tests",
  145. $dir."vendor-bin",
  146. $dir."robo",
  147. $dir."robo.bat",
  148. ]);
  149. // generate a sample configuration file
  150. $t->taskExec("php arsse.php conf save-defaults config.defaults.php")->dir($dir);
  151. // package it all up
  152. $t->taskPack($archive)->addDir("arsse", $dir);
  153. // execute the collection
  154. $out = $t->run();
  155. // clean the Git worktree list
  156. $this->_exec("git worktree prune");
  157. return $out;
  158. }
  159. }