Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions .github/workflows/semgrep.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ on:
workflow_dispatch: {}
schedule:
- cron: "0 4 * * *"
pull_request: {}

name: Semgrep config
permissions:
contents: read

jobs:
semgrep:
name: semgrep/ci
name: semgrep
runs-on: ubuntu-latest
env:
SEMGREP_APP_TOKEN: ${{ secrets.SEMGREP_APP_TOKEN }}
Expand All @@ -18,4 +21,35 @@ jobs:
image: semgrep/semgrep
steps:
- uses: actions/checkout@v4
- run: semgrep ci
with:
# fetch full history so Semgrep can compare against the base branch
fetch-depth: 0

# Semgrep CI to run on Schedule (Cron) or Manual Dispatch
# scans using managed rules at cloudflare.semgrep.dev
- name: Semgrep CI Rules (Managed rules at cloudflare.semgrep.dev)
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
run: semgrep ci

# Semgrep Scan to run on Pull Request events
# scans using rules inside the .semgrep/ folder and fails on error
# include [skip semgrep] in top-most commit message to skip scan
- name: Semgrep Repo Rules (Custom rules found in .semgrep/)
if: github.event_name == 'pull_request' && !contains(github.event.head_commit.message, '[skip semgrep]')
run: |

git config --global --add safe.directory $PWD
base_commit=$(git merge-base HEAD origin/$GITHUB_BASE_REF)
git diff $base_commit... --diff-filter=ACMRT --name-only | grep -E '\.(htm|html|yaml|yml|md|mdx)$' > tools/relevant_changed_files.txt || true

# Check if file list is empty to prevent errors
if [ -s tools/relevant_changed_files.txt ]; then
list_of_files=$(cat tools/relevant_changed_files.txt | tr '\n' ' ')
semgrep scan \
--config .semgrep --metrics=off \
--include "*.mdx" --include "*.mdx" \
$list_of_files
# add '--error' to return error code to workflow
else
echo "No relevant files changed."
fi
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ pnpm-debug.log*
/worker/functions/

.idea

tools/relevant_changed_files.txt
41 changes: 41 additions & 0 deletions .semgrep/dates-in-docs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
rules:
- id: coming-soon
languages: [generic]
message: "Found forbidden string 'coming soon'. Too often we set expectations unfairly by attaching this phrase to a feature that may not actually arrive soon."
severity: MEDIUM
paths:
include:
- "*.htm"
- "*.html"
- "*.md"
- "*.mdx"
- "*.yaml"
- "*.yml"
exclude:
- "/src/content/changelog/**"
- "/src/content/release-notes/**"
- "/.semgrep/**"
- "/.github/**"
patterns:
- pattern-regex: "[Cc]oming [Ss]oon"

- id: potential-date
languages: [generic]
message: "Potential date found. Documentation should strive to represent universal truth, not something time-bound."
severity: MEDIUM
paths:
include:
- "*.htm"
- "*.html"
- "*.md"
- "*.mdx"
- "*.yaml"
- "*.yml"
exclude:
- "/src/content/changelog/**"
- "/src/content/release-notes/**"
- "/.semgrep/**"
- "/.github/**"
pattern-either:
- pattern-regex: Jan\| Feb\| Mar\| Apr\| May\| Jun\| Jul\| Aug\| Sep\| Nov\| Dec
- pattern-regex: \ 20[0-9][0-9]
26 changes: 26 additions & 0 deletions tools/semgrep-repo-rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#! /bin/bash

repo_root_dir="$(git rev-parse --show-toplevel)"

pushd "${repo_root_dir}" > /dev/null || return

base_commit=$(git merge-base HEAD origin/production)
git diff $base_commit... --diff-filter=ACMRT --name-only | grep -E '\.(htm|html|yaml|yml|md|mdx)$' > tools/relevant_changed_files.txt || true

# this file wants to also match uncommitted changes, not just commited changes (in CI this is not the case)
git diff --diff-filter=ACMRT --name-only | grep -E '\.(htm|html|yaml|yml|md|mdx)$' >> tools/relevant_changed_files.txt || true

if [ -s tools/relevant_changed_files.txt ]; then
list_of_files=$(cat tools/relevant_changed_files.txt | tr '\n' ' ')

docker run --rm -v "${PWD}:/src" semgrep/semgrep \
semgrep scan \
--config .semgrep --metrics=off \
--include "*.mdx" --include "*.mdx" \
--force-color \
$list_of_files
else
echo "No relevant files changed."
fi

popd > /dev/null || return
Loading