fix(infra) - Add pr number to the release branch name for final step of release (#10364)

Co-authored-by: Shi Shu <shii@google.com>
This commit is contained in:
shishu314
2025-10-02 14:30:25 -04:00
committed by GitHub
parent a6af7bbb46
commit 0f465e88e8

View File

@@ -101,7 +101,60 @@ async function main() {
);
}
const releaseRef = `release/${version}`;
// Try to find the original PR that requested this patch
let originalPr = null;
if (!testMode) {
try {
console.log('Looking for original PR using search...');
const { execFileSync } = await import('node:child_process');
// Split search string into searchArgs to prevent triple escaping on the quoted filters
const searchArgs =
`repo:${context.repo.owner}/${context.repo.repo} is:pr in:comments "${headRef}"`.split(
' ',
);
console.log('Search args:', searchArgs);
// Use gh CLI to search for PRs with comments referencing the hotfix branch
const result = execFileSync(
'gh',
[
'search',
'prs',
'--json',
'number,title',
'--limit',
'1',
...searchArgs,
'Patch PR Created',
],
{
encoding: 'utf8',
env: { ...process.env, GH_TOKEN: process.env.GITHUB_TOKEN },
},
);
const searchResults = JSON.parse(result);
if (searchResults && searchResults.length > 0) {
originalPr = searchResults[0].number;
console.log(`Found original PR: #${originalPr}`);
} else {
console.log('Could not find a matching original PR via search.');
}
} catch (e) {
console.log('Could not determine original PR:', e.message);
}
} else {
console.log('Skipping original PR lookup (test mode)');
originalPr = 8655; // Mock for testing
}
if (!originalPr) {
throw new Error(
'Could not find the original PR for this patch. Cannot proceed with release.',
);
}
const releaseRef = `release/${version}-pr-${originalPr}`;
const workflowId =
context.eventName === 'pull_request'
? 'release-patch-3-release.yml'
@@ -127,40 +180,6 @@ async function main() {
return;
}
// Try to find the original PR that requested this patch
let originalPr = null;
if (!testMode) {
try {
console.log('Looking for original PR using search...');
const { execFileSync } = await import('node:child_process');
// Use gh CLI to search for PRs with comments referencing the hotfix branch
const query = `repo:${context.repo.owner}/${context.repo.repo} is:pr is:all in:comments "Patch PR Created" "${headRef}"`;
const result = execFileSync(
'gh',
['search', 'prs', '--json', 'number,title', '--limit', '1', query],
{
encoding: 'utf8',
env: { ...process.env, GH_TOKEN: process.env.GITHUB_TOKEN },
},
);
const searchResults = JSON.parse(result);
if (searchResults && searchResults.length > 0) {
originalPr = searchResults[0].number;
console.log(`Found original PR: #${originalPr}`);
} else {
console.log('Could not find a matching original PR via search.');
}
} catch (e) {
console.log('Could not determine original PR:', e.message);
}
} else {
console.log('Skipping original PR lookup (test mode)');
originalPr = 8655; // Mock for testing
}
// Trigger the release workflow
console.log(`Triggering release workflow: ${workflowId}`);
if (!testMode) {