feature: Automatic Tool and Runtime Installation During Analysis - PLUTO-1422#145
feature: Automatic Tool and Runtime Installation During Analysis - PLUTO-1422#145franciscoovazevedo merged 10 commits intomainfrom
Conversation
Coverage summary from CodacySee diff coverage on Codacy
Coverage variation details
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: Diff coverage details
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: See your quality gate settings Change summary preferences |
403f8d0 to
6d168ad
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR enhances the CLI to automatically install missing tools and runtimes during analysis, removing pre-install steps and updating codacy.yaml dynamically.
- Automatic detection and addition of missing tools to configuration with default versions
- Runtime checks and on-the-fly installation before tool installation
- Updates to config management to write new tools into
codacy.yaml
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| config/tools-installer.go | Auto-add missing tools and ensure their runtimes are installed |
| config/runtimes-installer.go | Log runtime checks and correct permission setting for binaries |
| config/config.go | Add helpers to update codacy.yaml with new tools and versions |
| config-file/configFile.go | Introduce YAML tags for TOOLS and RUNTIMES struct fields |
| cmd/analyze_test.go | New unit tests covering ESLint installation validation logic |
| cmd/analyze.go | Wrap all analysis commands with tool/runtime auto-install flows |
Comments suppressed due to low confidence (5)
cmd/analyze.go:319
- [nitpick] There's almost identical setup and install logic across all
run*Analysisfunctions. Extract a shared helper to reduce duplication and simplify future changes.
func runEslintAnalysis(workDirectory string, pathsToCheck []string, autoFix bool, outputFile string, outputFormat string) error {
cmd/analyze.go:333
- [nitpick] User-facing messages should consistently use the official tool name casing ("ESLint" rather than "Eslint").
fmt.Println("Eslint tool configuration not found, adding and installing...")
cmd/analyze_test.go:137
- [nitpick] Tests cover only the ESLint installation trigger logic; consider adding similar validation tests or mocks for other tools to ensure consistent behavior across all
run*Analysisfunctions.
func TestEslintInstallationValidationLogic(t *testing.T) {
cmd/analyze.go:520
- After invoking
InstallTool, refreshdartanalyzerfromconfig.Config.Tools()before checking for nil, otherwise this check always sees the old nil value.
if dartanalyzer == nil {
cmd/analyze.go:619
- Refresh
lizardToolfromconfig.Config.Tools()after installing it so that this nil check reflects the updated configuration.
if lizardTool == nil {
bb92304 to
97d5dc2
Compare
e8c649a to
6e31cf5
Compare
| patterns, err = lizard.ReadConfig(configFile) | ||
| var runtime *plugins.RuntimeInfo | ||
| if tool == nil || !isToolInstalled { | ||
| fmt.Println("Tool configuration not found, adding and installing...") |
There was a problem hiding this comment.
[blocker]
Tool configuration not found -> I see this in case when I have config but I am missing installed tool
There was a problem hiding this comment.
Shouldn't this be:
Tool not installed, installing now...
| } | ||
|
|
||
| // updateToolsList updates the tools list in the configuration, avoiding duplicates | ||
| func updateToolsList(tools []interface{}, name, version string) []interface{} { |
There was a problem hiding this comment.
[question]
Wait, is this PR also include updating tools in codacy yaml ? 🤔
I do not undestand why it's adding tools ?
There was a problem hiding this comment.
why should we only install if the tool is in codacy.yaml?
my interpretation was, if a user tries to run a tool that is not installed it should not fail. a tool that is not configured, is not installed, therefore we add it and install it.
There was a problem hiding this comment.
Sorry, jsut thinking more about this scenario.
Let's assume:
- You are in remote mode
- You do not have lizard condf file nor lizard in codacy yaml
- You "force" run lizard
go run cli-v2.go analyze --tool lizard - Lizard is added to codacy yaml
- Lizard config file is missing
There was a problem hiding this comment.
https://codacy.atlassian.net/jira/software/c/projects/PLUTO/boards/226?selectedIssue=PLUTO-1423
that will be tackled in the next task.
…e not trying to install typo tool
2c75a9d to
bdb7819
Compare
a240171 to
40d0afa
Compare
40d0afa to
c80dceb
Compare
…duce code duplication. Updated runtime and tool handling functions to use a unified entry list update method. Improved addToCodacyYaml function for better maintainability. (#149)
Automatic Tool and Runtime Installation During Analysis
Summary
This PR implements automatic installation of missing tools and runtimes during analysis, eliminating the need for explicit
installcommands before running analysis. When analyzing code, if a required tool or runtime is missing, the CLI will now automatically install them and continue with the analysis seamlessly.Changes Made
🔧 Enhanced Tool Analysis Functions (
cmd/analyze.go)codacy.yamlwith their default versions⚙️ Enhanced Tool Installation (
config/tools-installer.go)InstallTool()now acceptsniltoolInfo and automatically adds missing tools to configuration🔧 Enhanced Runtime Installation (
config/runtimes-installer.go)📝 Configuration Management (
config/config.go)AddToolWithDefaultVersion()function for adding missing toolscodacy.yamlwhen missingUser Experience Improvements
Before ❌
$ codacy-cli analyze file.js 2025/01/05 11:51:31 Running eslint... Eslint tool configuration not found # Fatal error - analysis stopsAfter ✅
Technical Details
Automatic Installation Flow
codacy.yamlwith default versionsSupported Installation Types
Error Handling
log.Fatal()with proper error returnsAcceptance Criteria ✅
✅ Trying to run tools that are not installed, should install them
✅ Make sure explicit logs are shared about it
✅ Make sure the STDOUT and output of analysis is not compromised
✅ Analyze should work as normal
✅ Don't show any extra logs like 'tool is already installed'
Testing
The implementation has been tested with various scenarios:
Related
🎫 Jira Ticket: PLUTO-1422
This change significantly improves the developer experience by removing the friction of manual tool installation while maintaining all existing functionality and output formats.