Skip to content

Commit 8d267ba

Browse files
alerizzoCopilot
andauthored
clean: updated README (#130)
* clean: updated README * add codacy badges * Update README.md Co-authored-by: Copilot <[email protected]> * PR review comments --------- Co-authored-by: Copilot <[email protected]>
1 parent e0c3429 commit 8d267ba

File tree

1 file changed

+158
-54
lines changed

1 file changed

+158
-54
lines changed

README.md

Lines changed: 158 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,221 @@
1-
# codacy-cli-v2
1+
# Codacy CLI v2
22

3-
The Codacy CLI (version 2) is a command-line tool that supports analyzing code using tools like ESLint and uploading the results in SARIF format to Codacy.
4-
The tool is invoked using the `codacy-cli` command, and provides two main commands: analyze and upload.
3+
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/8cae070168cf488db82478ba6505a005)](https://app.codacy.com/gh/codacy/codacy-cli-v2/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade) [![Codacy Badge](https://app.codacy.com/project/badge/Coverage/8cae070168cf488db82478ba6505a005)](https://app.codacy.com/gh/codacy/codacy-cli-v2/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage)
54

6-
### Commands
75

8-
- **`analyze` Command**: Runs ESLint analysis on the codebase.
9-
- `--output, -o`: Output file for the results.
10-
- `--tool, -t`: Specifies the tool to run analysis with (e.g., ESLint).
11-
- `--format`: Output format (use 'sarif' for SARIF format to terminal).
12-
- `--fix`: Automatically fixes issues when possible.
6+
Codacy CLI (version 2) is a command-line tool for running code analysis and integrating with Codacy. If your repository exists in Codacy, you can sync your configuration to ensure consistency with your organization's standards.
137

14-
- **`upload` Command With Project Token**: Uploads a SARIF file containing analysis results to Codacy.
15-
- `--sarif-path, -s`: Path to the SARIF report.
16-
- `--commit-uuid, -c`: Commit UUID.
17-
- `--project-token, -t`: Project token for Codacy API.
8+
You can also use Codacy CLI for local code analysis without a Codacy account, leveraging the linter configuration files found in your project's root or Codacy's suggested defaults.
189

19-
- **`upload` Command With API Token**: Uploads a SARIF file containing analysis results to Codacy.
20-
- `--sarif-path, -s`: Path to the SARIF report.
21-
- `--commit-uuid, -c`: Commit UUID.
22-
- `--api-token, -a`: User level token for Codacy API.
23-
- `--provider, -p`: Provider name (e.g., gh, gl, bb).
24-
- `--owner, -o`: Repository owner.
25-
- `--repository, -r`: Repository name.
10+
The CLI supports uploading analysis results (in [SARIF](https://docs.oasis-open.org/sarif/sarif/v2.1.0/sarif-v2.1.0.html) format) to Codacy as well.
2611

27-
### Important Concepts
12+
It is invoked using the `codacy-cli` command and provides several commands for project setup, analysis, and integration.
2813

29-
- **`.codacy/codacy.yaml`**: Configuration file to specify runtimes and tools versions for the CLI.
30-
```yaml
31-
runtimes:
32-
33-
tools:
34-
35-
36-
- **`codacy-cli install`**: Command to install the specified node and eslint versions before running analysis.
14+
---
3715

38-
## Download
16+
## Supported Platforms
3917

40-
### MacOS (brew)
18+
- **macOS**
19+
- **Linux**
20+
- **Windows (via WSL only)**
4121

42-
To install `codacy-cli` using Homebrew:
22+
> **Note:** Native Windows is not yet supported. For Windows, use [Windows Subsystem for Linux (WSL)](https://learn.microsoft.com/en-us/windows/wsl/) and follow the Linux instructions inside your WSL terminal.
23+
24+
---
25+
26+
## Installation
27+
28+
### macOS (Homebrew)
4329

4430
```bash
4531
brew install codacy/codacy-cli-v2/codacy-cli-v2
4632
```
4733

48-
### Linux
34+
### Linux / Windows (WSL)
4935

50-
For Linux, we rely on the codacy-cli.sh script in the root. To download the CLI, run:
36+
Run the following in your terminal (Linux or WSL):
5137

5238
```bash
5339
bash <(curl -Ls https://raw.githubusercontent.com/codacy/codacy-cli-v2/main/codacy-cli.sh)
5440
```
55-
You can either put the downloaded script in a specific file or create an alias that will download the script and look for changes:
41+
42+
Or create an alias for convenience:
5643

5744
```bash
5845
alias codacy-cli="bash <(curl -Ls https://raw.githubusercontent.com/codacy/codacy-cli-v2/main/codacy-cli.sh)"
5946
```
6047

61-
## Installation
48+
---
49+
50+
## CLI Commands
51+
52+
### `init` — Bootstrap Project Configuration
53+
54+
Bootstraps the CLI configuration in your project's folder. This command creates a `.codacy` directory containing a `codacy.yaml` file, which specifies the runtimes and tools that will be used and installed.
55+
56+
- If you provide Codacy repository information (API token, provider, organization, repository), the configuration will be fetched from Codacy, ensuring consistency with your organization's standards.
57+
- If no Codacy information is provided, all available tools will be included. For each tool, if a local configuration file exists in your project, it will be used; otherwise, Codacy's suggested defaults will be used.
58+
59+
- **Local mode (local configuration files):**
60+
```bash
61+
codacy-cli init
62+
```
63+
- **Remote mode (fetch configuration from Codacy):**
64+
```bash
65+
codacy-cli init --api-token <token> --provider <gh|gl|bb> --organization <org> --repository <repo>
66+
```
67+
68+
**Flags:**
69+
- `--api-token` (string): Codacy API token (optional; enables fetching remote config)
70+
- `--provider` (string): Provider (`gh`, `gl`, `bb`), required with `--api-token`
71+
- `--organization` (string): Organization name, required with `--api-token`
72+
- `--repository` (string): Repository name, required with `--api-token`
73+
74+
### `install` — Install Runtimes and Tools
6275

63-
Before running the analysis, install the specified tools:
76+
Installs all runtimes and tools specified in `.codacy/codacy.yaml`:
77+
- Downloads and extracts runtimes (Node, Python, Dart, Java, etc.)
78+
- Installs tools (ESLint, Trivy, Pylint, PMD, etc.) using the correct package manager or direct download
79+
- Handles platform-specific details
80+
- Skips already installed components (e.g., Node, Python, Dart, Java, etc.)
81+
- Shows a progress bar and reports any failures
6482

6583
```bash
6684
codacy-cli install
6785
```
86+
- Optionally specify a custom registry:
87+
```bash
88+
codacy-cli install --registry <url>
89+
```
6890

69-
## Run Analysis
91+
### `analyze`Run Code Analysis
7092

71-
To run ESLint and output the results to the terminal:
93+
Runs all configured tools, or a specific tool, on your codebase.
7294

7395
```bash
96+
# Run all tools
97+
codacy-cli analyze
98+
99+
# Run a specific tool (e.g., ESLint)
74100
codacy-cli analyze --tool eslint
101+
102+
# Output results in SARIF format
103+
codacy-cli analyze --tool eslint --format sarif
104+
105+
# Store results as SARIF in a file
106+
codacy-cli analyze -t eslint --format sarif -o eslint.sarif
107+
108+
# Analyze a specific file with all configured tools
109+
codacy-cli analyze path/to/file.js
110+
111+
# Analyze a specific file with a specific tool (e.g., ESLint)
112+
codacy-cli analyze --tool eslint path/to/file.js
75113
```
76114

77-
To output results in SARIF format to the terminal:
115+
**Flags:**
116+
- `--output, -o`: Output file for the results; if not provided, results will be printed to the console
117+
- `--tool, -t`: Tool to run analysis with (e.g., eslint)
118+
- `--format`: Output format (e.g., `sarif`)
119+
- `--fix`: Automatically fix issues when possible
120+
121+
### `upload` — Upload SARIF Results to Codacy
122+
123+
Uploads a SARIF file containing analysis results to Codacy.
78124

79125
```bash
80-
codacy-cli analyze --tool eslint --format sarif
126+
# With project token
127+
codacy-cli upload -s path/to/your.sarif -c <commit-uuid> -t <project-token>
128+
129+
# With API token
130+
codacy-cli upload -s path/to/your.sarif -c <commit-uuid> -a <api-token> -p <provider> -o <owner> -r <repository>
81131
```
82132

83-
To store the results as SARIF in a file:
133+
**Flags:**
134+
- `--sarif-path, -s`: Path to the SARIF report (required)
135+
- `--commit-uuid, -c`: Commit UUID
136+
- `--project-token, -t`: Project token for Codacy API
137+
- `--api-token, -a`: User-level token for Codacy API
138+
- `--provider, -p`: Provider name (e.g., gh, gl, bb)
139+
- `--owner, -o`: Repository owner
140+
- `--repository, -r`: Repository name
141+
142+
### `update` — Update the CLI
143+
144+
Fetches and installs the latest version of the CLI.
84145

85146
```bash
86-
codacy-cli analyze -t eslint --format sarif -o eslint.sarif
147+
codacy-cli update
87148
```
88149

89-
## Upload Results
150+
### `version` — Show Version Information
90151

91-
To upload a SARIF file to Codacy:
152+
Displays detailed version/build information for the CLI.
92153

93154
```bash
94-
codacy-cli upload -s path/to/your.sarif -c your-commit-uuid -t your-project-token
155+
codacy-cli version
95156
```
96157

97-
## Breaking Changes
158+
---
159+
160+
## Configuration
161+
162+
- **`.codacy/codacy.yaml`**: Main configuration file specifying runtimes and tool versions.
163+
- **`.codacy/tools-configs/`**: Tool-specific configuration files (auto-generated or fetched from Codacy).
164+
165+
---
98166

99-
Some behaviors have changed with the new updates of the CLI. To rely on a specific version, you can add that version to your environment:
167+
## Example Usage
100168

169+
```bash
170+
# 1. Initialize project (local or remote)
171+
codacy-cli init
172+
# or
173+
codacy-cli init --api-token <token> --provider gh --organization my-org --repository my-repo
174+
175+
# 2. Install all required runtimes and tools
176+
codacy-cli install
177+
178+
# 3. Run analysis (all tools or specific tool)
179+
codacy-cli analyze
180+
codacy-cli analyze --tool eslint
181+
182+
# 4. Upload results to Codacy
183+
codacy-cli upload -s eslint.sarif -c <commit-uuid> -t <project-token>
101184
```
102-
export CODACY_CLI_V2_VERSION="1.0.0-main.133.3607792"
185+
186+
---
187+
188+
## Troubleshooting
189+
190+
### WSL (Windows Subsystem for Linux)
191+
- **Always use a WSL terminal** (e.g., Ubuntu on Windows) for all commands.
192+
- Ensure you have the latest version of WSL and a supported Linux distribution installed.
193+
- If you see errors related to missing Linux tools (e.g., `curl`, `tar`), install them using your WSL package manager (e.g., `sudo apt install curl tar`).
194+
195+
### MacOS: Errors related to `docker-credential-osxkeychain` not found
196+
197+
Install the docker credential helper:
198+
199+
```bash
200+
brew install docker-credential-helper
103201
```
104202

203+
---
204+
105205
## Example Repository
106206

107-
As an example, you can check https://github.com/troubleshoot-codacy/eslint-test-examples for a repository that has an action relying on this CLI.
207+
See [eslint-test-examples](https://github.com/troubleshoot-codacy/eslint-test-examples) for a repository using this CLI in GitHub Actions.
108208

109-
## Troubleshooting
209+
---
110210

111-
#### Errors related to `docker-credential-osxkeychain` not found when running analysis
211+
## Breaking Changes & Version Pinning
112212

113-
Install the docker credential helper. For example, in MacOS:
213+
Some behaviors have changed with recent updates. To rely on a specific CLI version, set the following environment variable:
114214

115215
```bash
116-
brew install docker-credential-helper
216+
export CODACY_CLI_V2_VERSION="1.0.0-main.133.3607792"
117217
```
218+
219+
Check the [releases](https://github.com/codacy/codacy-cli-v2/releases) page for all available versions.
220+
221+
---

0 commit comments

Comments
 (0)