/semgrep-library

Semgrep rule "components"

Primary LanguageMakefileMIT LicenseMIT

template-rules

powered by semgrep r2c community slack

a template repo for semgrep rules and semgrep performance.

Geting started

This guide assumes you are familiar with Semgrep and have it already installed.

  1. Test out this template repo with the following command:
git clone https://github.com/semgrep/template-rules.git

To test out the rules template, run:

semgrep --config template-rules/rules template-rules/rules/hello-world.py

To test out the benchmarking scripts in semgrep/perf, run:

cd semgrep/perf
make

or refer to https://github.com/returntocorp/semgrep/tree/develop/perf.

  1. Copy this template to your own repo.

Performance CI Configurations


What are these for?

These configurations are Github Action scripts that you can run in CI. You can find them in perf-templates.

benchmark-tests.yml benchmark-tests.yml is a YAML file that runs the timing benchmark with source code in perf.

The Run Timing Benchmark With Latest Semgrep Version action runs the benchmark script with the following flags:

  • --small-only: runs the script on small benchmarking repositories only, as compared to medium-sized or large-sized repositories.
  • --std-only: runs semgrep with no optimization flags.
  • --output-time-per-rule-json: outputs a JSON file that states the total time taken per rule per repository and the average time taken per rule.

The Run Timing Benchmark With Specified Config File action runs the benchmark script with the additional flag:

  • --config: runs the benchmarking script using the repositories and rules specified in a YAML config file.

config-template.yml config-template.yml is a YAML file that lets the user specify which repositories and rules to run the benchmarking scripts on. Feeding this file into the --config flag for the run-benchmarks script in the semgrep/perf folder.

How can I use these?

  1. Copy the desired configuration files into your .github/workflows folder.
  2. Change these configuration templates as needed.
  3. Create a pull request with these changes and see if the appropriate tests are running in your Github Actions!

Rule Templates

  1. Add your rules (and their test files) to the rules folder
  2. Iterate rules and ensure they pass the built-in tests
  3. Open a PR to the Awesome Semgrep list
  4. Ask for help in the Semgrep community slack any time 👋