fix: restrict remote prune to self-hosted runners (#4250)

This commit is contained in:
Peter Evans
2025-12-05 17:14:47 +00:00
committed by GitHub
parent d4f3be6ce6
commit 22a9089034
3 changed files with 26 additions and 12 deletions

View File

@@ -121,12 +121,14 @@ export async function createPullRequest(inputs: Inputs): Promise<void> {
`The 'base' and 'branch' for a pull request must be different branches. Unable to continue.`
)
}
// For self-hosted runners the repository state persists between runs.
// This command prunes the stale remote ref when the pull request branch was
// deleted after being merged or closed. Without this the push using
// '--force-with-lease' fails due to "stale info."
// https://github.com/peter-evans/create-pull-request/issues/633
await git.exec(['remote', 'prune', branchRemoteName])
if (utils.isSelfHosted()) {
// For self-hosted runners the repository state persists between runs.
// This command prunes the stale remote ref when the pull request branch was
// deleted after being merged or closed. Without this the push using
// '--force-with-lease' fails due to "stale info."
// https://github.com/peter-evans/create-pull-request/issues/633
await git.exec(['remote', 'prune', branchRemoteName])
}
core.endGroup()
// Apply the branch suffix if set

View File

@@ -135,3 +135,8 @@ export function getErrorMessage(error: unknown) {
if (error instanceof Error) return error.message
return String(error)
}
export const isSelfHosted = (): boolean =>
process.env['RUNNER_ENVIRONMENT'] !== 'github-hosted' &&
(process.env['AGENT_ISSELFHOSTED'] === '1' ||
process.env['AGENT_ISSELFHOSTED'] === undefined)