Skip to content

On cherry-pick, attempt to update baselines on conflict #57891

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

Merged
merged 1 commit into from
Mar 21, 2024
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
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