Skip to content

Commit 0d542b6

Browse files
committed
ci: mirror toolbox changelog into extension changelog
1 parent b533eb2 commit 0d542b6

1 file changed

Lines changed: 129 additions & 0 deletions

File tree

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: Mirror Toolbox Changelog
16+
17+
on:
18+
pull_request_target:
19+
types: [opened, edited]
20+
21+
jobs:
22+
add-release-notes:
23+
if: github.actor == 'renovate[bot]' && startsWith(github.head_ref, 'renovate/googleapis-genai-toolbox')
24+
runs-on: ubuntu-latest
25+
permissions:
26+
pull-requests: write
27+
28+
steps:
29+
- name: Add Toolbox Release Notes to PR Body
30+
uses: actions/github-script@v6
31+
env:
32+
REQUIRED_KEYWORD: 'alloydb'
33+
with:
34+
script: |
35+
const requiredKeyword = process.env.REQUIRED_KEYWORD;
36+
const prBody = context.payload.pull_request.body || '';
37+
38+
// Extract the relevant changelog section
39+
const startMarker = '<summary>googleapis/genai-toolbox';
40+
const endMarker = '</details>';
41+
const startIndex = prBody.indexOf(startMarker);
42+
const endIndex = prBody.indexOf(endMarker, startIndex);
43+
44+
if (startIndex === -1 || endIndex === -1) {
45+
console.log('Could not find the release notes section in the PR body. Exiting.');
46+
return;
47+
}
48+
const releaseNotesSection = prBody.substring(startIndex, endIndex);
49+
50+
// Parse, Filter, and transform
51+
const prefixesToFilter = ['source/', 'sources/', 'tool/', 'tools/'];
52+
53+
// Use a map for cleaner type switching
54+
const typeMap = {
55+
'##### ⚠ BREAKING CHANGES': 'feat!',
56+
'##### Features': 'feat',
57+
'##### Bug Fixes': 'fix',
58+
'##### Chores': 'ignore',
59+
'##### Miscellaneous Chores': 'ignore',
60+
'##### Documentation': 'ignore',
61+
};
62+
63+
let currentType = 'feat'; // Default
64+
const newChangelog = [];
65+
66+
for (const line of releaseNotesSection.split('\n')) {
67+
const trimmedLine = line.trim();
68+
69+
// Update current type if it's a header
70+
if (typeMap[trimmedLine]) {
71+
currentType = typeMap[trimmedLine];
72+
continue;
73+
}
74+
75+
// Skip ignored sections
76+
if (currentType === 'ignore') {
77+
continue;
78+
}
79+
80+
// Match and extract changelog item
81+
const itemMatch = trimmedLine.match(/^[*-]\s(.*)$/);
82+
if (itemMatch) {
83+
// Use the raw content, exactly as the original script did
84+
const originalContent = itemMatch[1];
85+
86+
const lineAsLowerCase = originalContent.toLowerCase();
87+
const hasPrefix = prefixesToFilter.some(prefix => lineAsLowerCase.includes(prefix));
88+
const hasKeyword = lineAsLowerCase.includes(requiredKeyword);
89+
90+
// Include if it doesn't have a prefix OR it has the keyword
91+
if (!hasPrefix || hasKeyword) {
92+
// Use the original script's output format
93+
newChangelog.push(`- ${currentType}: ${originalContent}`);
94+
} else {
95+
console.log(`Filtering out: ${originalContent}`);
96+
}
97+
}
98+
}
99+
100+
if (newChangelog.length === 0) {
101+
console.log('Found no changelog items to add after filtering. Exiting.');
102+
return;
103+
}
104+
105+
// Construct the override block
106+
const overrideBlock = [
107+
'\n\nBEGIN_COMMIT_OVERRIDE',
108+
...newChangelog,
109+
'END_COMMIT_OVERRIDE'
110+
].join('\n');
111+
112+
// Update PR body
113+
const baseBody = prBody.split('\n\nBEGIN_COMMIT_OVERRIDE')[0].trim();
114+
const finalBody = baseBody + overrideBlock;
115+
116+
if (finalBody === prBody) {
117+
console.log('The generated changelog is identical. No update needed.');
118+
return;
119+
}
120+
121+
// 5. Update the PR
122+
await github.rest.pulls.update({
123+
owner: context.repo.owner,
124+
repo: context.repo.repo,
125+
pull_number: context.issue.number,
126+
body: finalBody,
127+
});
128+
129+
console.log('Successfully updated the PR body with filtered release notes.');

0 commit comments

Comments
 (0)