Prevent actions from running in forks#3938
Merged
cheenamalhotra merged 2 commits intodotnet:mainfrom Feb 6, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds fork prevention checks to GitHub Actions workflows to ensure they only run in the main repository, not in forked repositories. This addresses issue #3924 by preventing unnecessary workflow executions in forks.
Changes:
- Added conditional checks to prevent workflows from running in forked repositories
- Applied the fork check to both the stale issues/PRs cleanup workflow and the CodeQL security analysis workflow
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| .github/workflows/stale.yml | Added fork check to prevent stale issue/PR cleanup from running in forks |
| .github/workflows/codeql.yml | Added fork check to prevent CodeQL security analysis from running in forks |
.github/workflows/stale.yml
Outdated
| jobs: | ||
| close-stale: | ||
| runs-on: ubuntu-latest | ||
| if: github.event.repository.fork != true |
There was a problem hiding this comment.
The condition uses != true which will also evaluate to true when the value is null or undefined. For more explicit fork detection, use github.event.repository.fork == false or !github.event.repository.fork to ensure the check only passes when the repository is definitively not a fork.
Suggested change
| if: github.event.repository.fork != true | |
| if: github.event.repository.fork == false |
cheenamalhotra
approved these changes
Feb 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This change prevents GitHub actions from running in any fork
Issues
fixes #3924