Skip to content

Fix files changed workflow to not run on external repositories #4417

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 4, 2025

The GitHub Action for adding files changed labels was running on external repositories (forks), which could cause permission issues and unnecessary resource consumption.

Problem

The workflow was using shell script logic to check for external repositories and exit early:

# Check if PR is from a fork (external repository)
if [[ "$PR_HEAD_REPO" != "$BASE_REPO" ]]; then
  echo "This PR is from an external repository: $PR_HEAD_REPO"
  echo "Skipping label operations for external repository PR to avoid permission issues."
  exit 0
fi

This approach still executed the job and consumed resources, even though it exited early.

Solution

Replaced the shell script check with GitHub Actions' native conditional logic:

jobs:
  add_files_changed_label:
    if: github.event.pull_request.head.repo.full_name == github.repository
    runs-on: ubuntu-latest

Changes Made

  • Added job-level conditional: if: github.event.pull_request.head.repo.full_name == github.repository
  • Removed redundant shell script logic: No longer needs to check and exit within the script
  • Cleaned up environment variables: Removed PR_HEAD_REPO and BASE_REPO which are no longer needed

Benefits

  • No job execution on external repositories: Job won't run at all instead of running and exiting early
  • Resource efficiency: Saves compute resources by preventing unnecessary job execution
  • Cleaner logs: No unnecessary log entries for external repository PRs
  • GitHub Actions best practice: Uses native conditional logic instead of shell script workarounds
  • Maintains all existing functionality: All core workflow features preserved

Testing

The conditional github.event.pull_request.head.repo.full_name == github.repository will:

  • Return true for PRs from the same repository (including different branches)
  • Return false for PRs from forks/external repositories
  • When the condition is false, the job won't execute at all

Fixes #4416.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@Copilot Copilot AI changed the title [WIP] make it so that the files changed github action does not run on external repositories Fix files changed workflow to not run on external repositories Jul 4, 2025
@Copilot Copilot AI requested a review from DonnieBLT July 4, 2025 18:38
Copilot finished work on behalf of DonnieBLT July 4, 2025 18:38
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.

make it so that the files changed github action does not run on external repositories
2 participants