Skip to content

Commit 9bcd70f

Browse files
mattKorwelnagendrareddy10
authored andcommitted
migrate to patch both (google-gemini#8803)
1 parent 91d27b0 commit 9bcd70f

File tree

3 files changed

+73
-54
lines changed

3 files changed

+73
-54
lines changed

.github/workflows/release-patch-1-create-pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ jobs:
7373
}
7474
7575
- name: 'Comment on Original PR'
76-
if: '!inputs.dry_run && inputs.original_pr'
76+
if: 'inputs.original_pr'
7777
env:
7878
GH_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
7979
ORIGINAL_PR: '${{ github.event.inputs.original_pr }}'

.github/workflows/release-patch-from-comment.yml

Lines changed: 60 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ jobs:
2727
commands: 'patch'
2828
permission: 'write'
2929
issue-type: 'pull-request'
30-
static-args: |
31-
dry_run=false
3230

3331
- name: 'Get PR Status'
3432
id: 'pr_status'
@@ -49,66 +47,79 @@ jobs:
4947
with:
5048
github-token: '${{ secrets.GITHUB_TOKEN }}'
5149
script: |
52-
// Parse the comment body directly to extract channel
50+
// Parse the comment body directly to extract channel(s)
5351
const commentBody = process.env.COMMENT_BODY;
5452
console.log('Comment body:', commentBody);
5553
56-
let channel = 'stable'; // default
54+
let channels = ['stable', 'preview']; // default to both
5755
5856
// Parse different formats:
59-
// /patch channel=preview
60-
// /patch --channel preview
57+
// /patch (defaults to both)
58+
// /patch both
59+
// /patch stable
6160
// /patch preview
62-
if (commentBody.includes('channel=preview')) {
63-
channel = 'preview';
64-
} else if (commentBody.includes('--channel preview')) {
65-
channel = 'preview';
61+
if (commentBody.trim() === '/patch' || commentBody.trim() === '/patch both') {
62+
channels = ['stable', 'preview'];
63+
} else if (commentBody.trim() === '/patch stable') {
64+
channels = ['stable'];
6665
} else if (commentBody.trim() === '/patch preview') {
67-
channel = 'preview';
66+
channels = ['preview'];
67+
} else {
68+
// Fallback parsing for legacy formats
69+
if (commentBody.includes('channel=preview')) {
70+
channels = ['preview'];
71+
} else if (commentBody.includes('--channel preview')) {
72+
channels = ['preview'];
73+
}
6874
}
6975
70-
// Validate channel
71-
if (channel !== 'stable' && channel !== 'preview') {
72-
throw new Error(`Invalid channel: ${channel}. Must be 'stable' or 'preview'.`);
73-
}
76+
console.log('Detected channels:', channels);
7477
75-
console.log('Detected channel:', channel);
78+
const dispatchedRuns = [];
7679
77-
const response = await github.rest.actions.createWorkflowDispatch({
78-
owner: context.repo.owner,
79-
repo: context.repo.repo,
80-
workflow_id: 'release-patch-1-create-pr.yml',
81-
ref: 'main',
82-
inputs: {
83-
commit: '${{ steps.pr_status.outputs.MERGE_COMMIT_SHA }}',
84-
channel: channel,
85-
dry_run: 'false',
86-
original_pr: '${{ github.event.issue.number }}'
87-
}
88-
});
80+
// Dispatch workflow for each channel
81+
for (const channel of channels) {
82+
console.log(`Dispatching workflow for channel: ${channel}`);
8983
90-
// Wait a moment for the workflow to be created, then find it
91-
await new Promise(resolve => setTimeout(resolve, 2000));
84+
const response = await github.rest.actions.createWorkflowDispatch({
85+
owner: context.repo.owner,
86+
repo: context.repo.repo,
87+
workflow_id: 'release-patch-1-create-pr.yml',
88+
ref: 'main',
89+
inputs: {
90+
commit: '${{ steps.pr_status.outputs.MERGE_COMMIT_SHA }}',
91+
channel: channel,
92+
original_pr: '${{ github.event.issue.number }}'
93+
}
94+
});
95+
96+
dispatchedRuns.push({ channel, response });
97+
}
98+
99+
// Wait a moment for the workflows to be created
100+
await new Promise(resolve => setTimeout(resolve, 3000));
92101
93102
const runs = await github.rest.actions.listWorkflowRuns({
94103
owner: context.repo.owner,
95104
repo: context.repo.repo,
96105
workflow_id: 'release-patch-1-create-pr.yml',
97-
per_page: 10
106+
per_page: 20 // Increased to handle multiple runs
98107
});
99108
100-
// Find the most recent run that matches our trigger
101-
const dispatchedRun = runs.data.workflow_runs.find(run =>
109+
// Find the recent runs that match our trigger
110+
const recentRuns = runs.data.workflow_runs.filter(run =>
102111
run.event === 'workflow_dispatch' &&
103-
new Date(run.created_at) > new Date(Date.now() - 10000) // Within last 10 seconds
104-
);
112+
new Date(run.created_at) > new Date(Date.now() - 15000) // Within last 15 seconds
113+
).slice(0, channels.length); // Limit to the number of channels we dispatched
105114
106-
if (dispatchedRun) {
107-
core.setOutput('dispatched_run_id', dispatchedRun.id);
108-
core.setOutput('dispatched_run_url', dispatchedRun.html_url);
109-
}
115+
// Set outputs
116+
core.setOutput('dispatched_channels', channels.join(','));
117+
core.setOutput('dispatched_run_count', channels.length.toString());
110118
111-
core.setOutput('channel', channel);
119+
if (recentRuns.length > 0) {
120+
core.setOutput('dispatched_run_urls', recentRuns.map(r => r.html_url).join(','));
121+
core.setOutput('dispatched_run_ids', recentRuns.map(r => r.id).join(','));
122+
}
112123
113124
- name: 'Comment on Failure'
114125
if: "startsWith(github.event.comment.body, '/patch') && steps.pr_status.outputs.STATE != 'MERGED'"
@@ -120,34 +131,36 @@ jobs:
120131
:x: The `/patch` command failed. This pull request must be merged before a patch can be created.
121132
122133
- name: 'Final Status Comment - Success'
123-
if: "always() && startsWith(github.event.comment.body, '/patch') && steps.dispatch_patch.outcome == 'success' && steps.dispatch_patch.outputs.dispatched_run_url"
134+
if: "always() && startsWith(github.event.comment.body, '/patch') && steps.dispatch_patch.outcome == 'success' && steps.dispatch_patch.outputs.dispatched_run_urls"
124135
uses: 'peter-evans/create-or-update-comment@67dcc547d311b736a8e6c5c236542148a47adc3d'
125136
with:
126137
token: '${{ secrets.GITHUB_TOKEN }}'
127138
issue-number: '${{ github.event.issue.number }}'
128139
body: |
129-
✅ **Patch workflow dispatched successfully!**
140+
✅ **Patch workflow(s) dispatched successfully!**
130141
131142
**📋 Details:**
132-
- **Channel**: `${{ steps.dispatch_patch.outputs.channel }}`
143+
- **Channels**: `${{ steps.dispatch_patch.outputs.dispatched_channels }}`
133144
- **Commit**: `${{ steps.pr_status.outputs.MERGE_COMMIT_SHA }}`
145+
- **Workflows Created**: ${{ steps.dispatch_patch.outputs.dispatched_run_count }}
134146
135147
**🔗 Track Progress:**
136-
- [Dispatched patch workflow](${{ steps.dispatch_patch.outputs.dispatched_run_url }})
148+
- [View patch workflows](https://github.com/${{ github.repository }}/actions/workflows/release-patch-1-create-pr.yml)
137149
- [This workflow run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
138150
139151
- name: 'Final Status Comment - Dispatch Success (No URL)'
140-
if: "always() && startsWith(github.event.comment.body, '/patch') && steps.dispatch_patch.outcome == 'success' && !steps.dispatch_patch.outputs.dispatched_run_url"
152+
if: "always() && startsWith(github.event.comment.body, '/patch') && steps.dispatch_patch.outcome == 'success' && !steps.dispatch_patch.outputs.dispatched_run_urls"
141153
uses: 'peter-evans/create-or-update-comment@67dcc547d311b736a8e6c5c236542148a47adc3d'
142154
with:
143155
token: '${{ secrets.GITHUB_TOKEN }}'
144156
issue-number: '${{ github.event.issue.number }}'
145157
body: |
146-
✅ **Patch workflow dispatched successfully!**
158+
✅ **Patch workflow(s) dispatched successfully!**
147159
148160
**📋 Details:**
149-
- **Channel**: `${{ steps.dispatch_patch.outputs.channel }}`
161+
- **Channels**: `${{ steps.dispatch_patch.outputs.dispatched_channels }}`
150162
- **Commit**: `${{ steps.pr_status.outputs.MERGE_COMMIT_SHA }}`
163+
- **Workflows Created**: ${{ steps.dispatch_patch.outputs.dispatched_run_count }}
151164
152165
**🔗 Track Progress:**
153166
- [View patch workflows](https://github.com/${{ github.repository }}/actions/workflows/release-patch-1-create-pr.yml)

docs/releases.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,20 @@ There are two ways to create a patch pull request:
110110

111111
After a pull request containing the fix has been merged, a maintainer can add a comment on that same PR with the following format:
112112

113-
`/patch <channel> [--dry-run]`
113+
`/patch [channel]`
114114

115-
- **channel**: `stable` or `preview`
116-
- **--dry-run** (optional): If included, the workflow will run in dry-run mode. This will create the PR with "[DRY RUN]" in the title, and merging it will trigger a dry run of the final release, so nothing is actually published.
115+
- **channel** (optional):
116+
- _no channel_ - patches both stable and preview channels (default, recommended for most fixes)
117+
- `both` - patches both stable and preview channels (same as default)
118+
- `stable` - patches only the stable channel
119+
- `preview` - patches only the preview channel
117120

118-
Example: `/patch stable --dry-run`
121+
Examples:
122+
123+
- `/patch` (patches both stable and preview - default)
124+
- `/patch both` (patches both stable and preview - explicit)
125+
- `/patch stable` (patches only stable)
126+
- `/patch preview` (patches only preview)
119127

120128
The `Release: Patch from Comment` workflow will automatically find the merge commit SHA and trigger the `Release: Patch (1) Create PR` workflow. If the PR is not yet merged, it will post a comment indicating the failure.
121129

@@ -134,8 +142,6 @@ This workflow will automatically:
134142
4. Cherry-pick your specified commit into the hotfix branch.
135143
5. Create a pull request from the hotfix branch back to the release branch.
136144

137-
**Important:** If you select `stable`, the workflow will run twice, creating one PR for the `stable` channel and a second PR for the `preview` channel.
138-
139145
#### 2. Review and Merge
140146

141147
Review the automatically created pull request(s) to ensure the cherry-pick was successful and the changes are correct. Once approved, merge the pull request.

0 commit comments

Comments
 (0)