Skip to content

Commit 4e95db3

Browse files
committed
replace semgrep with opengrep
1 parent da0cd76 commit 4e95db3

File tree

33 files changed

+206
-336
lines changed

33 files changed

+206
-336
lines changed

.codacy/codacy.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ tools:
1010
- pmd@6.55.0
1111
- pylint@3.3.9
1212
- revive@1.12.0
13-
- semgrep@1.78.0
13+
- opengrep@1.16.2
1414
- trivy@0.66.0
1515
- dartanalyzer@3.7.2

cmd/analyze.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ var versionedToolNames = map[string]map[int]string{
273273

274274
var simpleToolAliases = map[string]string{
275275
"lizard": "Lizard",
276-
"semgrep": "Semgrep",
276+
"opengrep": "Opengrep",
277277
"pylint": "pylintpython3",
278278
"trivy": "Trivy",
279279
}
@@ -405,9 +405,9 @@ func runToolByName(toolName string, workDirectory string, pathsToCheck []string,
405405
case "dartanalyzer":
406406
binaryPath := tool.Binaries[tool.Runtime]
407407
return tools.RunDartAnalyzer(workDirectory, tool.InstallDir, binaryPath, pathsToCheck, outputFile, outputFormat)
408-
case "semgrep":
408+
case "opengrep":
409409
binaryPath := tool.Binaries[toolName]
410-
return tools.RunSemgrep(workDirectory, binaryPath, pathsToCheck, outputFile, outputFormat)
410+
return tools.RunOpengrep(workDirectory, binaryPath, pathsToCheck, outputFile, outputFormat)
411411
case "lizard":
412412
binaryPath := tool.Binaries[tool.Runtime]
413413
return lizard.RunLizard(workDirectory, binaryPath, pathsToCheck, outputFile, outputFormat)

cmd/analyze_integration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func TestToolConfigFileNameMapCompleteness(t *testing.T) {
114114
"pmd": constants.PMDConfigFileName,
115115
"pylint": constants.PylintConfigFileName,
116116
"dartanalyzer": constants.DartAnalyzerConfigFileName,
117-
"semgrep": constants.SemgrepConfigFileName,
117+
"opengrep": constants.OpengrepConfigFileName,
118118
"revive": constants.ReviveConfigFileName,
119119
"lizard": constants.LizardConfigFileName,
120120
}

cmd/analyze_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ func TestToolConfigFileNameMap(t *testing.T) {
449449
"pmd": constants.PMDConfigFileName,
450450
"pylint": constants.PylintConfigFileName,
451451
"dartanalyzer": constants.DartAnalyzerConfigFileName,
452-
"semgrep": constants.SemgrepConfigFileName,
452+
"opengrep": constants.OpengrepConfigFileName,
453453
"revive": constants.ReviveConfigFileName,
454454
"lizard": constants.LizardConfigFileName,
455455
}

cmd/configsetup/tool_creators.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var toolConfigRegistry = map[string]ToolConfigCreator{
2424
domain.PMD7: &pmd7ConfigCreator{},
2525
domain.PyLint: &pylintConfigCreator{},
2626
domain.DartAnalyzer: &dartAnalyzerConfigCreator{},
27-
domain.Semgrep: &semgrepConfigCreator{},
27+
domain.Opengrep: &opengrepConfigCreator{},
2828
domain.Lizard: &lizardConfigCreator{},
2929
domain.Revive: &reviveConfigCreator{},
3030
}
@@ -121,23 +121,23 @@ func (d *dartAnalyzerConfigCreator) GetConfigFileName() string {
121121
}
122122
func (d *dartAnalyzerConfigCreator) GetToolName() string { return "Dart Analyzer" }
123123

124-
// semgrepConfigCreator implements ToolConfigCreator for Semgrep
125-
type semgrepConfigCreator struct{}
124+
// opengrepConfigCreator implements ToolConfigCreator for Opengrep
125+
type opengrepConfigCreator struct{}
126126

127-
func (s *semgrepConfigCreator) CreateConfig(toolsConfigDir string, patterns []domain.PatternConfiguration) error {
128-
configData, err := tools.GetSemgrepConfig(patterns)
127+
func (s *opengrepConfigCreator) CreateConfig(toolsConfigDir string, patterns []domain.PatternConfiguration) error {
128+
configData, err := tools.GetOpengrepConfig(patterns)
129129
if err != nil {
130-
return fmt.Errorf("failed to create Semgrep config: %v", err)
130+
return fmt.Errorf("failed to create Opengrep config: %v", err)
131131
}
132-
err = writeConfigFile(filepath.Join(toolsConfigDir, constants.SemgrepConfigFileName), configData)
132+
err = writeConfigFile(filepath.Join(toolsConfigDir, constants.OpengrepConfigFileName), configData)
133133
if err == nil {
134-
fmt.Println("Semgrep configuration created based on Codacy settings")
134+
fmt.Println("Opengrep configuration created based on Codacy settings")
135135
}
136136
return err
137137
}
138138

139-
func (s *semgrepConfigCreator) GetConfigFileName() string { return constants.SemgrepConfigFileName }
140-
func (s *semgrepConfigCreator) GetToolName() string { return "Semgrep" }
139+
func (s *opengrepConfigCreator) GetConfigFileName() string { return constants.OpengrepConfigFileName }
140+
func (s *opengrepConfigCreator) GetToolName() string { return "Opengrep" }
141141

142142
// lizardConfigCreator implements ToolConfigCreator for Lizard
143143
type lizardConfigCreator struct{}

cmd/init_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestConfigFileTemplate(t *testing.T) {
2525
"node@22.2.0",
2626
"python@3.11.11",
2727
"eslint@8.57.0",
28-
"trivy@0.66.0",
28+
"trivy@0.69.3",
2929
"pylint@3.3.6",
3030
"pmd@7.11.0",
3131
},

cmd/upload.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ var sarifShortNameMap = map[string]string{
5555
"Trivy": "trivy",
5656
"Pylint": "pylintpython3",
5757
"dartanalyzer": "dartanalyzer",
58-
"Semgrep": "semgrep",
58+
"Opengrep": "opengrep",
5959
"Lizard": "lizard",
6060
"revive": "revive",
6161
}

config/tools-installer.go

Lines changed: 73 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"codacy/cli-v2/utils"
88
"codacy/cli-v2/utils/logger"
99
"fmt"
10+
"io"
1011
"log"
1112
"os"
1213
"os/exec"
@@ -297,29 +298,43 @@ func installDownloadBasedTool(toolInfo *plugins.ToolInfo) error {
297298
return fmt.Errorf("failed to create installation directory: %w", err)
298299
}
299300

300-
// Extract based on file extension
301-
logger.Debug("Extracting tool", logrus.Fields{
302-
"tool": toolInfo.Name,
303-
"version": toolInfo.Version,
304-
"fileName": fileName,
305-
"extractDirectory": toolInfo.InstallDir,
306-
})
301+
isArchive := strings.HasSuffix(fileName, ".zip") || strings.HasSuffix(fileName, ".tar.gz") || strings.HasSuffix(fileName, ".tgz")
307302

308-
if strings.HasSuffix(fileName, ".zip") {
309-
err = utils.ExtractZip(file.Name(), toolInfo.InstallDir)
310-
} else {
311-
err = utils.ExtractTarGz(file, toolInfo.InstallDir)
312-
}
303+
if isArchive {
304+
// Extract based on file extension
305+
logger.Debug("Extracting tool", logrus.Fields{
306+
"tool": toolInfo.Name,
307+
"version": toolInfo.Version,
308+
"fileName": fileName,
309+
"extractDirectory": toolInfo.InstallDir,
310+
})
313311

314-
if err != nil {
315-
return fmt.Errorf("failed to extract tool: %w", err)
316-
}
312+
if strings.HasSuffix(fileName, ".zip") {
313+
err = utils.ExtractZip(file.Name(), toolInfo.InstallDir)
314+
} else {
315+
err = utils.ExtractTarGz(file, toolInfo.InstallDir)
316+
}
317+
318+
if err != nil {
319+
return fmt.Errorf("failed to extract tool: %w", err)
320+
}
317321

318-
// Make sure all binaries are executable
319-
for _, binaryPath := range toolInfo.Binaries {
320-
err = os.Chmod(filepath.Join(toolInfo.InstallDir, filepath.Base(binaryPath)), constants.DefaultDirPerms)
321-
if err != nil && !os.IsNotExist(err) {
322-
return fmt.Errorf("failed to make binary executable: %w", err)
322+
// Make sure all binaries are executable
323+
for _, binaryPath := range toolInfo.Binaries {
324+
err = os.Chmod(filepath.Join(toolInfo.InstallDir, filepath.Base(binaryPath)), constants.DefaultDirPerms)
325+
if err != nil && !os.IsNotExist(err) {
326+
return fmt.Errorf("failed to make binary executable: %w", err)
327+
}
328+
}
329+
} else {
330+
// Bare binary — copy directly to the binary destination path
331+
logger.Debug("Installing bare binary", logrus.Fields{
332+
"tool": toolInfo.Name,
333+
"version": toolInfo.Version,
334+
"downloadPath": downloadPath,
335+
})
336+
if err = installBareBinary(downloadPath, toolInfo); err != nil {
337+
return fmt.Errorf("failed to install binary: %w", err)
323338
}
324339
}
325340

@@ -330,6 +345,44 @@ func installDownloadBasedTool(toolInfo *plugins.ToolInfo) error {
330345
return nil
331346
}
332347

348+
// installBareBinary copies a downloaded bare binary to its destination path and makes it executable.
349+
func installBareBinary(downloadPath string, toolInfo *plugins.ToolInfo) error {
350+
var destPath string
351+
for _, p := range toolInfo.Binaries {
352+
destPath = p
353+
break
354+
}
355+
if destPath == "" {
356+
return fmt.Errorf("no binary destination defined for tool %s", toolInfo.Name)
357+
}
358+
359+
if err := os.MkdirAll(filepath.Dir(destPath), constants.DefaultDirPerms); err != nil {
360+
return fmt.Errorf("failed to create binary directory: %w", err)
361+
}
362+
363+
src, err := os.Open(downloadPath)
364+
if err != nil {
365+
return fmt.Errorf("failed to open downloaded binary: %w", err)
366+
}
367+
defer src.Close()
368+
369+
dst, err := os.Create(destPath)
370+
if err != nil {
371+
return fmt.Errorf("failed to create binary file: %w", err)
372+
}
373+
defer dst.Close()
374+
375+
if _, err = io.Copy(dst, src); err != nil {
376+
return fmt.Errorf("failed to copy binary: %w", err)
377+
}
378+
379+
if err = os.Chmod(destPath, constants.DefaultDirPerms); err != nil {
380+
return fmt.Errorf("failed to make binary executable: %w", err)
381+
}
382+
383+
return nil
384+
}
385+
333386
func installPythonTool(name string, toolInfo *plugins.ToolInfo) error {
334387
logger.Debug("Starting Python tool installation", logrus.Fields{
335388
"tool": toolInfo.Name,

constants/tool_configs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const (
1212
PMDConfigFileName = "ruleset.xml"
1313
PylintConfigFileName = "pylint.rc"
1414
DartAnalyzerConfigFileName = "analysis_options.yaml"
15-
SemgrepConfigFileName = "semgrep.yaml"
15+
OpengrepConfigFileName = "semgrep.yaml"
1616
ReviveConfigFileName = "revive.toml"
1717
LizardConfigFileName = "lizard.yaml"
1818
)
@@ -24,7 +24,7 @@ var ToolConfigFileNames = map[string]string{
2424
"pmd": PMDConfigFileName,
2525
"pylint": PylintConfigFileName,
2626
"dartanalyzer": DartAnalyzerConfigFileName,
27-
"semgrep": SemgrepConfigFileName,
27+
"opengrep": OpengrepConfigFileName,
2828
"revive": ReviveConfigFileName,
2929
"lizard": LizardConfigFileName,
3030
}

domain/tool.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const (
2828
PMD7 string = "ed7e8287-707d-485a-a0cb-e211004432c2"
2929
PyLint string = "31677b6d-4ae0-4f56-8041-606a8d7a8e61"
3030
DartAnalyzer string = "d203d615-6cf1-41f9-be5f-e2f660f7850f"
31-
Semgrep string = "6792c561-236d-41b7-ba5e-9d6bee0d548b"
31+
Opengrep string = "6792c561-236d-41b7-ba5e-9d6bee0d548b"
3232
Lizard string = "76348462-84b3-409a-90d3-955e90abfb87"
3333
Revive string = "bd81d1f4-1406-402d-9181-1274ee09f1aa"
3434
)
@@ -48,6 +48,6 @@ var SupportedToolsMetadata = map[string]ToolInfo{
4848
Trivy: {Name: "trivy", Priority: 0},
4949
DartAnalyzer: {Name: "dartanalyzer", Priority: 0},
5050
Lizard: {Name: "lizard", Priority: 0},
51-
Semgrep: {Name: "semgrep", Priority: 0},
51+
Opengrep: {Name: "opengrep", Priority: 0},
5252
Revive: {Name: "revive", Priority: 0},
5353
}

0 commit comments

Comments
 (0)