Skip to content

Conversation

@phapalova
Copy link
Contributor

@phapalova phapalova commented Dec 17, 2025

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.

Command Description
/run-all Trigger all PR workflows (tests, codestyle, cu128, cu130)
/run-tests Trigger tests.yml only
/run-codestyle Trigger codestyle.yml only
/run-cu128 Trigger cu128.yml only
/run-cu130 Trigger cu130.yml only
/rerun-all Rerun all failed workflows

Signed-off-by: Petra Hapalova <[email protected]>
Signed-off-by: Petra Hapalova <[email protected]>
@phapalova phapalova marked this pull request as ready for review December 17, 2025 15:37
@phapalova phapalova requested a review from a team as a code owner December 17, 2025 15:37
Signed-off-by: Petra Hapalova <[email protected]>
Copy link
Contributor

Copilot AI left a 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_dispatch trigger 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
Copy link

Copilot AI Jan 26, 2026

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.

Suggested change
ref: ref
ref: ref,
inputs: {
branch: ref
}

Copilot uses AI. Check for mistakes.
Comment on lines +77 to +148
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
Copy link

Copilot AI Jan 26, 2026

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant