Skip to content

Commit af6c04c

Browse files
Added semgrep (#134)
* Added semgrep * Remove YOLOv7 files * Properly establish YOLOv7 as a submodule * Update version & .gitignore --------- Co-authored-by: HonzaCuhel <[email protected]>
1 parent 50523f2 commit af6c04c

File tree

96 files changed

+92
-109967
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+92
-109967
lines changed

.github/workflows/semgrep.yaml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Semgrep SAST Scan
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
semgrep:
8+
# User definable name of this GitHub Actions job.
9+
name: semgrep/ci
10+
# If you are self-hosting, change the following `runs-on` value:
11+
runs-on: ubuntu-latest
12+
container:
13+
# A Docker image with Semgrep installed. Do not change this.
14+
image: returntocorp/semgrep
15+
# Skip any PR created by dependabot to avoid permission issues:
16+
if: (github.actor != 'dependabot[bot]')
17+
permissions:
18+
# required for all workflows
19+
security-events: write
20+
# only required for workflows in private repositories
21+
actions: read
22+
contents: read
23+
24+
steps:
25+
# Fetch project source with GitHub Actions Checkout.
26+
- name: Checkout repository
27+
uses: actions/checkout@v4
28+
29+
- name: Perform Semgrep Analysis
30+
# @NOTE: This is the actual semgrep command to scan your code.
31+
# Modify the --config option to 'r/all' to scan using all rules,
32+
# or use multiple flags to specify particular rules, such as
33+
# --config r/all --config custom/rules
34+
run: semgrep scan -q --sarif --config auto --config "p/secrets" . > semgrep-results.sarif
35+
36+
- name: Pretty-Print SARIF Output
37+
run: |
38+
jq . semgrep-results.sarif > formatted-semgrep-results.sarif || echo "{}"
39+
echo "Formatted SARIF Output (First 20 lines):"
40+
head -n 20 formatted-semgrep-results.sarif || echo "{}"
41+
42+
- name: Validate JSON Output
43+
run: |
44+
if ! jq empty formatted-semgrep-results.sarif > /dev/null 2>&1; then
45+
echo "⚠️ Semgrep output is not valid JSON. Skipping annotations."
46+
exit 0
47+
fi
48+
49+
- name: Add PR Annotations for Semgrep Findings
50+
run: |
51+
total_issues=$(jq '.runs[0].results | length' formatted-semgrep-results.sarif)
52+
if [[ "$total_issues" -eq 0 ]]; then
53+
echo "✅ No Semgrep issues found!"
54+
exit 0
55+
fi
56+
57+
jq -c '.runs[0].results[]' formatted-semgrep-results.sarif | while IFS= read -r issue; do
58+
file=$(echo "$issue" | jq -r '.locations[0].physicalLocation.artifactLocation.uri')
59+
line=$(echo "$issue" | jq -r '.locations[0].physicalLocation.region.startLine')
60+
message=$(echo "$issue" | jq -r '.message.text')
61+
62+
if [[ -n "$file" && -n "$line" && -n "$message" ]]; then
63+
echo "::error file=$file,line=$line,title=Semgrep Issue::${message}"
64+
fi
65+
done

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
profile_default/
1414
ipython_config.py
1515

16+
tools/.DS_Store
17+
1618
# Remove previous ipynb_checkpoints
1719
# git rm -r .ipynb_checkpoints/
1820

.gitmodules

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
url = https://github.com/meituan/YOLOv6
77
branch = main
88
[submodule "yolov7"]
9-
path = tools/yolov7/yolov7
10-
url = https://github.com/WongKinYiu/yolov7
9+
path = tools/yolov7/yolov7
10+
url = https://github.com/WongKinYiu/yolov7.git
1111
branch = main
1212
[submodule "tools/yolo/ultralytics"]
1313
path = tools/yolo/ultralytics

.semgrepignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tools/yolov7/yolov7

Dockerfile

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
11
FROM python:3.11-bullseye
22

3-
## set working directory
3+
## Set working directory
44
WORKDIR /app
55

6-
## instal
6+
## Install dependencies (including required libraries)
77
RUN apt-get update && apt-get install ffmpeg libsm6 libxext6 build-essential cmake git -y
8+
9+
## Add necessary files and set permissions
810
ADD tools /app/tools
911
ADD pyproject.toml /app
10-
1112
ADD requirements.txt /app
12-
RUN python3 -m pip install -r requirements.txt
13-
RUN python3 -m pip install .
1413

15-
## define image execution
14+
## Create non-root user and set ownership of the working directory
15+
RUN adduser --disabled-password --gecos "" --no-create-home non-root && \
16+
chown -R non-root:non-root /app
17+
18+
## Install Python dependencies
19+
RUN pip install .
20+
21+
## Switch to non-root user
22+
USER non-root
23+
24+
## Set PATH for the installed executable
25+
ENV PATH="/home/non-root/.local/bin:/usr/local/bin:$PATH"
26+
27+
## Define image execution
1628
ENTRYPOINT ["tools"]

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "tools"
3-
version = "0.2.3"
3+
version = "0.2.4"
44
description = "Converter for YOLO models into .ONNX format."
55
readme = "README.md"
66
requires-python = ">=3.8"

tools/utils/version_detection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ def detect_version(path: str, debug: bool = False) -> str:
3636

3737
# Extract the tar file into the extracted_model directory
3838
if platform.system() == "Windows":
39-
subprocess.check_output(f"tar -xf {path} -C extracted_model", shell=True)
39+
subprocess.check_output(["tar", "-xf", path, "-C", "extracted_model"])
4040
else:
41-
subprocess.check_output(f"unzip {path} -d extracted_model", shell=True)
41+
subprocess.check_output(["unzip", path, "-d", "extracted_model"])
4242

4343
folder = [
4444
f for f in listdir("extracted_model") if isdir(join("extracted_model", f))

tools/yolov7/yolov7

Submodule yolov7 added at a207844

0 commit comments

Comments
 (0)