Update patch PRs with additional content (#10180)

Co-authored-by: Shi Shu <shii@google.com>
This commit is contained in:
shishu314
2025-10-02 16:21:37 -04:00
committed by GitHub
parent 0c6f9d2898
commit f63561dce4
2 changed files with 41 additions and 24 deletions

View File

@@ -50,9 +50,10 @@ async function main() {
const releaseInfo = getLatestReleaseInfo(channel);
const latestTag = releaseInfo.currentTag;
const nextVersion = releaseInfo.nextVersion;
const releaseBranch = `release/${latestTag}-pr-${pullRequestNumber}`;
const hotfixBranch = `hotfix/${latestTag}/${channel}/cherry-pick-${commit.substring(0, 7)}`;
const hotfixBranch = `hotfix/${latestTag}/${nextVersion}/${channel}/cherry-pick-${commit.substring(0, 7)}`;
// Create the release branch from the tag if it doesn't exist.
if (!branchExists(releaseBranch)) {
@@ -190,8 +191,8 @@ async function main() {
console.log(
`Creating pull request from ${hotfixBranch} to ${releaseBranch}...`,
);
let prTitle = `fix(patch): cherry-pick ${commit.substring(0, 7)} to ${releaseBranch}`;
let prBody = `This PR automatically cherry-picks commit ${commit} to patch the ${channel} release.`;
let prTitle = `fix(patch): cherry-pick ${commit.substring(0, 7)} to ${releaseBranch} to patch version ${releaseInfo.currentTag} and create version ${releaseInfo.nextVersion}`;
let prBody = `This PR automatically cherry-picks commit ${commit} to patch version ${releaseInfo.currentTag} in the ${channel} release to create version ${releaseInfo.nextVersion}.`;
if (hasConflicts) {
prTitle = `fix(patch): cherry-pick ${commit.substring(0, 7)} to ${releaseBranch} [CONFLICTS]`;

View File

@@ -14,6 +14,42 @@
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
/**
* Extract base version and channel info from hotfix branch name. Branches can
* be in multiple formats:
* - New NEW: hotfix/v0.5.3/v0.5.4/preview/cherry-pick-abc -> v0.5.4 and preview
* - New format: hotfix/v0.5.3/preview/cherry-pick-abc -> v0.5.3 and preview
* - Old format: hotfix/v0.5.3/cherry-pick-abc -> v0.5.3 and stable (default)
* We check the formats from newest to oldest. If the channel found is invalid,
* an error is thrown.
*/
function getBranchInfo({ branchName, context }) {
const parts = branchName.split('/');
const version = parts[1];
let channel = 'stable'; // default for old format
if (parts.length >= 5 && (parts[3] === 'stable' || parts[3] === 'preview')) {
channel = parts[3];
} else if (
parts.length >= 4 &&
(parts[2] === 'stable' || parts[2] === 'preview')
) {
// New format with explicit channel
channel = parts[2];
} else if (context.eventName === 'workflow_dispatch') {
// Manual dispatch, infer from version name
channel = version.includes('preview') ? 'preview' : 'stable';
}
// Validate channel
if (channel !== 'stable' && channel !== 'preview') {
throw new Error(
`Invalid channel: ${channel}. Must be 'stable' or 'preview'.`,
);
}
return { channel, version };
}
async function main() {
const argv = await yargs(hideBin(process.argv))
.option('head-ref', {
@@ -79,27 +115,7 @@ async function main() {
console.log(`Processing patch trigger for branch: ${headRef}`);
// Extract base version and channel from hotfix branch name
// New format: hotfix/v0.5.3/preview/cherry-pick-abc -> v0.5.3 and preview
// Old format: hotfix/v0.5.3/cherry-pick-abc -> v0.5.3 and stable (default)
const parts = headRef.split('/');
const version = parts[1];
let channel = 'stable'; // default for old format
if (parts.length >= 4 && (parts[2] === 'stable' || parts[2] === 'preview')) {
// New format with explicit channel
channel = parts[2];
} else if (context.eventName === 'workflow_dispatch') {
// Manual dispatch, infer from version name
channel = version.includes('preview') ? 'preview' : 'stable';
}
// Validate channel
if (channel !== 'stable' && channel !== 'preview') {
throw new Error(
`Invalid channel: ${channel}. Must be 'stable' or 'preview'.`,
);
}
const { version, channel } = getBranchInfo({ branchName: headRef, context });
// Try to find the original PR that requested this patch
let originalPr = null;