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.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. if ($this->isWindows()) {
  76. $dbg = dirname(\PHP_BINARY)."\\phpdbg.exe";
  77. $dbg = file_exists($dbg) ? $dbg : "";
  78. } else {
  79. $dbg = trim(`which phpdbg`);
  80. }
  81. if ($dbg) {
  82. return escapeshellarg($dbg)." -qrr";
  83. } else {
  84. return escapeshellarg(\PHP_BINARY);
  85. }
  86. }
  87. protected function isWindows(): bool {
  88. return defined("PHP_WINDOWS_VERSION_MAJOR");
  89. }
  90. protected function runTests(string $executor, string $set, array $args) : Result {
  91. switch ($set) {
  92. case "typical":
  93. $set = ["--exclude-group", "optional"];
  94. break;
  95. case "quick":
  96. $set = ["--exclude-group", "optional,slow"];
  97. break;
  98. case "coverage":
  99. $set = ["--exclude-group", "optional,coverageOptional"];
  100. break;
  101. case "full":
  102. $set = [];
  103. break;
  104. default:
  105. throw new \Exception;
  106. }
  107. $execpath = realpath(self::BASE."vendor-bin/phpunit/vendor/phpunit/phpunit/phpunit");
  108. $confpath = realpath(self::BASE_TEST."phpunit.xml");
  109. $this->taskServer(8000)->host("localhost")->dir(self::BASE_TEST."docroot")->rawArg("-n")->arg(self::BASE_TEST."server.php")->background()->run();
  110. return $this->taskExec($executor)->arg($execpath)->option("-c", $confpath)->args(array_merge($set, $args))->run();
  111. }
  112. /** Packages a given commit of the software into a release tarball
  113. *
  114. * The version to package may be any Git tree-ish identifier: a tag, a branch,
  115. * or any commit hash. If none is provided on the command line, Robo will prompt
  116. * for a commit to package; the default is "head".
  117. *
  118. * Note that while it is possible to re-package old versions, the resultant tarball
  119. * may not be equivalent due to subsequent changes in the exclude list, or because
  120. * of new tooling.
  121. */
  122. public function package(string $version = null): Result {
  123. // establish which commit to package
  124. $version = $version ?? $this->askDefault("Commit to package:", "head");
  125. $archive = self::BASE."arsse-$version.tar.gz";
  126. // start a collection
  127. $t = $this->collectionBuilder();
  128. // create a temporary directory
  129. $dir = $t->tmpDir().\DIRECTORY_SEPARATOR;
  130. // create a Git worktree for the selected commit in the temp location
  131. $t->taskExec("git worktree add ".escapeshellarg($dir)." ".escapeshellarg($version));
  132. // perform Composer installation in the temp location
  133. $t->taskComposerInstall()->dir($dir)->noDev()->optimizeAutoloader()->arg("--no-scripts");
  134. // delete unwanted files
  135. $t->taskFilesystemStack()->remove([
  136. $dir.".git",
  137. $dir.".gitignore",
  138. $dir.".gitattributes",
  139. $dir."composer.json",
  140. $dir."composer.lock",
  141. $dir.".php_cs.dist",
  142. $dir."phpdoc.dist.xml",
  143. $dir."build.xml",
  144. $dir."RoboFile.php",
  145. $dir."CONTRIBUTING.md",
  146. $dir."tests",
  147. $dir."vendor-bin",
  148. $dir."robo",
  149. $dir."robo.bat",
  150. ]);
  151. // generate a sample configuration file
  152. $t->taskExec("php arsse.php conf save-defaults config.defaults.php")->dir($dir);
  153. // package it all up
  154. $t->taskPack($archive)->addDir("arsse", $dir);
  155. // execute the collection
  156. $out = $t->run();
  157. // clean the Git worktree list
  158. $this->_exec("git worktree prune");
  159. return $out;
  160. }
  161. }