This commit is contained in:
Emi Huang 2025-08-21 14:27:45 -07:00
parent ff7abcd0c3
commit 9905cd6970
8 changed files with 90 additions and 2 deletions

View file

@ -257,6 +257,14 @@ class GitAuthHelper {
this.sshCommand = `"${sshPath}" -i "$RUNNER_TEMP/${path.basename(
this.sshKeyPath
)}"`
// Apply SSH ConnectTimeout if input timeout is set
const parsedTimeout = Math.floor(
Number(process.env['INPUT_TIMEOUT'] || '0')
)
if (!isNaN(parsedTimeout) && parsedTimeout > 0) {
// OpenSSH ConnectTimeout is in seconds
this.sshCommand += ` -o ConnectTimeout=${parsedTimeout}`
}
if (this.settings.sshStrict) {
this.sshCommand += ' -o StrictHostKeyChecking=yes -o CheckHostIP=no'
}

View file

@ -539,6 +539,14 @@ class GitCommandManager {
listeners: mergedListeners
}
// Apply timeout from input (seconds -> ms). 0 disables.
const parsedTimeout = Math.floor(
Number(process.env['INPUT_TIMEOUT'] || '0')
)
if (!isNaN(parsedTimeout) && parsedTimeout > 0) {
;(options as any).timeout = parsedTimeout * 1000
}
result.exitCode = await exec.exec(`"${this.gitPath}"`, args, options)
result.stdout = stdout.join('')

View file

@ -118,4 +118,14 @@ export interface IGitSourceSettings {
* User override on the GitHub Server/Host URL that hosts the repository to be cloned
*/
githubServerUrl: string | undefined
/**
* Timeout in seconds for individual git/network operations (0 disables)
*/
timeout?: number
/**
* Maximum number of retry attempts for flaky operations (min 1)
*/
retry?: number
}

View file

@ -161,5 +161,23 @@ export async function getInputs(): Promise<IGitSourceSettings> {
result.githubServerUrl = core.getInput('github-server-url')
core.debug(`GitHub Host URL = ${result.githubServerUrl}`)
// Retry attempts (min 1)
const retryInput = core.getInput('retry') || '3'
let retry = Math.floor(Number(retryInput))
if (isNaN(retry) || retry < 1) {
retry = 1
}
result.retry = retry
core.debug(`retry = ${result.retry}`)
// Timeout seconds (0 disables)
const timeoutInput = core.getInput('timeout') || '0'
let timeout = Math.floor(Number(timeoutInput))
if (isNaN(timeout) || timeout < 0) {
timeout = 0
}
result.timeout = timeout
core.debug(`timeout = ${result.timeout}`)
return result
}

View file

@ -1,6 +1,7 @@
import * as core from '@actions/core'
const defaultMaxAttempts = 3
const parsedRetry = Math.floor(Number(process.env['INPUT_RETRY'] || ''))
const defaultMaxAttempts = !isNaN(parsedRetry) && parsedRetry > 0 ? parsedRetry : 3
const defaultMinSeconds = 10
const defaultMaxSeconds = 20