Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 22a9089

Browse filesBrowse files
authored
fix: restrict remote prune to self-hosted runners (peter-evans#4250)
1 parent d4f3be6 commit 22a9089
Copy full SHA for 22a9089

File tree

Expand file treeCollapse file tree

3 files changed

+26
-12
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+26
-12
lines changed
Open diff view settings
Collapse file

‎dist/index.js‎

Copy file name to clipboardExpand all lines: dist/index.js
+13-6Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -452,12 +452,14 @@ function createPullRequest(inputs) {
452452
if (branchRemoteName == 'origin' && base == inputs.branch) {
453453
throw new Error(`The 'base' and 'branch' for a pull request must be different branches. Unable to continue.`);
454454
}
455-
// For self-hosted runners the repository state persists between runs.
456-
// This command prunes the stale remote ref when the pull request branch was
457-
// deleted after being merged or closed. Without this the push using
458-
// '--force-with-lease' fails due to "stale info."
459-
// https://github.com/peter-evans/create-pull-request/issues/633
460-
yield git.exec(['remote', 'prune', branchRemoteName]);
455+
if (utils.isSelfHosted()) {
456+
// For self-hosted runners the repository state persists between runs.
457+
// This command prunes the stale remote ref when the pull request branch was
458+
// deleted after being merged or closed. Without this the push using
459+
// '--force-with-lease' fails due to "stale info."
460+
// https://github.com/peter-evans/create-pull-request/issues/633
461+
yield git.exec(['remote', 'prune', branchRemoteName]);
462+
}
461463
core.endGroup();
462464
// Apply the branch suffix if set
463465
if (inputs.branchSuffix) {
@@ -1888,6 +1890,7 @@ var __importStar = (this && this.__importStar) || (function () {
18881890
};
18891891
})();
18901892
Object.defineProperty(exports, "__esModule", ({ value: true }));
1893+
exports.isSelfHosted = void 0;
18911894
exports.getInputAsArray = getInputAsArray;
18921895
exports.getStringAsArray = getStringAsArray;
18931896
exports.stripOrgPrefixFromTeams = stripOrgPrefixFromTeams;
@@ -1996,6 +1999,10 @@ function getErrorMessage(error) {
19961999
return error.message;
19972000
return String(error);
19982001
}
2002+
const isSelfHosted = () => process.env['RUNNER_ENVIRONMENT'] !== 'github-hosted' &&
2003+
(process.env['AGENT_ISSELFHOSTED'] === '1' ||
2004+
process.env['AGENT_ISSELFHOSTED'] === undefined);
2005+
exports.isSelfHosted = isSelfHosted;
19992006

20002007

20012008
/***/ }),
Collapse file

‎src/create-pull-request.ts‎

Copy file name to clipboardExpand all lines: src/create-pull-request.ts
+8-6Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,14 @@ export async function createPullRequest(inputs: Inputs): Promise<void> {
121121
`The 'base' and 'branch' for a pull request must be different branches. Unable to continue.`
122122
)
123123
}
124-
// For self-hosted runners the repository state persists between runs.
125-
// This command prunes the stale remote ref when the pull request branch was
126-
// deleted after being merged or closed. Without this the push using
127-
// '--force-with-lease' fails due to "stale info."
128-
// https://github.com/peter-evans/create-pull-request/issues/633
129-
await git.exec(['remote', 'prune', branchRemoteName])
124+
if (utils.isSelfHosted()) {
125+
// For self-hosted runners the repository state persists between runs.
126+
// This command prunes the stale remote ref when the pull request branch was
127+
// deleted after being merged or closed. Without this the push using
128+
// '--force-with-lease' fails due to "stale info."
129+
// https://github.com/peter-evans/create-pull-request/issues/633
130+
await git.exec(['remote', 'prune', branchRemoteName])
131+
}
130132
core.endGroup()
131133

132134
// Apply the branch suffix if set
Collapse file

‎src/utils.ts‎

Copy file name to clipboardExpand all lines: src/utils.ts
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,8 @@ export function getErrorMessage(error: unknown) {
135135
if (error instanceof Error) return error.message
136136
return String(error)
137137
}
138+
139+
export const isSelfHosted = (): boolean =>
140+
process.env['RUNNER_ENVIRONMENT'] !== 'github-hosted' &&
141+
(process.env['AGENT_ISSELFHOSTED'] === '1' ||
142+
process.env['AGENT_ISSELFHOSTED'] === undefined)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.