-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -34,6 +34,233 @@ jobs: | |||||||||||||||||||||||||||||||||||||
| steps: | ||||||||||||||||||||||||||||||||||||||
| - name: Execute pulsarbot command | ||||||||||||||||||||||||||||||||||||||
| id: pulsarbot | ||||||||||||||||||||||||||||||||||||||
| env: | ||||||||||||||||||||||||||||||||||||||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||||||||||||||||||||||||||||||||||||||
| uses: apache/pulsar-test-infra/pulsarbot@master | ||||||||||||||||||||||||||||||||||||||
| uses: actions/github-script@v7 | ||||||||||||||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||||||||||||||
| github-token: ${{ secrets.GITHUB_TOKEN }} | ||||||||||||||||||||||||||||||||||||||
| script: | | ||||||||||||||||||||||||||||||||||||||
| // Supported commands: | ||||||||||||||||||||||||||||||||||||||
| // - /pulsarbot rerun | ||||||||||||||||||||||||||||||||||||||
| // Reruns all completed workflows with conclusions of failure/timed_out/skipped/cancelled | ||||||||||||||||||||||||||||||||||||||
| // If workflow is still running, cannot rerun whole workflow, just suggest using "/pulsarbot rerun jobname" | ||||||||||||||||||||||||||||||||||||||
| // - /pulsarbot rerun jobname | ||||||||||||||||||||||||||||||||||||||
| // Matches job.name by keyword, reruns matching jobs (regardless of current state, failures are logged) | ||||||||||||||||||||||||||||||||||||||
| // - /pulsarbot stop or /pulsarbot cancel | ||||||||||||||||||||||||||||||||||||||
| // Cancels all still running (queued/in_progress) workflow runs associated with the current PR | ||||||||||||||||||||||||||||||||||||||
| const commentBody = context.payload.comment.body.trim(); | ||||||||||||||||||||||||||||||||||||||
| const prefix = '/pulsarbot'; | ||||||||||||||||||||||||||||||||||||||
| if (!commentBody.startsWith(prefix)) { | ||||||||||||||||||||||||||||||||||||||
| console.log('Not a pulsarbot command, skipping ...'); | ||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| if (!context.payload.issue || !context.payload.issue.pull_request) { | ||||||||||||||||||||||||||||||||||||||
| console.error('This comment is not on a Pull Request. pulsarbot only works on PRs.'); | ||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| const parts = commentBody.split(/\s+/); | ||||||||||||||||||||||||||||||||||||||
| const sub = (parts[1] || '').toLowerCase(); | ||||||||||||||||||||||||||||||||||||||
lhotari marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||
| 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'.`); | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
| 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(', ')}.`); |
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)
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 | |
| }); |
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.
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
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: