-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[improve][ci] update pulsarbot to use github-script based implementation #24940
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Co-authored-by: Lari Hotari <[email protected]>
lhotari
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
/pulsarbot rerun-failure-checks |
| continue; | ||
| } | ||
| try { | ||
| await github.rest.actions.reRunWorkflow({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to LLM, this should use reRunWorkflowFailedJobs instead of reRunWorkflow to rerun only the failed jobs.
| await github.rest.actions.reRunWorkflow({ | |
| await github.rest.actions.reRunWorkflowFailedJobs({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Octokit API reference: https://octokit.github.io/rest.js/v22/#actions-re-run-workflow-failed-jobs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR replaces the external apache/pulsar-test-infra/pulsarbot@master action with an inline implementation using actions/github-script@v7. The change provides direct control over the pulsarbot functionality for managing PR workflow runs.
Key changes:
- Migrated from external action to inline JavaScript implementation
- Implements commands:
/pulsarbot rerun,/pulsarbot rerun <jobname>,/pulsarbot stop/cancel, and/pulsarbot rerun-failure-checks - Adds comprehensive logging and error handling for workflow/job management operations
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const arg = parts.length > 2 ? parts.slice(2).join(' ') : ''; | ||
| const supported = ['rerun', 'stop', 'cancel', 'rerun-failure-checks']; | ||
| if (!supported.includes(sub)) { | ||
| console.log(`Unsupported command '${sub}'. Supported: '/pulsarbot rerun [jobName?]', '/pulsarbot stop', '/pulsarbot cancel'.`); |
Copilot
AI
Nov 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message lists supported commands but omits 'rerun-failure-checks' which is included in the supported array on line 62. The message should include all supported commands or reference them generically.
| console.log(`Unsupported command '${sub}'. Supported: '/pulsarbot rerun [jobName?]', '/pulsarbot stop', '/pulsarbot cancel'.`); | |
| console.log(`Unsupported command '${sub}'. Supported: ${supported.map(cmd => `'/pulsarbot ${cmd}'`).join(', ')}.`); |
| if (github.rest.actions.reRunJobForWorkflowRun) { | ||
| await github.rest.actions.reRunJobForWorkflowRun({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| job_id: job.id | ||
| }); | ||
| } else { | ||
| await github.request('POST /repos/{owner}/{repo}/actions/jobs/{job_id}/rerun', { | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| job_id: job.id | ||
| }); | ||
| } |
Copilot
AI
Nov 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fallback logic checks if reRunJobForWorkflowRun exists at runtime, but this adds unnecessary complexity. The GitHub REST API for rerunning jobs should be consistently available in the @v7 version of actions/github-script. Consider using only the primary method or documenting why the fallback is necessary.
| if (github.rest.actions.reRunJobForWorkflowRun) { | |
| await github.rest.actions.reRunJobForWorkflowRun({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| job_id: job.id | |
| }); | |
| } else { | |
| await github.request('POST /repos/{owner}/{repo}/actions/jobs/{job_id}/rerun', { | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| job_id: job.id | |
| }); | |
| } | |
| await github.rest.actions.reRunJobForWorkflowRun({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| job_id: job.id | |
| }); |
| if (fullRerunCount === 0) { | ||
| console.error(`No eligible workflow runs to re-run. Skipped running=${skippedRunning}, skipped by conclusion=${skippedConclusion}.`); | ||
| } else { | ||
| console.log(`Finished. Triggered full re-run for ${fullRerunCount} workflow run(s). Skipped running=${skippedRunning}, skipped by conclusion=${skippedConclusion}.`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no intention to do a "full re-run". Please update this comment to be consistent with the intention about re-running failed jobs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
full re-run: https://docs.github.com/en/rest/actions/workflow-runs?apiVersion=2022-11-28#re-run-a-workflow / https://octokit.github.io/rest.js/v22/#actions-re-run-workflow
re-run failed jobs: https://docs.github.com/en/rest/actions/workflow-runs?apiVersion=2022-11-28#re-run-failed-jobs-from-a-workflow-run / https://octokit.github.io/rest.js/v22/#actions-re-run-workflow-failed-jobs
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| uses: apache/pulsar-test-infra/pulsarbot@master | ||
| uses: actions/github-script@v7 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use most recent version, v8:
| uses: actions/github-script@v7 | |
| uses: actions/github-script@v8 |
| let page = 1; | ||
| const allRunsRaw = []; | ||
| while (true) { | ||
| const { data } = await github.rest.actions.listWorkflowRunsForRepo({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| actor: prUser, | ||
| branch: prBranch, | ||
| per_page: 100, | ||
| page | ||
| }); | ||
| const wr = data.workflow_runs || []; | ||
| if (wr.length === 0) break; | ||
| allRunsRaw.push(...wr); | ||
| if (wr.length < 100) break; | ||
| page++; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Octokit has built-in support for pagination and retrieving all results in a single call: https://github.com/octokit/octokit.js?tab=readme-ov-file#pagination (check the last example for the single call)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #24940 +/- ##
=============================================
+ Coverage 38.46% 74.33% +35.86%
- Complexity 13239 33535 +20296
=============================================
Files 1856 1913 +57
Lines 145283 149446 +4163
Branches 16876 17362 +486
=============================================
+ Hits 55890 111088 +55198
+ Misses 81827 29505 -52322
- Partials 7566 8853 +1287
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
Motivation
The ci-pulsarbot.yaml is slightly out-dated, update pulsarbot with github-script
Verifying this change
test in liangyepianzhou#19
Documentation
docdoc-requireddoc-not-neededdoc-complete