Skip to content

Approve GitHub Actions workflow runs on /ok-to-test#612

Merged
k8s-ci-robot merged 1 commit into
kubernetes-sigs:mainfrom
cblecker:feat/approve-workflow-runs
Feb 6, 2026
Merged

Approve GitHub Actions workflow runs on /ok-to-test#612
k8s-ci-robot merged 1 commit into
kubernetes-sigs:mainfrom
cblecker:feat/approve-workflow-runs

Conversation

@cblecker

@cblecker cblecker commented Feb 5, 2026

Copy link
Copy Markdown
Member

Summary

When /ok-to-test is issued by a trusted user and TriggerGitHubWorkflows is enabled, automatically approve any pending GitHub Actions workflow runs for the PR. This enables a unified workflow where /ok-to-test both triggers Prow jobs AND approves GitHub Actions workflows from fork PRs.

Changes

GitHub Client (pkg/github/client.go)

  • Added GetPendingApprovalActionRuns method to retrieve workflow runs with status=action_required for a PR's head SHA
  • Added ApproveGitHubWorkflowRun method to approve pending workflow runs via GitHub API
  • Updated Client interface to include both new methods

Trigger Plugin (pkg/plugins/trigger/)

  • Added approval logic in generic-comment.go that triggers on /ok-to-test when TriggerGitHubWorkflows=true
  • Added approveGitHubActionsWorkflowRuns helper function that:
    • Fetches pending workflow runs for the PR head SHA
    • Approves each run asynchronously using goroutines
    • Handles errors gracefully (403/404 logged at info level, others at error level)
    • Logs SHA used in lookup for debugging PR head sync issues
  • Updated githubClient interface in trigger.go to include new methods

Fake Client (pkg/github/fakegithub/fakegithub.go)

  • Added PendingApprovalRuns field to track pending runs by "org/repo/branch/sha"
  • Added ApprovedWorkflowRuns field to track approval attempts
  • Implemented fake versions of both new methods for testing

Tests

  • GitHub Client Tests (pkg/github/client_test.go):

    • TestGetPendingApprovalActionRuns - Verifies API calls with correct query parameters (status=action_required, event filters)
    • TestApproveGitHubWorkflowRun - Tests successful approval and error cases (201, 403, 404)
  • Trigger Plugin Tests (pkg/plugins/trigger/generic-comment_test.go):

    • TestApproveGitHubActionsWorkflowRuns - Comprehensive test covering:
      • Approval triggers on /ok-to-test with TriggerGitHubWorkflows=true
      • No approval when TriggerGitHubWorkflows=false
      • No approval on /test all or /retest
      • No approval when IgnoreOkToTest=true
      • Handles multiple pending runs ✓
      • Gracefully handles no pending runs ✓

Behavior

When approval is triggered:

  • Only on /ok-to-test command (not /test all or /retest)
  • Only when TriggerGitHubWorkflows configuration flag is enabled
  • Only for pull_request and pull_request_target triggered workflows

Error handling:

  • 403 (already approved) and 404 (run completed) errors are logged at info level as expected cases
  • Unexpected errors are logged at error level
  • Errors do not block the /ok-to-test command from proceeding

Design rationale:

  • Reuses existing TriggerGitHubWorkflows flag (semantic expansion - existing users automatically get this behavior)
  • Asynchronous approval via goroutines prevents blocking the main workflow
  • Best-effort approach ensures the core /ok-to-test functionality isn't impacted by approval failures

Testing

All tests pass:

go test ./pkg/github/... -run 'TestGetPendingApprovalActionRuns|TestApproveGitHubWorkflowRun' -v
go test ./pkg/plugins/trigger/... -run 'TestApproveGitHubActionsWorkflowRuns' -v

No regressions in existing test suites:

go test ./pkg/github/...
go test ./pkg/plugins/trigger/...

@netlify

netlify Bot commented Feb 5, 2026

Copy link
Copy Markdown

Deploy Preview for k8s-prow ready!

Name Link
🔨 Latest commit 0f2446a
🔍 Latest deploy log https://app.netlify.com/projects/k8s-prow/deploys/6984043eeaeac20008b6de46
😎 Deploy Preview https://deploy-preview-612--k8s-prow.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@k8s-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cblecker

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

The pull request process is described 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

@k8s-ci-robot k8s-ci-robot requested a review from cjwagner February 5, 2026 02:10
@k8s-ci-robot k8s-ci-robot added the area/plugins Issues or PRs related to prow's plugins for the hook component label Feb 5, 2026
@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Feb 5, 2026
Add automatic approval of pending GitHub Actions workflow runs when
/ok-to-test is issued by a trusted user with TriggerGitHubWorkflows enabled.

Changes:
- Add GetPendingApprovalActionRuns and ApproveGitHubWorkflowRun methods to GitHub client
- Update trigger plugin interface to include new methods
- Add approval logic in generic-comment handler for /ok-to-test command
- Implement fake client methods for testing
- Add comprehensive unit tests for all new functionality

The approval:
- Only triggers on /ok-to-test (not /test all or /retest)
- Only approves pull_request and pull_request_target triggered workflows
- Handles errors gracefully (403/404 logged at info level)
- Logs SHA for debugging PR head sync issues
- Uses goroutines for non-blocking approval

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@cblecker cblecker force-pushed the feat/approve-workflow-runs branch from 0cb79d4 to 0f2446a Compare February 5, 2026 02:45
@Prucek

Prucek commented Feb 6, 2026

Copy link
Copy Markdown
Member

/lgtm
Just curious, what is the current state? What/Who approves the GitHub actions?

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 6, 2026
@k8s-ci-robot k8s-ci-robot merged commit 85e3dda into kubernetes-sigs:main Feb 6, 2026
11 checks passed
@cblecker cblecker deleted the feat/approve-workflow-runs branch February 6, 2026 15:39
@stevehipwell

Copy link
Copy Markdown

@cblecker would this be implemented for a net-new project by adding an entry to triggers in the plugins config file of kubernetes/test-infra? There are a couple of sigs projects where I've implemented this directly in GH Actions and would like to swap over to this implementation. Are there any side effects to be aware of?

@cblecker

cblecker commented Mar 4, 2026

Copy link
Copy Markdown
Member Author

@stevehipwell Yup, that should be all it takes. No side effects that I've seen so far.

@stevehipwell

Copy link
Copy Markdown

@cblecker for clarity, I meant what (if any) are the side effects of adding a repo to triggers not specifically the GitHub automation setting.

@cblecker

cblecker commented Mar 5, 2026

Copy link
Copy Markdown
Member Author

@stevehipwell

Copy link
Copy Markdown

@cblecker I'm just checking that by adding repos (metrics-server & external-dns) to the triggers to get the new behaviour (and replace a custom workflow), I wont introduce any new behaviour as a side effect?

@cblecker

cblecker commented Mar 5, 2026

Copy link
Copy Markdown
Member Author

@stevehipwell No, I am not aware of any side effects. That doesn't mean you might not find any as we're all just humans working with code, but to the best of my knowledge and experience, this is pretty straight forward. If you do find anything strange, feel free to open an issue. 😄

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

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. area/plugins Issues or PRs related to prow's plugins for the hook component cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. 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.

4 participants