Use GitHub repository rulesets to quickly implement Semgrep scans across hundreds or thousands of repositories in your GitHub organization. Repository rulesets allow you to add a Semgrep scan as a workflow that is required for pull requests to pass before merging. Formerly, this feature was called required workflows. Repository rulesets use a centralized workflow file to execute the Semgrep scan action, meaning you can run scans on pull requests in as many repositories as desired by creating a single file.Documentation Index
Fetch the complete documentation index at: https://docs.semgrep.dev/llms.txt
Use this file to discover all available pages before exploring further.
Set up the central Semgrep scan workflow
To use the Semgrep workflow in other repositories owned by your organization, you can create a new repository in the organization with the Semgrep workflow file, or add it to an existing repository where you store common workflows. This example describes creating the workflow in a new repository calledsemgrep-workflow.
Create a new repository following the GitHub documentation.
Choose the repository visibility that matches the widest visibility of the repositories you want to run the workflow in. For example, if you want to run Semgrep on public, internal, and private repositories, the repository containing the workflow file must be public.
Add the Semgrep workflow file to the repository at
.github/workflows/semgrep.yml. You can use the sample configuration provided in the documentation, or a custom configuration.
Behavior with bot-initiated commits
The default Semgrep GitHub Actions configuration excludes any PRs or commits from GitHub’sdependabot to prevent permissions errors. If you have other bots or automations active in your organization’s workflows, consider excluding these bots as well. Otherwise, the action may error due to bot permissions, or it may simply not be useful to run a Semgrep scan on changes made by an automation. For example, to exclude both dependabot and other GitHub Actions, include:
Recommended configuration with merge queues
If you use merge queues for repositories scanned with this workflow, your config must includemerge_group as a trigger in the on: block. Otherwise, the workflow cannot run in the merge queue and can block the queue.
Unlike for pull_request event types, Semgrep does not have any automatic configuration to run diff-aware scans on merge_group events, so additional configuration is needed to run diff-aware scans in this environment. The most straightforward solution is to configure the workflow to be skipped during the merge group check, since the primary goal of a Semgrep diff-aware scan is to inform the developer before merging if they are introducing security issues.
With the recommended alterations and removal of event types that do not occur with repository rulesets, the sample configuration would look like this:
Configure repository workflow access
The repository containing the Semgrep workflow must allow access to workflows from other repositories in the organization. To configure access:Configure an organization secret
To run a scan usingsemgrep ci, Semgrep requires a valid token. When configuring Semgrep as a required workflow for multiple repositories, set up the token as an organization secret.
INFOIf you use a custom
semgrep.yml configuration, ensure you refer to the secret as ${{ secrets.SEMGREP_APP_TOKEN }} in your configuration. For the required workflow, this refers to the organization secret.Click Create new token on Settings > Tokens in the Semgrep AppSec Platform.
Create an organization secret, following the GitHub documentation.
Select a value for Repository access that matches the repositories you intend to scan with the workflow.
Create an organization ruleset
To create the ruleset:Configure the enforcement status, bypass list, target repositories, and target branches based on your organization policies.
In the Pick a workflow file field, click and select the Semgrep workflow you created in Setting up the central Semgrep scan workflow.
Verify by creating a pull request
After completing the preceding steps, create a pull request in an affected repository to verify the workflow runs as expected.Create a pull request in that repository, following the GitHub documentation.

Limitations
Workflows required by repository rulesets are only triggered bypull_request or merge_group events. When triggered for a pull request, Semgrep runs a diff-aware scan, which only scans changed files.
To run full scans (scan all files) for your organization’s repositories as well, you would need to supplement this setup with another approach, such as reusable workflows.
.