Skip to content

Commit

Permalink
Merge pull request #22 from creative-commoners/pulls/main/dispatch-ci
Browse files Browse the repository at this point in the history
NEW Add dispatch-ci
  • Loading branch information
GuySartorelli authored Sep 13, 2023
2 parents 03249f9 + 4442c42 commit d25f57d
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 d25f57d

Please sign in to comment.