Hourly scheduled builds via a ??:MM slot
`atTimes: ["??:05"]` runs a build five past every hour. The pattern expands to its 24 concrete slots before the due-slot match, so each hour is its own slot in the trigger state and fires once — the existing per-slot semantics carry over unchanged, including that only the latest due slot of a day triggers and that a slot whose pool is still building is retried until it starts. Only the hour may be a wildcard; anything else is skipped with a warning. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
08a8a0bbb4
commit
939d8eeb9c
@@ -162,7 +162,7 @@ class InitCommand(
|
||||
# Example definition — triggers (onPush/atTimes), branch selector
|
||||
# (branches/activeWithin), and overrides of the branch settings:
|
||||
# pitest:
|
||||
# atTimes: ["01:00"] # daily UTC times HH:MM
|
||||
# atTimes: ["01:00"] # daily UTC times HH:MM ("??:05" = every hour at :05)
|
||||
# branches: ["master"] # names or glob patterns; default: all branches
|
||||
# activeWithin: 24h # only branches with recent commits
|
||||
# buildCommand: ./gradlew piTestFull
|
||||
|
||||
@@ -16,7 +16,11 @@ import java.time.Instant
|
||||
data class BuildDefinition(
|
||||
/** Build every new commit of the selected branches. */
|
||||
val onPush: Boolean = false,
|
||||
/** Daily UTC times `HH:MM`; each slot rebuilds the selected branches' heads once per day. */
|
||||
/**
|
||||
* Daily UTC times `HH:MM`; each slot rebuilds the selected branches' heads once per day.
|
||||
* `??:MM` is the hourly form — it stands for that minute of every hour, so each of its
|
||||
* 24 slots triggers separately.
|
||||
*/
|
||||
val atTimes: List<String> = emptyList(),
|
||||
/**
|
||||
* Branch names or glob patterns (`*` matches any characters, also across `/`);
|
||||
|
||||
@@ -29,22 +29,41 @@ data class AutoBuildTrigger(
|
||||
object AutoBuildSlots {
|
||||
private val log = LoggerFactory.getLogger(AutoBuildSlots::class.java)
|
||||
|
||||
/** The latest valid slot at or before [now], or null when no slot is due yet today. */
|
||||
/**
|
||||
* The latest valid slot at or before [now], or null when no slot is due yet today.
|
||||
* The returned slot is always a concrete `HH:MM` — an hourly pattern is expanded
|
||||
* first, so each of its hours triggers separately.
|
||||
*/
|
||||
fun latestDueSlot(
|
||||
times: List<String>,
|
||||
now: LocalTime,
|
||||
): String? =
|
||||
times
|
||||
.flatMap { expand(it) }
|
||||
.mapNotNull { slot ->
|
||||
try {
|
||||
LocalTime.parse(slot.trim()) to slot
|
||||
LocalTime.parse(slot) to slot
|
||||
} catch (_: DateTimeParseException) {
|
||||
log.warn("skipping invalid scheduled-build time slot '{}': expected HH:MM", slot)
|
||||
log.warn("skipping invalid scheduled-build time slot '{}': expected HH:MM or ??:MM", slot)
|
||||
null
|
||||
}
|
||||
}.filter { (parsed, _) -> !parsed.isAfter(now) }
|
||||
.maxByOrNull { (parsed, _) -> parsed }
|
||||
?.second
|
||||
|
||||
/** `??:MM` means every hour at that minute and expands to its 24 slots; `HH:MM` is itself. */
|
||||
private fun expand(time: String): List<String> {
|
||||
val slot = time.trim()
|
||||
if (!slot.startsWith("??:")) {
|
||||
return listOf(slot)
|
||||
}
|
||||
val minute = slot.substringAfter(':').toIntOrNull()
|
||||
if (minute == null || minute !in 0..59) {
|
||||
log.warn("skipping invalid scheduled-build time slot '{}': expected ??:MM with MM from 00 to 59", slot)
|
||||
return emptyList()
|
||||
}
|
||||
return (0..23).map { hour -> "%02d:%02d".format(hour, minute) }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user