Skip to content

Commit 796ade5

Browse files
authored
[PLUTO-1412] Test init (#113)
1 parent 068ea50 commit 796ade5

30 files changed

+698
-490
lines changed

.github/workflows/it-test.yml

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,32 @@ on:
77
push:
88

99
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0 # Needed for git history
17+
- name: Set up Go
18+
uses: actions/setup-go@v4
19+
- name: Build CLI for all platforms
20+
run: make build-all
21+
- name: Upload CLI binaries
22+
uses: actions/upload-artifact@v4
23+
with:
24+
name: cli-binaries
25+
path: |
26+
cli-v2-linux
27+
cli-v2.exe
28+
cli-v2-macos
29+
1030
test:
31+
needs: build
1132
runs-on: ${{ matrix.os }}
1233
strategy:
1334
matrix:
14-
os: [ubuntu-latest, macos-latest] # [windows-latest] removed for now
35+
os: [ubuntu-latest, macos-latest, windows-latest]
1536
fail-fast: false
1637
steps:
1738
- name: Checkout code
@@ -25,10 +46,9 @@ jobs:
2546
go-version: '1.21'
2647
cache: true
2748

28-
- name: Download CLI binaries from go workflow
29-
uses: dawidd6/action-download-artifact@v2
49+
- name: Download CLI binaries
50+
uses: actions/download-artifact@v4
3051
with:
31-
workflow: go.yml
3252
name: cli-binaries
3353
path: .
3454

@@ -48,6 +68,38 @@ jobs:
4868
if: matrix.os != 'windows-latest'
4969
run: chmod +x cli-v2
5070

71+
- name: Install yq on Windows
72+
if: matrix.os == 'windows-latest'
73+
shell: pwsh
74+
run: |
75+
choco install yq -y
76+
Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1
77+
refreshenv
78+
79+
- name: Run init tests on Windows
80+
if: matrix.os == 'windows-latest'
81+
shell: pwsh
82+
run: |
83+
$ErrorActionPreference = "Stop"
84+
& ./integration-tests/run.ps1
85+
if ($LASTEXITCODE -ne 0) {
86+
Write-Error "Integration tests failed with exit code $LASTEXITCODE"
87+
exit $LASTEXITCODE
88+
}
89+
env:
90+
CODACY_API_TOKEN: ${{ secrets.CODACY_API_TOKEN }}
91+
92+
- name: Run init tests on Unix
93+
if: matrix.os != 'windows-latest'
94+
id: run_init_tests_unix
95+
continue-on-error: true
96+
shell: bash
97+
env:
98+
CODACY_API_TOKEN: ${{ secrets.CODACY_API_TOKEN }}
99+
run: |
100+
chmod +x integration-tests/run.sh
101+
./integration-tests/run.sh
102+
51103
- name: Run tool tests
52104
if: matrix.os != 'windows-latest'
53105
id: run_tests
@@ -84,7 +136,7 @@ jobs:
84136
fi
85137
86138
- name: Check test results
87-
if: steps.run_tests.outcome == 'failure'
139+
if: failure()
88140
run: |
89-
echo "Job failed because some tool tests failed. Please check the logs above for details."
141+
echo "Job failed because some tests failed. Please check the logs above for details."
90142
exit 1

cmd/init.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ var initCmd = &cobra.Command{
7575
if err != nil {
7676
log.Fatal(err)
7777
}
78-
createGitIgnoreFile()
7978
}
79+
createGitIgnoreFile()
8080
fmt.Println()
8181
fmt.Println("✅ Successfully initialized Codacy configuration!")
8282
fmt.Println()
@@ -95,12 +95,7 @@ func createGitIgnoreFile() error {
9595
}
9696
defer gitIgnoreFile.Close()
9797

98-
content := `# Codacy CLI
99-
tools-configs/
100-
.gitignore
101-
cli-config.yaml
102-
logs/
103-
`
98+
content := "# Codacy CLI\ntools-configs/\n.gitignore\ncli-config.yaml\nlogs/\n"
10499
if _, err := gitIgnoreFile.WriteString(content); err != nil {
105100
return fmt.Errorf("failed to write to .gitignore file: %w", err)
106101
}
@@ -275,6 +270,8 @@ func buildRepositoryConfigurationFiles(token string) error {
275270
PyLint: "pylint",
276271
PMD: "pmd",
277272
DartAnalyzer: "dartanalyzer",
273+
Lizard: "lizard",
274+
Semgrep: "semgrep",
278275
}
279276

280277
// Generate languages configuration based on API tools response
@@ -384,52 +381,56 @@ func createToolFileConfigurations(tool tools.Tool, patternConfiguration []domain
384381
if err != nil {
385382
return fmt.Errorf("failed to create Trivy config: %v", err)
386383
}
384+
fmt.Println("Trivy configuration created based on Codacy settings")
387385
} else {
388386
err := createDefaultTrivyConfigFile(toolsConfigDir)
389387
if err != nil {
390388
return fmt.Errorf("failed to create default Trivy config: %v", err)
391389
}
392390
}
393-
fmt.Println("Trivy configuration created based on Codacy settings")
394391
case PMD:
395392
if len(patternConfiguration) > 0 {
396393
err := createPMDConfigFile(patternConfiguration, toolsConfigDir)
397394
if err != nil {
398395
return fmt.Errorf("failed to create PMD config: %v", err)
399396
}
397+
398+
fmt.Println("PMD configuration created based on Codacy settings")
400399
} else {
401400
err := createDefaultPMDConfigFile(toolsConfigDir)
402401
if err != nil {
403402
return fmt.Errorf("failed to create default PMD config: %v", err)
404403
}
405404
}
406-
fmt.Println("PMD configuration created based on Codacy settings")
405+
407406
case PyLint:
408407
if len(patternConfiguration) > 0 {
409408
err := createPylintConfigFile(patternConfiguration, toolsConfigDir)
410409
if err != nil {
411410
return fmt.Errorf("failed to create Pylint config: %v", err)
412411
}
412+
fmt.Println("Pylint configuration created based on Codacy settings")
413413
} else {
414414
err := createDefaultPylintConfigFile(toolsConfigDir)
415415
if err != nil {
416416
return fmt.Errorf("failed to create default Pylint config: %v", err)
417417
}
418418
}
419-
fmt.Println("Pylint configuration created based on Codacy settings")
420419
case DartAnalyzer:
421420
if len(patternConfiguration) > 0 {
422421
err := createDartAnalyzerConfigFile(patternConfiguration, toolsConfigDir)
423422
if err != nil {
424423
return fmt.Errorf("failed to create Dart Analyzer config: %v", err)
425424
}
425+
fmt.Println("Dart configuration created based on Codacy settings")
426426
}
427427
case Semgrep:
428428
if len(patternConfiguration) > 0 {
429429
err := createSemgrepConfigFile(patternConfiguration, toolsConfigDir)
430430
if err != nil {
431431
return fmt.Errorf("failed to create Semgrep config: %v", err)
432432
}
433+
fmt.Println("Semgrep configuration created based on Codacy settings")
433434
}
434435
case Lizard:
435436
createLizardConfigFile(toolsConfigDir, patternConfiguration)
@@ -541,7 +542,6 @@ func createLizardConfigFile(toolsConfigDir string, patternConfiguration []domain
541542
var patterns []domain.PatternDefinition
542543

543544
if len(patternConfiguration) == 0 {
544-
fmt.Println("Using default Lizard configuration")
545545
var err error
546546
patterns, err = tools.FetchDefaultEnabledPatterns(Lizard)
547547
if err != nil {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
runtimes:
2+
3+
4+
tools:
5+
6+
7+
8+
9+
10+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Codacy CLI
2+
tools-configs/
3+
.gitignore
4+
cli-config.yaml
5+
logs/
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mode: remote
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
runtimes:
2+
3+
4+
tools:
5+
6+
7+
8+
9+
10+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default [
2+
{
3+
rules: {
4+
}
5+
}
6+
];
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
tools:
2+
- name: pylint
3+
languages: [Python]
4+
extensions: [.py]
5+
- name: lizard
6+
languages: [Java, JavaScript, Python]
7+
extensions: [.java, .js, .jsm, .jsx, .mjs, .py, .vue]
8+
- name: pmd
9+
languages: [Java, JavaScript]
10+
extensions: [.java, .js, .jsm, .jsx, .mjs, .vue]
11+
- name: eslint
12+
languages: [JavaScript]
13+
extensions: [.js, .jsm, .jsx, .mjs, .vue]
14+
- name: trivy
15+
languages: [Multiple]
16+
extensions: []
17+
- name: semgrep
18+
languages: [Java, JavaScript, JSON, Python]
19+
extensions: [.java, .js, .jsm, .json, .jsx, .mjs, .py, .vue]
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
patterns:
2+
Lizard_ccn-minor:
3+
category: Complexity
4+
description: Check the Cyclomatic Complexity value of a function or logic block. If the threshold is not met, raise a Minor issue. The default threshold is 5.
5+
explanation: |-
6+
# Minor Cyclomatic Complexity control
7+
8+
Check the Cyclomatic Complexity value of a function or logic block. If the threshold is not met, raise a Minor issue. The default threshold is 4.
9+
id: Lizard_ccn-minor
10+
level: Info
11+
severityLevel: Info
12+
threshold: 5
13+
timeToFix: 5
14+
title: Minor Cyclomatic Complexity control
15+
Lizard_nloc-critical:
16+
category: Complexity
17+
description: Check the number of lines of code (without comments) in a function or logic block. If the threshold is not met, raise a Critical issue. The default threshold is 100.
18+
explanation: |-
19+
# Critical NLOC control - Number of Lines of Code (without comments)
20+
21+
Check the number of lines of code (without comments) in a function or logic block. If the threshold is not met, raise a Critical issue. The default threshold is 100.
22+
id: Lizard_nloc-critical
23+
level: Error
24+
severityLevel: Error
25+
threshold: 100
26+
timeToFix: 5
27+
title: Critical NLOC control - Number of Lines of Code (without comments)
28+
Lizard_nloc-medium:
29+
category: Complexity
30+
description: Check the number of lines of code (without comments) in a function. If the threshold is not met, raise a Medium issue. The default threshold is 50.
31+
explanation: |-
32+
# Medium NLOC control - Number of Lines of Code (without comments)
33+
34+
Check the number of lines of code (without comments) in a function. If the threshold is not met, raise a Medium issue. The default threshold is 50.
35+
id: Lizard_nloc-medium
36+
level: Warning
37+
severityLevel: Warning
38+
threshold: 50
39+
timeToFix: 5
40+
title: Medium NLOC control - Number of Lines of Code (without comments)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[MASTER]
2+
ignore=CVS
3+
persistent=yes
4+
load-plugins=
5+
6+
[MESSAGES CONTROL]
7+
disable=all
8+
enable=E1124,E1130,E1133
9+

0 commit comments

Comments
 (0)