Skip to content

Commit

Permalink
On cherry-pick, attempt to update baselines on conflict (#57891)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebailey committed Mar 21, 2024
1 parent 39fd535 commit b75261d
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions .github/workflows/create-cherry-pick-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,35 @@ jobs:
await exec.exec("git", ["config", "user.name", "TypeScript Bot"]);
await exec.exec("git", ["switch", "--detach", `origin/${TARGET_BRANCH}`]);
await exec.exec("git", ["switch", "-c", pickBranch]);
await exec.exec("git", ["cherry-pick", "-m", "1", pr.data.merge_commit_sha]);
let updatedBaselinesMessage = "";
try {
await exec.exec("git", ["cherry-pick", "-m", "1", pr.data.merge_commit_sha]);
} catch (e) {
console.log(e);
// The cherry-pick failed. If all of the conflicts are in tests/baselines,
// try to run the tests and accept the new baselines.
await exec.exec("git", ["add", "tests/baselines"]);
// This will fail if any other files were modified.
await exec.exec("git", ["-c", "core.editor=true", "cherry-pick", "--continue"]);
await exec.exec("npm", ["ci"]);
try {
await exec.exec("npm", ["test", "--", "--no-lint"]);
} catch {
// Expected to fail.
}
await exec.exec("npx", ["hereby", "baseline-accept"]);
await exec.exec("git", ["add", "tests/baselines"]);
await exec.exec("git", ["commit", "-m", "Update baselines"]);
updatedBaselinesMessage = " This involved updating baselines; please check the diff.";
}
await exec.exec("git", ["push", "--force", "--set-upstream", "origin", pickBranch]);
const existingPulls = await github.rest.pulls.list({
Expand All @@ -106,7 +134,7 @@ jobs:
if (existingPulls.data.length === 0) {
console.log(`No existing PRs found for ${pickBranch}`);
const body = `This cherry-pick was triggered by a request on #${PR}.\n\nPlease review the diff and merge if no changes are unexpected.`;
const body = `This cherry-pick was triggered by a request on #${PR}.\n\nPlease review the diff and merge if no changes are unexpected.${updatedBaselinesMessage}`;
const newPr = await github.rest.pulls.create({
owner: context.repo.owner,
Expand All @@ -131,7 +159,7 @@ jobs:
reviewers: ["DanielRosenwasser", REQUESTING_USER],
});
commentBody = `I've created #${newPr.data.number} for you.`;
commentBody = `I've created #${newPr.data.number} for you.${updatedBaselinesMessage}`;
}
else {
const existing = existingPulls.data[0];
Expand All @@ -144,7 +172,7 @@ jobs:
title,
});
commentBody = `I've updated #${existing.number} for you.`;
commentBody = `I've updated #${existing.number} for you.${updatedBaselinesMessage}`;
}
return commentBody;
Expand Down

0 comments on commit b75261d

Please sign in to comment.