-
Notifications
You must be signed in to change notification settings - Fork 17
Add PR workflow commands #397
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: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Petra Hapalova <[email protected]>
Signed-off-by: Petra Hapalova <[email protected]>
Signed-off-by: Petra Hapalova <[email protected]>
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 adds a GitHub Actions workflow that enables maintainers to manually trigger CI workflows through PR comments. This is particularly useful for re-running workflows that didn't trigger automatically (e.g., due to draft PR state) or for manually re-running failed workflows.
Changes:
- New PR command workflow that responds to comment-based commands like
/run-all,/run-tests,/run-codestyle,/run-cu128,/run-cu130, and/rerun-all - Added
workflow_dispatchtrigger to cu128.yml, cu130.yml, and codestyle.yml to enable manual triggering - Implements authorization checks to restrict commands to repository owners, members, and collaborators
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| .github/workflows/pr-commands.yml | New workflow that listens for PR comments and triggers workflows or reruns failed ones based on commands |
| .github/workflows/cu130.yml | Added workflow_dispatch trigger to enable manual workflow execution |
| .github/workflows/cu128.yml | Added workflow_dispatch trigger to enable manual workflow execution |
| .github/workflows/codestyle.yml | Added workflow_dispatch trigger to enable manual workflow execution |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| workflow_id: workflow, | ||
| ref: ref |
Copilot
AI
Jan 26, 2026
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 tests.yml workflow has a required input parameter 'branch' (see tests.yml lines 24-29), but this workflow dispatch call doesn't provide it. This will cause the workflow dispatch to fail when triggering tests.yml. You need to add inputs to the createWorkflowDispatch call for tests.yml, providing the branch parameter with the value from pr.data.head.ref.
| ref: ref | |
| ref: ref, | |
| inputs: { | |
| branch: ref | |
| } |
| const pr = await github.rest.pulls.get({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| pull_number: context.issue.number | ||
| }); | ||
| const ref = pr.data.head.ref; | ||
| console.log(`PR branch: ${ref}`); | ||
|
|
||
| const comment = context.payload.comment.body; | ||
|
|
||
| const workflowMap = { | ||
| '/run-tests': 'tests.yml', | ||
| '/run-codestyle': 'codestyle.yml', | ||
| '/run-cu128': 'cu128.yml', | ||
| '/run-cu130': 'cu130.yml' | ||
| }; | ||
|
|
||
| // Helper to check if command is present (with word boundary) | ||
| const hasCommand = (cmd) => new RegExp(`${cmd}(?:\\s|$)`).test(comment); | ||
|
|
||
| // Determine which workflows to run | ||
| let workflowsToRun = []; | ||
| if (hasCommand('/run-all')) { | ||
| workflowsToRun = Object.values(workflowMap); | ||
| } else { | ||
| for (const [command, workflow] of Object.entries(workflowMap)) { | ||
| if (hasCommand(command)) { | ||
| workflowsToRun.push(workflow); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Helper to find the triggered run with retries | ||
| async function findWorkflowRun(workflowId, beforeTime) { | ||
| const maxRetries = 5; | ||
| const delayMs = 3000; | ||
|
|
||
| for (let attempt = 1; attempt <= maxRetries; attempt++) { | ||
| await new Promise(resolve => setTimeout(resolve, delayMs)); | ||
| console.log(`Looking for ${workflowId} run (attempt ${attempt}/${maxRetries})...`); | ||
|
|
||
| const runs = await github.rest.actions.listWorkflowRuns({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| workflow_id: workflowId, | ||
| branch: ref, | ||
| per_page: 10, | ||
| event: 'workflow_dispatch' | ||
| }); | ||
|
|
||
| const run = runs.data.workflow_runs.find(r => | ||
| new Date(r.created_at) >= beforeTime | ||
| ); | ||
|
|
||
| if (run) { | ||
| console.log(`Found run: ${run.html_url}`); | ||
| return run; | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| const results = []; | ||
| for (const workflow of workflowsToRun) { | ||
| const beforeTime = new Date(); | ||
| try { | ||
| console.log(`Triggering ${workflow} on ref ${ref}`); | ||
| await github.rest.actions.createWorkflowDispatch({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| workflow_id: workflow, | ||
| ref: ref |
Copilot
AI
Jan 26, 2026
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.
This workflow will fail for PRs from forks because pr.data.head.ref contains only the branch name, which doesn't exist in the base repository for forked PRs. The createWorkflowDispatch API can only trigger workflows on branches/tags that exist in the target repository. Consider checking if the PR is from a fork (pr.data.head.repo.fork === true or pr.data.head.repo.id !== pr.data.base.repo.id) and either skip the operation with an appropriate error message, or use a different ref format. Note that workflow_dispatch fundamentally cannot be triggered on fork branches, so you may need to document this limitation.
Adds a new GitHub Actions workflow that allows maintainers to trigger CI workflows via PR comments. This is useful when workflows need to be re-run manually or when the automatic triggers didn't fire due to PR draft state.
/run-all/run-teststests.ymlonly/run-codestylecodestyle.ymlonly/run-cu128cu128.ymlonly/run-cu130cu130.ymlonly/rerun-all