From 673716fd197430a6d32d0c3d95950fb3d117314c Mon Sep 17 00:00:00 2001 From: pad Date: Mon, 21 Oct 2024 15:27:58 +0200 Subject: [PATCH] more --- .../workflows/semgrep-rules-test-develop.yml | 7 ++- .github/workflows/semgrep-rules-test.yml | 8 ++-- Makefile | 44 ++++++++++--------- 3 files changed, 32 insertions(+), 27 deletions(-) diff --git a/.github/workflows/semgrep-rules-test-develop.yml b/.github/workflows/semgrep-rules-test-develop.yml index 06db2cd0c9..2a759cc2d3 100644 --- a/.github/workflows/semgrep-rules-test-develop.yml +++ b/.github/workflows/semgrep-rules-test-develop.yml @@ -14,6 +14,8 @@ on: jobs: test-develop: name: rules-test-develop + # alt: use directly the semgrep/semgrep:pro-develop container here so we + # don't need the calls to 'docker run ...' below runs-on: ubuntu-20.04 # TODO: remove the with: path: below to simplify steps: @@ -21,10 +23,11 @@ jobs: with: path: semgrep-rules # alt: call 'make validate' but would require 'make' in the docker image - # alt: export SEMGREP="docker run semgrep" + # alt: export SEMGREP="docker run --rm -w ... semgrep" # make -C "$GITHUB_WORKSPACE"/semgrep-rules validate + #TODO: this actually currently fails because of errors in stats/ but GHA + # still continue, weird - name: run osemgrep validate --pro run: docker run --rm -w /src -v ${GITHUB_WORKSPACE}/semgrep-rules:/src semgrep/semgrep:pro-develop semgrep validate --pro . - # alt: call 'make test-only' but would require 'make' in the docker image - name: run osemgrep test --pro run: docker run --rm -w /src -v ${GITHUB_WORKSPACE}/semgrep-rules:/src semgrep/semgrep:pro-develop semgrep test --pro . diff --git a/.github/workflows/semgrep-rules-test.yml b/.github/workflows/semgrep-rules-test.yml index ac9672914e..5cd02cec82 100644 --- a/.github/workflows/semgrep-rules-test.yml +++ b/.github/workflows/semgrep-rules-test.yml @@ -17,13 +17,13 @@ jobs: - uses: actions/setup-python@v2 with: python-version: 3.9.2 - - name: install semgrep + - name: install semgrep via pip run: pip3 install semgrep - name: remove stats directory run: rm -rf stats - name: remove rules requiring Semgrep Pro run: rm -rf apex elixir - name: validate rules - run: semgrep --validate --config . - - name: run semgrep - run: semgrep --test --test-ignore-todo + run: semgrep validate . + - name: run semgrep test + run: semgrep test . diff --git a/Makefile b/Makefile index 70558b56ea..5d359b692a 100644 --- a/Makefile +++ b/Makefile @@ -1,33 +1,34 @@ # # Check rule validity and check that semgrep finds the expected findings. +# See https://semgrep.dev/docs/writing-rules/testing-rules for more info. # -# The semgrep repo also runs this as part of its CI for consistency. +# The semgrep repo (and now semgrep-pro repo) also runs those tests as part +# of its CI for consistency. # .PHONY: test test: $(MAKE) validate $(MAKE) test-only -# Use the SEMGREP environment variable to specify a non-standard semgrep -# command. This is useful for calling a development version of semgrep -# e.g. -# PIPENV_PIPFILE=~/semgrep/cli/Pipfile SEMGREP='pipenv run semgrep' make test +# Use the SEMGREP env variable to specify a non-standard semgrep command SEMGREP ?= semgrep -# TODO: semgrep validate use a different targeting than semgrep test +.PHONY: test-only +#old: pysemgrep --test was also using flags below but not needed +# --test-ignore-todo --strict --disable-version-check --metrics=off --verbose +test-only: + $(SEMGREP) test --pro . + +# TODO: semgrep validate use a different targeting than 'semgrep test' # so we unfortunately need this whitelist of dirs because it reports -# errors on stats/ and scripts/ (and .github yaml) files otherwise -# NOTE: the apex/ and elixir/ requires --pro (hence the --pro below) -# alt: we could also skip libsonnet/ and trusted_python/ -DIRS=\ - ai \ - apex \ +# errors on stats/ and scripts/ (and .github/workflows/) files otherwise +# (we also skip libsonnet/ and trusted_python/ which do not contain rules) +LANG_DIRS=\ bash \ c \ clojure \ csharp \ dockerfile \ - elixir \ generic \ go \ html \ @@ -35,10 +36,8 @@ DIRS=\ javascript \ json \ kotlin \ - libsonnet \ ocaml \ php \ - problem-based-packs \ python \ ruby \ rust \ @@ -46,9 +45,11 @@ DIRS=\ solidity \ swift \ terraform \ - trusted_python \ typescript \ yaml +PRO_DIRS=apex elixir +OTHER_DIRS=ai problem-based-packs +DIRS=$(LANG_DIRS) $(PRO_DIRS) $(OTHER_DIRS) .PHONY: validate #old: pysemgrep --validate was also using the flags below but not needed @@ -56,8 +57,9 @@ DIRS=\ validate: $(SEMGREP) validate --pro $(DIRS) -.PHONY: test-only -#old: pysemgrep --test was also using -# --test-ignore-todo --strict --disable-version-check --metrics=off --verbose -test-only: - $(SEMGREP) test --pro . +.PHONY: test-oss-only +test-oss-only: + @for dir in $(LANG_DIRS) $(OTHER_DIRS); do \ + echo "processing $$dir"; \ + $(SEMGREP) test $$dir; \ + done