Skip to content

Commit f0b8976

Browse files
committed
[PLUTO-1431] Revive/go installation/running
1 parent 63a2be3 commit f0b8976

File tree

7 files changed

+119
-0
lines changed

7 files changed

+119
-0
lines changed

.codacy/codacy.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ runtimes:
33
44
55
6+
67
tools:
78
89
@@ -12,3 +13,4 @@ tools:
1213
1314
1415
16+

cmd/analyze.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"codacy/cli-v2/plugins"
77
"codacy/cli-v2/tools"
88
"codacy/cli-v2/tools/lizard"
9+
reviveTool "codacy/cli-v2/tools/revive"
910
"encoding/json"
1011
"fmt"
1112
"io"
@@ -412,6 +413,16 @@ func runEnigmaAnalysis(workDirectory string, pathsToCheck []string, outputFile s
412413
return tools.RunEnigma(workDirectory, enigma.InstallDir, enigma.Binaries["codacy-enigma-cli"], pathsToCheck, outputFile, outputFormat)
413414
}
414415

416+
func runReviveAnalysis(workDirectory string, pathsToCheck []string, outputFile string, outputFormat string) error {
417+
revive := config.Config.Tools()["revive"]
418+
if revive == nil {
419+
log.Fatal("Revive tool configuration not found")
420+
}
421+
reviveBinary := revive.Binaries["revive"]
422+
423+
return reviveTool.RunRevive(workDirectory, reviveBinary, pathsToCheck, outputFile, outputFormat)
424+
}
425+
415426
var analyzeCmd = &cobra.Command{
416427
Use: "analyze",
417428
Short: "Runs all configured linters.",
@@ -522,6 +533,8 @@ func runTool(workDirectory string, toolName string, args []string, outputFile st
522533
return runLizardAnalysis(workDirectory, args, outputFile, outputFormat)
523534
case "codacy-enigma-cli":
524535
return runEnigmaAnalysis(workDirectory, args, outputFile, outputFormat)
536+
case "revive":
537+
return runReviveAnalysis(workDirectory, args, outputFile, outputFormat)
525538
default:
526539
return fmt.Errorf("unsupported tool: %s", toolName)
527540
}

config/tools-installer.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,13 @@ func installRuntimeTool(name string, toolInfo *plugins.ToolInfo, registry string
167167
// Execute the installation command using the package manager
168168
cmd := exec.Command(packageManagerBinary, strings.Split(installCmd, " ")...)
169169

170+
// Special handling for Go tools: set GOBIN so the binary is installed in the tool's install directory
171+
if toolInfo.Runtime == "go" {
172+
env := os.Environ()
173+
env = append(env, "GOBIN="+toolInfo.InstallDir)
174+
cmd.Env = env
175+
}
176+
170177
// Special handling for ESLint installation in Linux (WSL) environment
171178
if toolInfo.Name == "eslint" && runtime.GOOS == "linux" {
172179
// Get node binary directory to add to PATH

plugins/runtime-utils.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ func processRuntime(config RuntimeConfig, runtimesDir string) (*RuntimeInfo, err
5353
var installDir string
5454
if config.Name == "python" {
5555
installDir = path.Join(runtimesDir, "python")
56+
} else if config.Name == "go" {
57+
installDir = path.Join(runtimesDir, "go")
5658
} else {
5759
installDir = path.Join(runtimesDir, fileName)
5860
}

plugins/runtimes/go/plugin.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: go
2+
# Go Programming Language Runtime
3+
# Provides the Go compiler and tools for building and running Go programs.
4+
description: Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.
5+
default_version: 1.22.3
6+
download:
7+
url_template: "https://go.dev/dl/go{{.Version}}.{{.OS}}-{{.Arch}}.tar.gz"
8+
file_name_template: "go{{.Version}}.{{.OS}}-{{.Arch}}.tar.gz"
9+
extension:
10+
default: tar.gz
11+
windows: zip
12+
arch_mapping:
13+
amd64: amd64
14+
arm64: arm64
15+
386: 386
16+
arm: armv6l
17+
os_mapping:
18+
linux: linux
19+
darwin: darwin
20+
windows: windows
21+
binaries:
22+
- name: go
23+
path: bin/go
24+
- name: gofmt
25+
path: bin/gofmt

plugins/tools/revive/plugin.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: revive
2+
version: 1.7.0
3+
description: Revive is a fast, configurable, extensible, flexible, and beautiful linter for Go.
4+
default_version: 1.7.0
5+
runtime: go
6+
runtime_binaries:
7+
package_manager: go
8+
execution: revive
9+
installation:
10+
command: "install github.com/mgechev/revive@v{{.Version}}"
11+
binaries:
12+
- name: revive
13+
path: revive
14+
formatters:
15+
- name: stylish
16+
flag: "-formatter stylish"
17+
- name: json
18+
flag: "-formatter json"
19+
output_options:
20+
file_flag: "-o"
21+
analysis_options:
22+
autofix_flag: ""
23+
default_path: "."

tools/revive/reviveRunner.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package tools
2+
3+
import (
4+
"fmt"
5+
"log"
6+
"os"
7+
"os/exec"
8+
)
9+
10+
// RunRevive executes revive analysis on the specified files or directory
11+
func RunRevive(workDirectory string, binary string, files []string, outputFile string, outputFormat string) error {
12+
cmdArgs := []string{}
13+
14+
// Add output format if specified
15+
if outputFormat != "" {
16+
cmdArgs = append(cmdArgs, "-formatter", outputFormat)
17+
}
18+
19+
// Add output file if specified
20+
if outputFile != "" {
21+
cmdArgs = append(cmdArgs, "-o", outputFile)
22+
}
23+
24+
// Add files to analyze - if no files specified, analyze current directory
25+
if len(files) > 0 {
26+
cmdArgs = append(cmdArgs, files...)
27+
} else {
28+
cmdArgs = append(cmdArgs, ".")
29+
}
30+
31+
cmd := exec.Command(binary, cmdArgs...)
32+
cmd.Dir = workDirectory
33+
cmd.Stdout = os.Stdout
34+
cmd.Stderr = os.Stderr
35+
36+
if err := cmd.Run(); err != nil {
37+
if _, ok := err.(*exec.ExitError); !ok {
38+
log.Printf("[REVIVE] Error running revive: %v", err)
39+
return fmt.Errorf("failed to run revive: %w", err)
40+
}
41+
log.Printf("[REVIVE] revive exited with non-zero status (findings may be present)")
42+
} else {
43+
log.Printf("[REVIVE] revive completed successfully")
44+
}
45+
46+
return nil
47+
}

0 commit comments

Comments
 (0)