├── LICENSE ├── composer-dependency-analyser.php ├── composer.json ├── phpunit.xml.dist └── src ├── autoload.php ├── recipe └── setono_cron.php └── task └── setono_cron.php /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 Setono 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /composer-dependency-analyser.php: -------------------------------------------------------------------------------- 1 | addPathToScan(__DIR__ . '/src', false) 8 | ->addPathToExclude(__DIR__ . '/vendor') 9 | ; 10 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "setono/deployer-cron", 3 | "description": "Use the Setono cron builder to generate cron files in your deployment process", 4 | "license": "MIT", 5 | "type": "library", 6 | "authors": [ 7 | { 8 | "name": "Joachim Løvgaard", 9 | "email": "joachim@loevgaard.dk" 10 | } 11 | ], 12 | "require": { 13 | "php": ">=8.1", 14 | "deployer/deployer": "^7.5.12", 15 | "setono/cron-builder": "^1.0@beta", 16 | "webmozart/assert": "^1.10" 17 | }, 18 | "require-dev": { 19 | "setono/code-quality-pack": "^2.9", 20 | "shipmonk/composer-dependency-analyser": "^1.8.2" 21 | }, 22 | "prefer-stable": true, 23 | "autoload": { 24 | "psr-4": { 25 | "Setono\\Deployer\\Cron\\": "src/" 26 | }, 27 | "files": [ 28 | "src/autoload.php" 29 | ] 30 | }, 31 | "autoload-dev": { 32 | "psr-4": { 33 | "Deployer\\": "vendor/deployer/deployer/src/" 34 | }, 35 | "files": [ 36 | "vendor/deployer/deployer/src/functions.php" 37 | ] 38 | }, 39 | "config": { 40 | "allow-plugins": { 41 | "dealerdirect/phpcodesniffer-composer-installer": false, 42 | "ergebnis/composer-normalize": true 43 | }, 44 | "sort-packages": true 45 | }, 46 | "scripts": { 47 | "analyse": "psalm", 48 | "check-style": "ecs check", 49 | "fix-style": "ecs check --fix", 50 | "phpunit": "phpunit" 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | tests 8 | 9 | 10 | 11 | 12 | src/ 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/autoload.php: -------------------------------------------------------------------------------- 1 | /dev/null || true', $cronUser !== '' ? (' -u ' . $cronUser) : '')); 64 | 65 | file_put_contents(get('crontab_backup_filename'), $crontab); 66 | })->desc('Backups the old crontab and stores it locally'); 67 | 68 | task('cron:apply', static function (): void { 69 | $cronUser = getCronUser(); 70 | 71 | $cronBuilder = new CronBuilder(get('cron_config_dir')); 72 | $cronBuilder->delimiter = get('cron_delimiter'); 73 | 74 | foreach (Deployer::get()->config->ownValues() as $key => $value) { 75 | if (is_callable($value)) { 76 | continue; 77 | } 78 | 79 | $cronBuilder->context->set($key, get($key)); 80 | } 81 | 82 | if (Context::has()) { 83 | $context = Context::get(); 84 | if (false !== $context) { 85 | foreach ($context->getConfig()->ownValues() as $key => $value) { 86 | if (is_callable($value)) { 87 | continue; 88 | } 89 | 90 | $cronBuilder->context->set($key, get($key)); 91 | } 92 | } 93 | } 94 | 95 | $existingCrontab = file_get_contents(get('crontab_backup_filename')); 96 | Assert::string($existingCrontab); 97 | 98 | file_put_contents(get('crontab_filename'), CronBuilder::merge($existingCrontab, $cronBuilder)); 99 | 100 | upload(get('crontab_filename'), '{{release_path}}/{{crontab_filename}}'); 101 | run(sprintf('cat {{release_path}}/{{crontab_filename}} | crontab%s -', $cronUser !== '' ? (' -u ' . $cronUser) : '')); 102 | }); 103 | 104 | task('cron:cleanup', static function (): void { 105 | if (file_exists(get('crontab_filename'))) { 106 | @unlink(get('crontab_filename')); 107 | } 108 | 109 | if (file_exists(get('crontab_backup_filename'))) { 110 | @unlink(get('crontab_backup_filename')); 111 | } 112 | }); 113 | 114 | function getCronUser(): string 115 | { 116 | $cronUser = get('cron_user'); 117 | Assert::string($cronUser); 118 | 119 | return $cronUser; 120 | } 121 | --------------------------------------------------------------------------------