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 5.8KB

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