Skip to content

Commit

Permalink
NEW Add dispatch-ci
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Sep 13, 2023
1 parent 03249f9 commit 4442c42
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions scripts/cms-any/dispatch-ci.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

// run on two consecutive days of the week
$dayOfWeek = predictable_random_int(6);
$nextDayOfWeek = $dayOfWeek === 6 ? 0 : $dayOfWeek + 1;
$runsOnDaysOfWeek = sprintf('%s,%s', $dayOfWeek, $nextDayOfWeek);
// run at a random hour of the day
$runOnHour = predictable_random_int(23);
// run at a random minute of the hour rounded to 5 minutes
$runOnMinute = predictable_random_int(11) * 5;

$cron = "$runOnMinute $runOnHour * * $runsOnDaysOfWeek";
$humanCron = human_cron($cron);
$account = module_account();

$content = <<<EOT
name: Dispatch CI
on:
# $humanCron
schedule:
- cron: '$cron'
jobs:
dispatch-ci:
name: Dispatch CI
# Only run cron on the $account account
if: (github.event_name == 'schedule' && github.repository_owner == '$account') || (github.event_name != 'schedule')
runs-on: ubuntu-latest
steps:
- name: Dispatch CI
uses: silverstripe/gha-dispatch-ci@v1
EOT;

if (check_file_exists('.github/workflows/ci.yml')) {
write_file_even_if_exists('.github/workflows/dispatch-ci.yml', $content);
}

0 comments on commit 4442c42

Please sign in to comment.