Skip to content

ci: add Tekton Task for /retest slash command#3246

Open
sahilleth wants to merge 1 commit into
tektoncd:mainfrom
sahilleth:slash-retest-task
Open

ci: add Tekton Task for /retest slash command#3246
sahilleth wants to merge 1 commit into
tektoncd:mainfrom
sahilleth:slash-retest-task

Conversation

@sahilleth
Copy link
Copy Markdown

@sahilleth sahilleth commented Mar 19, 2026

Changes

Implements a minimal Tekton Task and Pipeline for the /retest slash command as part of migrating chatops from GitHub Actions to Tekton (dogfooding cluster).

This PR establishes a simple and extensible baseline for /retest behavior aligned with the plumbing migration effort.

Implementation

Adds a slash-retest Task at tekton/ci/slash-commands/retest-pipeline.yaml.

Parameters:

  • repository: GitHub repository in owner/repo format
  • pull_request_number: PR number invoking /retest
  • commit_sha (optional): commit to inspect; if not provided, resolves PR head SHA via GitHub API
  • check_name_prefix (optional): filter failed checks by name prefix
  • dry_run: "true" or "false" (default "false")

Behavior:

  • Resolves PR head SHA when commit_sha is not provided
  • Lists check runs using gh api
  • Filters failed check runs (status == completed, conclusion == failure)
  • Optionally filters by check_name_prefix
  • Re-runs failed checks using gh run rerun when possible
  • If external_id is not available, skips rerun and logs the behavior
  • Supports dry_run mode for safe validation without triggering re-runs
  • Optionally adds a reaction to the PR to indicate successful processing

Pipeline

Adds a slash-retest Pipeline that directly invokes the Task.

The Pipeline is designed to be triggered via Tekton Triggers (EventListener → TriggerBinding → TriggerTemplate) from issue_comment webhooks.

Integration (High-Level)

  • GitHub issue_comment webhook receives /retest

  • TriggerBinding maps:

    • repository$(body.repository.full_name)
    • pull_request_number$(body.issue.number)
    • commit_sha (optional)
  • TriggerTemplate creates a PipelineRun for slash-retest

Design Notes

  • Keeps implementation in a single Task to minimize complexity
  • Avoids hardcoded values and keeps logic parameterized
  • Uses gh CLI with GH_TOKEN / GITHUB_TOKEN
  • dry_run mode enables safe testing during rollout

This PR focuses on providing a minimal, functional baseline. Additional refinements (e.g., advanced filtering or extended command support) can be introduced incrementally in follow-up PRs based on feedback.

Related Issues

Fixes #3126
Part of #3121

Release Notes

Add a slash-retest Task and Pipeline in tektoncd/plumbing to implement the /retest chatops command using Tekton. The Task resolves the PR head SHA, re-runs failed GitHub Actions checks, and supports dry-run mode for safe validation.

@tekton-robot tekton-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Mar 19, 2026
@sahilleth
Copy link
Copy Markdown
Author

/kind cleanup

@tekton-robot tekton-robot added the kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. label Mar 19, 2026
@sahilleth
Copy link
Copy Markdown
Author

/assign @savitaashture

@sahilleth
Copy link
Copy Markdown
Author

Hi @vdemeester ,
Just a gentle follow-up on this - happy to make any changes if needed.
Also worked on the /rebase implementation alongside this as part of the same migration.

Copy link
Copy Markdown
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few comments, I don't think this would work as is today. Sorry for the late review 🙏🏼

@@ -0,0 +1,166 @@
apiVersion: tekton.dev/v1beta1
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use tekton.dev/v1 here instead of v1beta1.

default: "false"
steps:
- name: rerun-failed-checks-and-react
image: ghcr.io/github/cli/gh:latest
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ghcr.io/github/cli/gh:latest is Alpine-based. mapfile is a bash builtin not available in Alpine's default /bin/sh. The shebang says #!/usr/bin/env bash but the image may not have bash — only sh/ash.

So this is likely to fail at runtime.

echo "Starting /retest for ${repo}#${pr}"

# gh uses GH_TOKEN or GITHUB_TOKEN for authentication.
if [[ -z "${GH_TOKEN:-${GITHUB_TOKEN:-}}" ]]; then
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How are those environment variables (GITHUB_TOKEN or GH_TOKTEN) provided ?

gh api \
-X POST \
-H "Accept: application/vnd.github+json" \
"repos/${repo}/issues/${pr}/reactions" \
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will add a reaction to the PR isn't it ? Not to the comment that issued /retest.

Comment on lines +89 to +92
mapfile -t run_ids < <(
gh api "repos/${repo}/commits/${sha}/check-runs" --paginate \
--jq "${jq_filter} | .external_id // empty"
)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

external_id is not the workflow run ID. GitHub Actions sets external_id to a UUID (e.g., 5cd96773-9f60-588e-974c-6bbce156716f), not the numeric run ID that gh run rerun expects. As a result, the rerun step will silently fail. The run ID can be extracted from details_url instead:

.details_url | capture("runs/(?<id>[0-9]+)") | .id

Results should be deduplicated with sort -u since multiple failed jobs within the same workflow share the same run ID.

@tekton-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To complete the pull request process, please ask for approval from savitaashture after the PR has been reviewed.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create Tekton Task/Pipeline for /retest slash command

4 participants