From 9aebe8478300679e3116ac57900b2ab6b3d302e9 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Fri, 15 Jul 2022 12:33:06 +1200 Subject: [PATCH] MNT Use GitHub Actions CI --- .github/workflows/ci.yml | 16 +++++++++++++++ .github/workflows/keepalive.yml | 17 +++++++++++++++ composer.json | 2 +- phpcs.xml.dist | 14 +++++++++++++ phpunit.xml => phpunit.xml.dist | 0 src/Manager/ProcessManager.php | 4 ++-- src/Rules/InMemoryRules.php | 25 ++++++++++++++++------- tests/Handler/CallbackHandlerTest.php | 2 +- tests/Manager/GroupProcessManagerTest.php | 2 +- tests/Manager/ProcessManagerTest.php | 2 +- tests/Manager/SynchronousManagerTest.php | 2 +- tests/Profile/InMemoryProfileTest.php | 2 +- tests/Rule/InMemoryRuleTest.php | 2 +- tests/Rules/InMemoryRulesTest.php | 2 +- tests/Shell/BashShellTest.php | 2 +- tests/Task/CallbackTaskTest.php | 2 +- tests/Task/ProcessCallbackTaskTest.php | 2 +- tests/Test.php | 4 ++-- 18 files changed, 80 insertions(+), 22 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/keepalive.yml create mode 100644 phpcs.xml.dist rename phpunit.xml => phpunit.xml.dist (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..1a7f555 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,16 @@ +name: CI + +on: + push: + pull_request: + workflow_dispatch: + # Every Monday at 2:00pm UTC + schedule: + - cron: '0 14 * * 1' + +jobs: + ci: + name: CI + # Only run cron on the silverstripe account + if: (github.event_name == 'schedule' && startsWith(github.repository, 'silverstripe/')) || (github.event_name != 'schedule') + uses: silverstripe/gha-ci/.github/workflows/ci.yml@v1 diff --git a/.github/workflows/keepalive.yml b/.github/workflows/keepalive.yml new file mode 100644 index 0000000..ebf9716 --- /dev/null +++ b/.github/workflows/keepalive.yml @@ -0,0 +1,17 @@ +name: Keepalive + +on: + workflow_dispatch: + # The 4th of every month at 10:50am UTC + schedule: + - cron: '50 10 4 * *' + +jobs: + keepalive: + name: Keepalive + # Only run cron on the silverstripe account + if: (github.event_name == 'schedule' && startsWith(github.repository, 'silverstripe/')) || (github.event_name != 'schedule') + runs-on: ubuntu-latest + steps: + - name: Keepalive + uses: silverstripe/gha-keepalive@v1 diff --git a/composer.json b/composer.json index 8368dc5..9721c4e 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "jeremeamia/superclosure": "^2.0" }, "require-dev": { - "phpunit/phpunit": "^4.8.36|^5.7.27" + "phpunit/phpunit": "^9.5" }, "autoload": { "psr-4": { diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 0000000..eff1d2e --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,14 @@ + + + CodeSniffer ruleset for SilverStripe coding conventions. + + src + tests + + + + + + + + diff --git a/phpunit.xml b/phpunit.xml.dist similarity index 100% rename from phpunit.xml rename to phpunit.xml.dist diff --git a/src/Manager/ProcessManager.php b/src/Manager/ProcessManager.php index 0d31d61..e351533 100644 --- a/src/Manager/ProcessManager.php +++ b/src/Manager/ProcessManager.php @@ -65,7 +65,7 @@ class ProcessManager implements Manager /** * Get a list of the waiting tasks. - * + * * @return array */ public function getWaiting() @@ -75,7 +75,7 @@ public function getWaiting() /** * Get a list of the running tasks. - * + * * @return array */ public function getRunning() diff --git a/src/Rules/InMemoryRules.php b/src/Rules/InMemoryRules.php index 9dea76f..0f6261d 100644 --- a/src/Rules/InMemoryRules.php +++ b/src/Rules/InMemoryRules.php @@ -69,7 +69,12 @@ public function canRunTask(Task $task, Profile $profile) continue; } - if (($rule->getHandler() === null || $rule->getHandler() === $task->getHandler()) && ($this->hasTooManyProcessesRunning($rule, $profile) || $this->hasTooManySiblingProcessesRunning($rule, $profile))) { + if (($rule->getHandler() === null || $rule->getHandler() === $task->getHandler()) && + ( + $this->hasTooManyProcessesRunning($rule, $profile) || + $this->hasTooManySiblingProcessesRunning($rule, $profile) + ) + ) { return false; } } @@ -128,7 +133,8 @@ private function withinConstraints(Rule $rule, Profile $profile) private function withinProcessorConstraints(Rule $rule, Profile $profile) { if ($rule->getMinimumProcessorUsage() !== null && $rule->getMaximumProcessorUsage() !== null) { - return $profile->getProcessorLoad() >= $rule->getMinimumProcessorUsage() && $profile->getProcessorLoad() <= $rule->getMaximumProcessorUsage(); + return $profile->getProcessorLoad() >= $rule->getMinimumProcessorUsage() && + $profile->getProcessorLoad() <= $rule->getMaximumProcessorUsage(); } return false; @@ -145,7 +151,8 @@ private function withinProcessorConstraints(Rule $rule, Profile $profile) private function withinMemoryConstraints(Rule $rule, Profile $profile) { if ($rule->getMinimumMemoryUsage() !== null && $rule->getMaximumMemoryUsage() !== null) { - return $profile->getMemoryLoad() >= $rule->getMinimumMemoryUsage() && $profile->getMemoryLoad() <= $rule->getMaximumMemoryUsage(); + return $profile->getMemoryLoad() >= $rule->getMinimumMemoryUsage() && + $profile->getMemoryLoad() <= $rule->getMaximumMemoryUsage(); } return false; @@ -161,7 +168,8 @@ private function withinMemoryConstraints(Rule $rule, Profile $profile) */ private function hasTooManySiblingProcessesRunning(Rule $rule, Profile $profile) { - return $this->withinSiblingConstraints($rule, $profile) && count($profile->getSiblingProcesses()) >= $rule->getProcesses(); + return $this->withinSiblingConstraints($rule, $profile) && + count($profile->getSiblingProcesses()) >= $rule->getProcesses(); } /** @@ -174,7 +182,8 @@ private function hasTooManySiblingProcessesRunning(Rule $rule, Profile $profile) */ private function withinSiblingConstraints(Rule $rule, Profile $profile) { - return $this->withinSiblingProcessorConstraints($rule, $profile) || $this->withinSiblingMemoryConstraints($rule, $profile); + return $this->withinSiblingProcessorConstraints($rule, $profile) || + $this->withinSiblingMemoryConstraints($rule, $profile); } /** @@ -189,7 +198,8 @@ private function withinSiblingConstraints(Rule $rule, Profile $profile) private function withinSiblingProcessorConstraints(Rule $rule, Profile $profile) { if ($rule->getMinimumSiblingProcessorUsage() !== null && $rule->getMaximumSiblingProcessorUsage() !== null) { - return $profile->getSiblingProcessorLoad() >= $rule->getMinimumSiblingProcessorUsage() && $profile->getSiblingProcessorLoad() <= $rule->getMaximumSiblingProcessorUsage(); + return $profile->getSiblingProcessorLoad() >= $rule->getMinimumSiblingProcessorUsage() && + $profile->getSiblingProcessorLoad() <= $rule->getMaximumSiblingProcessorUsage(); } return false; @@ -206,7 +216,8 @@ private function withinSiblingProcessorConstraints(Rule $rule, Profile $profile) private function withinSiblingMemoryConstraints(Rule $rule, Profile $profile) { if ($rule->getMinimumSiblingMemoryUsage() !== null && $rule->getMaximumSiblingMemoryUsage() !== null) { - return $profile->getSiblingMemoryLoad() >= $rule->getMinimumSiblingMemoryUsage() && $profile->getSiblingMemoryLoad() <= $rule->getMaximumSiblingMemoryUsage(); + return $profile->getSiblingMemoryLoad() >= $rule->getMinimumSiblingMemoryUsage() && + $profile->getSiblingMemoryLoad() <= $rule->getMaximumSiblingMemoryUsage(); } return false; diff --git a/tests/Handler/CallbackHandlerTest.php b/tests/Handler/CallbackHandlerTest.php index ecd0257..15700c8 100644 --- a/tests/Handler/CallbackHandlerTest.php +++ b/tests/Handler/CallbackHandlerTest.php @@ -19,7 +19,7 @@ class CallbackHandlerTest extends Test /** * @inheritdoc */ - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/tests/Manager/GroupProcessManagerTest.php b/tests/Manager/GroupProcessManagerTest.php index f1975d7..0dead00 100644 --- a/tests/Manager/GroupProcessManagerTest.php +++ b/tests/Manager/GroupProcessManagerTest.php @@ -20,7 +20,7 @@ class GroupProcessManagerTest extends Test /** * @inheritdoc */ - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/tests/Manager/ProcessManagerTest.php b/tests/Manager/ProcessManagerTest.php index cedff24..82cae84 100644 --- a/tests/Manager/ProcessManagerTest.php +++ b/tests/Manager/ProcessManagerTest.php @@ -22,7 +22,7 @@ class ProcessManagerTest extends Test /** * @inheritdoc */ - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/tests/Manager/SynchronousManagerTest.php b/tests/Manager/SynchronousManagerTest.php index bf1b52f..a2c37b2 100644 --- a/tests/Manager/SynchronousManagerTest.php +++ b/tests/Manager/SynchronousManagerTest.php @@ -19,7 +19,7 @@ class SynchronousManagerTest extends Test /** * @inheritdoc */ - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/tests/Profile/InMemoryProfileTest.php b/tests/Profile/InMemoryProfileTest.php index 003b8d2..f02a74d 100644 --- a/tests/Profile/InMemoryProfileTest.php +++ b/tests/Profile/InMemoryProfileTest.php @@ -19,7 +19,7 @@ class InMemoryProfileTest extends Test /** * @inheritdoc */ - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/tests/Rule/InMemoryRuleTest.php b/tests/Rule/InMemoryRuleTest.php index 0ef58e0..7c81ea1 100644 --- a/tests/Rule/InMemoryRuleTest.php +++ b/tests/Rule/InMemoryRuleTest.php @@ -18,7 +18,7 @@ class InMemoryRuleTest extends Test /** * @inheritdoc */ - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/tests/Rules/InMemoryRulesTest.php b/tests/Rules/InMemoryRulesTest.php index 56b0c4d..0306895 100644 --- a/tests/Rules/InMemoryRulesTest.php +++ b/tests/Rules/InMemoryRulesTest.php @@ -21,7 +21,7 @@ class InMemoryRulesTest extends Test /** * @inheritdoc */ - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/tests/Shell/BashShellTest.php b/tests/Shell/BashShellTest.php index 108e578..e3abc99 100644 --- a/tests/Shell/BashShellTest.php +++ b/tests/Shell/BashShellTest.php @@ -18,7 +18,7 @@ class BashShellTest extends Test /** * @inheritdoc */ - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/tests/Task/CallbackTaskTest.php b/tests/Task/CallbackTaskTest.php index 4ac63c2..39ce600 100644 --- a/tests/Task/CallbackTaskTest.php +++ b/tests/Task/CallbackTaskTest.php @@ -23,7 +23,7 @@ class CallbackTaskTest extends Test /** * @inheritdoc */ - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/tests/Task/ProcessCallbackTaskTest.php b/tests/Task/ProcessCallbackTaskTest.php index 00d7e95..6a6a12e 100644 --- a/tests/Task/ProcessCallbackTaskTest.php +++ b/tests/Task/ProcessCallbackTaskTest.php @@ -18,7 +18,7 @@ class ProcessCallbackTaskTest extends Test /** * @inheritdoc */ - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/tests/Test.php b/tests/Test.php index c20856e..88394dd 100644 --- a/tests/Test.php +++ b/tests/Test.php @@ -2,9 +2,9 @@ namespace AsyncPHP\Doorman\Tests; -use PHPUnit_Framework_TestCase; +use PHPUnit\Framework\TestCase; -abstract class Test extends PHPUnit_Framework_TestCase +abstract class Test extends TestCase { /** * Safely deletes a file.