mirror of
https://github.com/Azure/k8s-deploy.git
synced 2026-04-17 20:32:20 +08:00
* Added timeout to the rollout status and tests for it * Fixed integration test errors * Fix for blue green integration test * Probable fix for integration errors * No jobs run error fixed * Changed timeout to file level constant * Added parsing logic for timeout * Made tests more concise * implemented timeout validation check in an extracted utils mod * Changed function name to parseDuration * Removed timeout parameter from getResource --------- Co-authored-by: David Gamero <david340804@gmail.com> Co-authored-by: Suneha Bose <123775811+bosesuneha@users.noreply.github.com>
39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
import * as core from '@actions/core'
|
|
|
|
export function parseDuration(duration: string): string {
|
|
const trimmed = duration.trim()
|
|
|
|
// Parse number and optional unit using regex
|
|
const match = /^(\d+(?:\.\d+)?)(ms|s|m|h)?$/i.exec(trimmed)
|
|
if (!match) {
|
|
throw new Error(
|
|
`Invalid duration format: "${duration}". Use: number + unit (30s, 5m, 1h) or just number (assumes minutes)`
|
|
)
|
|
}
|
|
|
|
const value = parseFloat(match[1])
|
|
const unit = match[2]?.toLowerCase() || 'm'
|
|
|
|
if (value <= 0) {
|
|
throw new Error(`Duration must be positive: "${duration}"`)
|
|
}
|
|
|
|
// Calculate total seconds for validation
|
|
const multipliers = {ms: 0.001, s: 1, m: 60, h: 3600}
|
|
const totalSeconds = value * multipliers[unit as keyof typeof multipliers]
|
|
|
|
// Validate bounds (1ms to 24h)
|
|
if (totalSeconds < 0.001 || totalSeconds > 86400) {
|
|
throw new Error(`Duration out of range (1ms to 24h): "${duration}"`)
|
|
}
|
|
|
|
// Log assumption for bare numbers (when no unit was provided)
|
|
if (!duration.trim().match(/\d+(ms|s|m|h)$/i)) {
|
|
core.debug(
|
|
`No unit specified for timeout "${duration}", assuming minutes`
|
|
)
|
|
}
|
|
|
|
return `${value}${unit}`
|
|
}
|