Skip to content

Commit a897081

Browse files
committed
Merge branch 'main' into add-tests
2 parents 2f5820b + 03133b3 commit a897081

File tree

16 files changed

+531
-153
lines changed

16 files changed

+531
-153
lines changed

.github/workflows/go.yml

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -94,30 +94,31 @@ jobs:
9494
# Write-Host "Attempting to run CLI..."
9595
# .\cli-v2.exe install
9696

97-
release:
98-
needs: [test, ittest]
99-
if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch) && github.event_name == 'push'
100-
runs-on: ubuntu-latest
101-
steps:
102-
- name: Checkout
103-
uses: actions/checkout@v4
104-
with:
105-
fetch-depth: 0
106-
- name: Set up Go
107-
uses: actions/setup-go@v4
108-
- name: "Git Version"
109-
id: generate-version
110-
uses: codacy/[email protected]
111-
- name: "Tag version"
112-
run: |
113-
git tag ${{ steps.generate-version.outputs.version }}
114-
git push --tags "https://codacy:${{ secrets.GITHUB_TOKEN }}@github.com/codacy/codacy-cli-v2"
115-
- name: Run GoReleaser
116-
uses: goreleaser/goreleaser-action@v5
117-
with:
118-
distribution: goreleaser
119-
# 'latest', 'nightly', or a semver
120-
version: "latest"
121-
args: release --clean
122-
env:
123-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
97+
## For now we are not releasing the CLI, as we are making some quicker iterations
98+
# release:
99+
# needs: [test, ittest]
100+
# if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch) && github.event_name == 'push'
101+
# runs-on: ubuntu-latest
102+
# steps:
103+
# - name: Checkout
104+
# uses: actions/checkout@v4
105+
# with:
106+
# fetch-depth: 0
107+
# - name: Set up Go
108+
# uses: actions/setup-go@v4
109+
# - name: "Git Version"
110+
# id: generate-version
111+
# uses: codacy/[email protected]
112+
# - name: "Tag version"
113+
# run: |
114+
# git tag ${{ steps.generate-version.outputs.version }}
115+
# git push --tags "https://codacy:${{ secrets.GITHUB_TOKEN }}@github.com/codacy/codacy-cli-v2"
116+
# - name: Run GoReleaser
117+
# uses: goreleaser/goreleaser-action@v5
118+
# with:
119+
# distribution: goreleaser
120+
# # 'latest', 'nightly', or a semver
121+
# version: "latest"
122+
# args: release --clean
123+
# env:
124+
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@ go.work
2222
go.work.sum
2323

2424
.idea/
25+
.vscode/
2526

26-
cli-v2
27+
cli-v2

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Codacy
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

cmd/analyze.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ var analyzeCmd = &cobra.Command{
205205
}
206206

207207
eslint := config.Config.Tools()["eslint"]
208-
eslintInstallationDirectory := eslint.Info()["installDir"]
208+
eslintInstallationDirectory := eslint.InstallDir
209209
nodeRuntime := config.Config.Runtimes()["node"]
210210
nodeBinary := nodeRuntime.Binaries["node"]
211211

@@ -220,4 +220,4 @@ var analyzeCmd = &cobra.Command{
220220

221221
tools.RunEslint(workDirectory, eslintInstallationDirectory, nodeBinary, args, autoFix, outputFile, outputFormat)
222222
},
223-
}
223+
}

cmd/install.go

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package cmd
22

33
import (
44
cfg "codacy/cli-v2/config"
5-
"fmt"
65
"log"
76

87
"github.com/spf13/cobra"
@@ -33,18 +32,9 @@ func installRuntimes(config *cfg.ConfigType) {
3332
}
3433

3534
func installTools(config *cfg.ConfigType) {
36-
for _, tool := range config.Tools() {
37-
switch tool.Name() {
38-
case "eslint":
39-
// eslint needs node runtime
40-
nodeRuntime := config.Runtimes()["node"]
41-
err := cfg.InstallEslint(nodeRuntime, tool, registry)
42-
if err != nil {
43-
fmt.Println(err.Error())
44-
log.Fatal(err)
45-
}
46-
default:
47-
log.Fatal("Unknown tool:", tool.Name())
48-
}
35+
// Use the new tools-installer instead of manual installation
36+
err := cfg.InstallTools()
37+
if err != nil {
38+
log.Fatal(err)
4939
}
50-
}
40+
}

config-file/configFile.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,22 @@ func parseConfigFile(configContents []byte) error {
3636
return err
3737
}
3838

39+
// Convert the tool strings to ToolConfig objects
40+
toolConfigs := make([]plugins.ToolConfig, 0, len(configFile.TOOLS))
3941
for _, tl := range configFile.TOOLS {
4042
ct, err := parseConfigTool(tl)
4143
if err != nil {
4244
return err
4345
}
44-
config.Config.AddTool(config.NewRuntime(ct.name, ct.version))
46+
toolConfigs = append(toolConfigs, plugins.ToolConfig{
47+
Name: ct.name,
48+
Version: ct.version,
49+
})
50+
}
51+
52+
// Add all tools at once
53+
if err := config.Config.AddTools(toolConfigs); err != nil {
54+
return err
4555
}
4656

4757
return nil

config/config.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type ConfigType struct {
1717
projectConfigFile string
1818

1919
runtimes map[string]*plugins.RuntimeInfo
20-
tools map[string]*Runtime
20+
tools map[string]*plugins.ToolInfo
2121
}
2222

2323
func (c *ConfigType) HomePath() string {
@@ -63,13 +63,23 @@ func (c *ConfigType) AddRuntimes(configs []plugins.RuntimeConfig) error {
6363
return nil
6464
}
6565

66-
// TODO do inheritance with tool
67-
func (c *ConfigType) Tools() map[string]*Runtime {
66+
func (c *ConfigType) Tools() map[string]*plugins.ToolInfo {
6867
return c.tools
6968
}
7069

71-
func (c *ConfigType) AddTool(t *Runtime) {
72-
c.tools[t.Name()] = t
70+
func (c *ConfigType) AddTools(configs []plugins.ToolConfig) error {
71+
// Process the tool configurations using the plugins.ProcessTools function
72+
toolInfoMap, err := plugins.ProcessTools(configs, c.toolsDirectory)
73+
if err != nil {
74+
return err
75+
}
76+
77+
// Store the tool information in the config
78+
for name, info := range toolInfoMap {
79+
c.tools[name] = info
80+
}
81+
82+
return nil
7383
}
7484

7585
func (c *ConfigType) initCodacyDirs() {
@@ -117,7 +127,7 @@ func Init() {
117127
Config.initCodacyDirs()
118128

119129
Config.runtimes = make(map[string]*plugins.RuntimeInfo)
120-
Config.tools = make(map[string]*Runtime)
130+
Config.tools = make(map[string]*plugins.ToolInfo)
121131
}
122132

123133
// Global singleton config-file

config/eslint-utils.go

Lines changed: 0 additions & 50 deletions
This file was deleted.

config/runtime.go

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)