Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjustments for Backport GH Action #4601

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 32 additions & 44 deletions .github/workflows/backport-base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,6 @@ jobs:
await exec.exec(`git checkout ${target_branch}`);
await exec.exec(`git clean -xdff`);

// skip opening PR if the branch already exists on the origin remote since that means it was opened
// by an earlier backport and force pushing to the branch updates the existing PR
let should_open_pull_request = true;
try {
await exec.exec(`git ls-remote --exit-code --heads origin ${temp_branch}`);
should_open_pull_request = false;
} catch { }

// download and apply patch
await exec.exec(`curl -sSL "${context.payload.issue.pull_request.patch_url}" --output changes.patch`);

Expand All @@ -161,44 +153,40 @@ jobs:
// await exec.exec(`git checkout -b ${temp_branch}`);

// configure git
// await exec.exec(`git config user.name "github-actions"`);
// await exec.exec(`git config user.email "github-actions@github.com"`);

// const git_am_command = "git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch";
// let git_am_output = `$ ${git_am_command}\n\n`;
// let git_am_failed = false;
// try {
// await exec.exec(git_am_command, [], {
// listeners: {
// stdout: function stdout(data) { git_am_output += data; },
// stderr: function stderr(data) { git_am_output += data; }
// }
// });
// } catch (error) {
// git_am_output += error;
// git_am_failed = true;
// }
await exec.exec(`git config user.name "github-actions"`);
await exec.exec(`git config user.email "github-actions@github.com"`);

// if (git_am_failed) {
// const git_am_failed_body = `@${context.payload.comment.user.login} backporting to ${target_branch} failed, the patch most likely resulted in conflicts:\n\n\`\`\`shell\n${git_am_output}\n\`\`\`\n\nPlease backport manually!`;
// await github.rest.issues.createComment({
// owner: repo_owner,
// repo: repo_name,
// issue_number: pr_number,
// body: git_am_failed_body
// });
// core.setFailed("Error: git am failed, most likely due to a merge conflict.");
// return;
// }
// else {
// // push the temp branch to the repository
// await exec.exec(`git push --force --set-upstream origin HEAD:${temp_branch}`);
// }
const git_am_command = "git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch";
let git_am_output = `$ ${git_am_command}\n\n`;
let git_am_failed = false;
try {
await exec.exec(git_am_command, [], {
listeners: {
stdout: function stdout(data) { git_am_output += data; },
stderr: function stderr(data) { git_am_output += data; }
}
});
} catch (error) {
git_am_output += error;
git_am_failed = true;
}

// if (!should_open_pull_request) {
// console.log("Backport temp branch already exists, skipping opening a PR.");
// return;
// }
if (git_am_failed) {
const git_am_failed_body = `@${context.payload.comment.user.login} backporting to ${target_branch} failed, the patch most likely resulted in conflicts:\n\n\`\`\`shell\n${git_am_output}\n\`\`\`\n\nPlease backport manually!`;
await github.rest.issues.createComment({
owner: repo_owner,
repo: repo_name,
issue_number: pr_number,
body: git_am_failed_body
});
core.setFailed("Error: git am failed, most likely due to a merge conflict.");
return;
}
else {
await exec.exec(`rm changes.patch`);
// push the temp branch to the repository
// await exec.exec(`git push --force --set-upstream origin HEAD:${temp_branch}`);
}

// prepare the GitHub PR details

Expand Down