Skip to content

Commit 7bd1565

Browse files
mattKorwelnagendrareddy10
authored andcommitted
better messaging (google-gemini#8794)
1 parent dd25dda commit 7bd1565

File tree

4 files changed

+375
-27
lines changed

4 files changed

+375
-27
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,22 @@ jobs:
7171
GH_TOKEN: '${{ steps.generate_token.outputs.token }}'
7272
continue-on-error: true
7373
run: |
74-
node scripts/releasing/create-patch-pr.js --commit=${{ github.event.inputs.commit }} --channel=${{ github.event.inputs.channel }} --dry-run=${{ github.event.inputs.dry_run }} > patch_output.log 2>&1
75-
echo "EXIT_CODE=$?" >> "$GITHUB_OUTPUT"
76-
cat patch_output.log
74+
# Capture output directly to environment variable
75+
{
76+
node scripts/releasing/create-patch-pr.js --commit=${{ github.event.inputs.commit }} --channel=${{ github.event.inputs.channel }} --dry-run=${{ github.event.inputs.dry_run }}
77+
echo "EXIT_CODE=$?" >> "$GITHUB_OUTPUT"
78+
} 2>&1 | {
79+
echo "LOG_CONTENT<<EOF" >> "$GITHUB_ENV"
80+
cat >> "$GITHUB_ENV"
81+
echo "EOF" >> "$GITHUB_ENV"
82+
}
7783
7884
- name: 'Comment on Original PR'
7985
if: '!inputs.dry_run && inputs.original_pr'
8086
env:
8187
GH_TOKEN: '${{ steps.generate_token.outputs.token }}'
8288
ORIGINAL_PR: '${{ github.event.inputs.original_pr }}'
8389
EXIT_CODE: '${{ steps.create_patch.outputs.EXIT_CODE }}'
84-
OUTPUT_LOG: 'patch_output.log'
8590
COMMIT: '${{ github.event.inputs.commit }}'
8691
CHANNEL: '${{ github.event.inputs.channel }}'
8792
REPOSITORY: '${{ github.repository }}'

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

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ jobs:
5252
5353
- name: 'Dispatch if Merged'
5454
if: "steps.pr_status.outputs.STATE == 'MERGED'"
55+
id: 'dispatch_patch'
5556
uses: 'actions/github-script@00f12e3e20659f42342b1c0226afda7f7c042325'
5657
env:
5758
COMMENT_BODY: '${{ github.event.comment.body }}'
@@ -82,7 +83,7 @@ jobs:
8283
8384
console.log('Detected channel:', channel);
8485
85-
github.rest.actions.createWorkflowDispatch({
86+
const response = await github.rest.actions.createWorkflowDispatch({
8687
owner: context.repo.owner,
8788
repo: context.repo.repo,
8889
workflow_id: 'release-patch-1-create-pr.yml',
@@ -93,7 +94,30 @@ jobs:
9394
dry_run: 'false',
9495
original_pr: '${{ github.event.issue.number }}'
9596
}
96-
})
97+
});
98+
99+
// Wait a moment for the workflow to be created, then find it
100+
await new Promise(resolve => setTimeout(resolve, 2000));
101+
102+
const runs = await github.rest.actions.listWorkflowRuns({
103+
owner: context.repo.owner,
104+
repo: context.repo.repo,
105+
workflow_id: 'release-patch-1-create-pr.yml',
106+
per_page: 10
107+
});
108+
109+
// Find the most recent run that matches our trigger
110+
const dispatchedRun = runs.data.workflow_runs.find(run =>
111+
run.event === 'workflow_dispatch' &&
112+
new Date(run.created_at) > new Date(Date.now() - 10000) // Within last 10 seconds
113+
);
114+
115+
if (dispatchedRun) {
116+
core.setOutput('dispatched_run_id', dispatchedRun.id);
117+
core.setOutput('dispatched_run_url', dispatchedRun.html_url);
118+
}
119+
120+
core.setOutput('channel', channel);
97121
98122
- name: 'Comment on Failure'
99123
if: "startsWith(github.event.comment.body, '/patch') && steps.pr_status.outputs.STATE != 'MERGED'"
@@ -102,3 +126,54 @@ jobs:
102126
issue-number: '${{ github.event.issue.number }}'
103127
body: |
104128
:x: The `/patch` command failed. This pull request must be merged before a patch can be created.
129+
130+
- name: 'Final Status Comment - Success'
131+
if: "always() && startsWith(github.event.comment.body, '/patch') && steps.dispatch_patch.outcome == 'success' && steps.dispatch_patch.outputs.dispatched_run_url"
132+
uses: 'peter-evans/create-or-update-comment@67dcc547d311b736a8e6c5c236542148a47adc3d'
133+
with:
134+
issue-number: '${{ github.event.issue.number }}'
135+
body: |
136+
✅ **Patch workflow dispatched successfully!**
137+
138+
**📋 Details:**
139+
- **Channel**: `${{ steps.dispatch_patch.outputs.channel }}`
140+
- **Commit**: `${{ steps.pr_status.outputs.MERGE_COMMIT_SHA }}`
141+
142+
**🔗 Track Progress:**
143+
- [Dispatched patch workflow](${{ steps.dispatch_patch.outputs.dispatched_run_url }})
144+
- [This workflow run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
145+
146+
- name: 'Final Status Comment - Dispatch Success (No URL)'
147+
if: "always() && startsWith(github.event.comment.body, '/patch') && steps.dispatch_patch.outcome == 'success' && !steps.dispatch_patch.outputs.dispatched_run_url"
148+
uses: 'peter-evans/create-or-update-comment@67dcc547d311b736a8e6c5c236542148a47adc3d'
149+
with:
150+
issue-number: '${{ github.event.issue.number }}'
151+
body: |
152+
✅ **Patch workflow dispatched successfully!**
153+
154+
**📋 Details:**
155+
- **Channel**: `${{ steps.dispatch_patch.outputs.channel }}`
156+
- **Commit**: `${{ steps.pr_status.outputs.MERGE_COMMIT_SHA }}`
157+
158+
**🔗 Track Progress:**
159+
- [View patch workflows](https://github.com/${{ github.repository }}/actions/workflows/release-patch-1-create-pr.yml)
160+
- [This workflow run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
161+
162+
- name: 'Final Status Comment - Failure'
163+
if: "always() && startsWith(github.event.comment.body, '/patch') && (steps.dispatch_patch.outcome == 'failure' || steps.dispatch_patch.outcome == 'cancelled')"
164+
uses: 'peter-evans/create-or-update-comment@67dcc547d311b736a8e6c5c236542148a47adc3d'
165+
with:
166+
issue-number: '${{ github.event.issue.number }}'
167+
body: |
168+
❌ **Patch workflow dispatch failed!**
169+
170+
There was an error dispatching the patch creation workflow.
171+
172+
**🔍 Troubleshooting:**
173+
- Check that the PR is properly merged
174+
- Verify workflow permissions
175+
- Review error logs in the workflow run
176+
177+
**🔗 Debug Links:**
178+
- [This workflow run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
179+
- [Patch workflow history](https://github.com/${{ github.repository }}/actions/workflows/release-patch-1-create-pr.yml)

scripts/releasing/patch-create-comment.js

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
import yargs from 'yargs';
1515
import { hideBin } from 'yargs/helpers';
16-
import { readFileSync } from 'node:fs';
1716

1817
async function main() {
1918
const argv = await yargs(hideBin(process.argv))
@@ -27,11 +26,6 @@ async function main() {
2726
type: 'number',
2827
demandOption: !process.env.GITHUB_ACTIONS,
2928
})
30-
.option('output-log', {
31-
description: 'Path to the patch output log file',
32-
type: 'string',
33-
default: 'patch_output.log',
34-
})
3529
.option('commit', {
3630
description: 'The commit SHA being patched',
3731
type: 'string',
@@ -86,8 +80,6 @@ async function main() {
8680
argv.exitCode !== undefined
8781
? argv.exitCode
8882
: parseInt(process.env.EXIT_CODE || '1');
89-
const outputLog =
90-
argv.outputLog || process.env.OUTPUT_LOG || 'patch_output.log';
9183
const commit = argv.commit || process.env.COMMIT;
9284
const channel = argv.channel || process.env.CHANNEL;
9385
const repository =
@@ -111,7 +103,6 @@ async function main() {
111103
console.log('\n📋 Inputs:');
112104
console.log(` - Original PR: ${originalPr}`);
113105
console.log(` - Exit Code: ${exitCode}`);
114-
console.log(` - Output Log: ${outputLog}`);
115106
console.log(` - Commit: ${commit}`);
116107
console.log(` - Channel: ${channel} → npm tag: ${npmTag}`);
117108
console.log(` - Repository: ${repository}`);
@@ -121,20 +112,17 @@ async function main() {
121112
let commentBody;
122113
let logContent = '';
123114

124-
// Try to read the output log
125-
try {
126-
if (testMode) {
127-
// Create mock log content for testing
128-
if (exitCode === 0) {
129-
logContent = `Creating hotfix branch hotfix/v0.5.3/${channel}/cherry-pick-${commit.substring(0, 7)} from release/v0.5.3`;
130-
} else {
131-
logContent = 'Error: Failed to create patch';
132-
}
115+
// Get log content from environment variable or generate mock content for testing
116+
if (testMode && !process.env.LOG_CONTENT) {
117+
// Create mock log content for testing only if LOG_CONTENT is not provided
118+
if (exitCode === 0) {
119+
logContent = `Creating hotfix branch hotfix/v0.5.3/${channel}/cherry-pick-${commit.substring(0, 7)} from release/v0.5.3`;
133120
} else {
134-
logContent = readFileSync(outputLog, 'utf8');
121+
logContent = 'Error: Failed to create patch';
135122
}
136-
} catch (error) {
137-
console.log(`Could not read output log ${outputLog}:`, error.message);
123+
} else {
124+
// Use log content from environment variable
125+
logContent = process.env.LOG_CONTENT || '';
138126
}
139127

140128
if (logContent.includes('already has an open PR')) {

0 commit comments

Comments
 (0)