Skip to content

Commit

Permalink
NEW Add merge-ups
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Aug 9, 2023
1 parent 98fe0ab commit 768892c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"require": {
"php": ">=7.4",
"symfony/console": "^6.3",
"symfony/process": "^6.3"
"symfony/process": "^6.3",
"panlatent/cron-expression-descriptor": "^1"
},
"require-dev": {
"phpunit/phpunit": "^9.5"
Expand Down
51 changes: 51 additions & 0 deletions scripts/cms5/merge-ups.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

// run 3 days offset from when a weekly CI run is, otherwise run on a random day of the week
$runOnDay = rand(0, 6);
// run at the same hour as the weekly CI run, otherwise run at a random hour of the day
$runOnHour = rand(0, 23);
// run at the same minute as the weekly CI run, otherwise run at the top of the hour
$runOnMinute = 0;

if (check_file_exists('.github/workflows/dispatch-ci.yml')) {
$ci = read_file('.github/workflows/dispatch-ci.yml');
preg_match("#- cron: '(.+?) (.+?) (.+?) (.+?) (.+?)'#", $ci, $matches);
[$_, $minute, $hour, $day, $month, $dayOfWeek] = $matches;
if ($dayOfWeek !== '*') {
$days = explode(',', $dayOfWeek);
$runOnDay = ($days[count($days) - 1] + 3) % 7;
}
if ($hour !== '*') {
$hours = explode(',', $hour);
$runOnHour = $hours[0];
}
if ($minute !== '*') {
$runOnMinute = $minute;
}
}

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

$content = <<<EOT
name: Merge-up
on:
# $humanCron
schedule:
- cron: '$cron'
workflow_dispatch:
jobs:
merge-up:
name: Merge-up
# 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: Merge-up
uses: silverstripe/gha-merge-up@v1
EOT;

write_file_if_not_exist('.github/workflows/merge-ups.yml', $content);

0 comments on commit 768892c

Please sign in to comment.