Skip to content

Conversation

@bhimrazy
Copy link
Collaborator

@bhimrazy bhimrazy commented Nov 19, 2025

What does this PR do ?

This PR updates the cpu-tests.yml workflow to select the correct trigger based on the author's association with the repository. It eliminates duplicate CI runs and ensures workflow modifications can be properly tested by maintainers.

Problem

Previously, when a collaborator opened a PR, two workflow runs would often trigger simultaneously:

  1. pull_request: Uses the PR's code and workflow file (but often lacks secrets if from a fork).
  2. pull_request_target: Uses the PR's code but ignores workflow changes, using the version from main instead.

This caused confusion because updates to the workflow file itself (e.g., changing python versions or steps) were ignored by the pull_request_target run, while the pull_request run might fail due to missing secrets.

Additionally, duplicate runs increased API requests to HuggingFace (eg: used in tokenizer test), occasionally hitting rate limits and blocking CI execution.

Solution

I have updated the if conditions in the pytester and testing-guardian jobs to enforce strict separation:

  • For Collaborators/Members:

    • The pull_request trigger runs.
    • The pull_request_target trigger is skipped.
    • Benefit: This uses the updated workflow file from the PR, allowing us to test CI changes. (Note: Branches must be pushed to the main repo to access secrets like HF_TOKEN).
  • For External Contributors (Forks):

    • The pull_request_target trigger runs.
    • The pull_request trigger is skipped.
    • Benefit: This securely runs tests using the trusted workflow definition from main while still having access to necessary secrets.

@bhimrazy bhimrazy self-assigned this Nov 19, 2025
@bhimrazy bhimrazy added the CI / actions Continuous integration label Nov 19, 2025
@bhimrazy bhimrazy requested review from Borda and Copilot November 19, 2025 08:12
Copilot finished reviewing on behalf of bhimrazy November 19, 2025 08:14
Copy link

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 optimizes the CI workflow trigger logic to prevent duplicate workflow runs by routing pull requests based on contributor type. Collaborators now use pull_request (which tests workflow changes from the PR), while external contributors use pull_request_target (which uses the trusted workflow from main).

  • Refactored job if conditions to enforce strict separation between pull_request and pull_request_target triggers based on author association
  • Updated comments to clearly explain the routing logic for different contributor types
  • Applied consistent logic to both pytester and testing-guardian jobs

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Labels

CI / actions Continuous integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant