Skip to content

Commit b75261d

Browse files
authored
On cherry-pick, attempt to update baselines on conflict (#57891)
1 parent 39fd535 commit b75261d

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

.github/workflows/create-cherry-pick-pr.yml

+32-4
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,35 @@ jobs:
9292
await exec.exec("git", ["config", "user.name", "TypeScript Bot"]);
9393
await exec.exec("git", ["switch", "--detach", `origin/${TARGET_BRANCH}`]);
9494
await exec.exec("git", ["switch", "-c", pickBranch]);
95-
await exec.exec("git", ["cherry-pick", "-m", "1", pr.data.merge_commit_sha]);
95+
96+
let updatedBaselinesMessage = "";
97+
try {
98+
await exec.exec("git", ["cherry-pick", "-m", "1", pr.data.merge_commit_sha]);
99+
} catch (e) {
100+
console.log(e);
101+
102+
// The cherry-pick failed. If all of the conflicts are in tests/baselines,
103+
// try to run the tests and accept the new baselines.
104+
105+
await exec.exec("git", ["add", "tests/baselines"]);
106+
// This will fail if any other files were modified.
107+
await exec.exec("git", ["-c", "core.editor=true", "cherry-pick", "--continue"]);
108+
109+
await exec.exec("npm", ["ci"]);
110+
111+
try {
112+
await exec.exec("npm", ["test", "--", "--no-lint"]);
113+
} catch {
114+
// Expected to fail.
115+
}
116+
117+
await exec.exec("npx", ["hereby", "baseline-accept"]);
118+
await exec.exec("git", ["add", "tests/baselines"]);
119+
await exec.exec("git", ["commit", "-m", "Update baselines"]);
120+
121+
updatedBaselinesMessage = " This involved updating baselines; please check the diff.";
122+
}
123+
96124
await exec.exec("git", ["push", "--force", "--set-upstream", "origin", pickBranch]);
97125
98126
const existingPulls = await github.rest.pulls.list({
@@ -106,7 +134,7 @@ jobs:
106134
if (existingPulls.data.length === 0) {
107135
console.log(`No existing PRs found for ${pickBranch}`);
108136
109-
const body = `This cherry-pick was triggered by a request on #${PR}.\n\nPlease review the diff and merge if no changes are unexpected.`;
137+
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}`;
110138
111139
const newPr = await github.rest.pulls.create({
112140
owner: context.repo.owner,
@@ -131,7 +159,7 @@ jobs:
131159
reviewers: ["DanielRosenwasser", REQUESTING_USER],
132160
});
133161
134-
commentBody = `I've created #${newPr.data.number} for you.`;
162+
commentBody = `I've created #${newPr.data.number} for you.${updatedBaselinesMessage}`;
135163
}
136164
else {
137165
const existing = existingPulls.data[0];
@@ -144,7 +172,7 @@ jobs:
144172
title,
145173
});
146174
147-
commentBody = `I've updated #${existing.number} for you.`;
175+
commentBody = `I've updated #${existing.number} for you.${updatedBaselinesMessage}`;
148176
}
149177
150178
return commentBody;

0 commit comments

Comments
 (0)