fix: restrict remote prune to self-hosted runners (#4250)
This commit is contained in:
19
dist/index.js
vendored
19
dist/index.js
vendored
@@ -452,12 +452,14 @@ function createPullRequest(inputs) {
|
|||||||
if (branchRemoteName == 'origin' && base == inputs.branch) {
|
if (branchRemoteName == 'origin' && base == inputs.branch) {
|
||||||
throw new Error(`The 'base' and 'branch' for a pull request must be different branches. Unable to continue.`);
|
throw new Error(`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.
|
if (utils.isSelfHosted()) {
|
||||||
// This command prunes the stale remote ref when the pull request branch was
|
// For self-hosted runners the repository state persists between runs.
|
||||||
// deleted after being merged or closed. Without this the push using
|
// This command prunes the stale remote ref when the pull request branch was
|
||||||
// '--force-with-lease' fails due to "stale info."
|
// deleted after being merged or closed. Without this the push using
|
||||||
// https://github.com/peter-evans/create-pull-request/issues/633
|
// '--force-with-lease' fails due to "stale info."
|
||||||
yield git.exec(['remote', 'prune', branchRemoteName]);
|
// https://github.com/peter-evans/create-pull-request/issues/633
|
||||||
|
yield git.exec(['remote', 'prune', branchRemoteName]);
|
||||||
|
}
|
||||||
core.endGroup();
|
core.endGroup();
|
||||||
// Apply the branch suffix if set
|
// Apply the branch suffix if set
|
||||||
if (inputs.branchSuffix) {
|
if (inputs.branchSuffix) {
|
||||||
@@ -1888,6 +1890,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
|
exports.isSelfHosted = void 0;
|
||||||
exports.getInputAsArray = getInputAsArray;
|
exports.getInputAsArray = getInputAsArray;
|
||||||
exports.getStringAsArray = getStringAsArray;
|
exports.getStringAsArray = getStringAsArray;
|
||||||
exports.stripOrgPrefixFromTeams = stripOrgPrefixFromTeams;
|
exports.stripOrgPrefixFromTeams = stripOrgPrefixFromTeams;
|
||||||
@@ -1996,6 +1999,10 @@ function getErrorMessage(error) {
|
|||||||
return error.message;
|
return error.message;
|
||||||
return String(error);
|
return String(error);
|
||||||
}
|
}
|
||||||
|
const isSelfHosted = () => process.env['RUNNER_ENVIRONMENT'] !== 'github-hosted' &&
|
||||||
|
(process.env['AGENT_ISSELFHOSTED'] === '1' ||
|
||||||
|
process.env['AGENT_ISSELFHOSTED'] === undefined);
|
||||||
|
exports.isSelfHosted = isSelfHosted;
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|||||||
@@ -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.`
|
`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.
|
if (utils.isSelfHosted()) {
|
||||||
// This command prunes the stale remote ref when the pull request branch was
|
// For self-hosted runners the repository state persists between runs.
|
||||||
// deleted after being merged or closed. Without this the push using
|
// This command prunes the stale remote ref when the pull request branch was
|
||||||
// '--force-with-lease' fails due to "stale info."
|
// deleted after being merged or closed. Without this the push using
|
||||||
// https://github.com/peter-evans/create-pull-request/issues/633
|
// '--force-with-lease' fails due to "stale info."
|
||||||
await git.exec(['remote', 'prune', branchRemoteName])
|
// https://github.com/peter-evans/create-pull-request/issues/633
|
||||||
|
await git.exec(['remote', 'prune', branchRemoteName])
|
||||||
|
}
|
||||||
core.endGroup()
|
core.endGroup()
|
||||||
|
|
||||||
// Apply the branch suffix if set
|
// Apply the branch suffix if set
|
||||||
|
|||||||
@@ -135,3 +135,8 @@ export function getErrorMessage(error: unknown) {
|
|||||||
if (error instanceof Error) return error.message
|
if (error instanceof Error) return error.message
|
||||||
return String(error)
|
return String(error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const isSelfHosted = (): boolean =>
|
||||||
|
process.env['RUNNER_ENVIRONMENT'] !== 'github-hosted' &&
|
||||||
|
(process.env['AGENT_ISSELFHOSTED'] === '1' ||
|
||||||
|
process.env['AGENT_ISSELFHOSTED'] === undefined)
|
||||||
|
|||||||
Reference in New Issue
Block a user