Repository navigation
docs: replace Codacy CLI v2 with the Analysis CLI [OD-742] #2821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,68 +16,93 @@ To run Dart Analyzer as a [client-side tool](client-side-tools.md): | |
| end="<!--instructions-end-->" | ||
| %} | ||
|
|
||
| ## Important Concepts | ||
| ## Dart SDK and dependencies | ||
|
|
||
| - **`.codacy/codacy.yaml`**: Configuration file to specify `dart`, or `flutter`, and `dartanalyzer` versions for the CLI. | ||
| The [Codacy Analysis CLI](../../codacy-analysis-cli/index.md) runs `dart analyze` from a Dart SDK. It uses the SDK that Codacy manages for you, if you have installed it, and otherwise the `dart` command on your `PATH`: | ||
|
|
||
| ```yaml | ||
| runtimes: | ||
| - [email protected] | ||
| tools: | ||
| - [email protected] | ||
| ``` | ||
| - **Codacy-managed SDK:** Add `--install-dependencies` to `analyze` and the CLI downloads the pinned Dart SDK, about 210 MB, into `~/.codacy/tools/dartanalyzer/`. | ||
| - **Your own SDK:** Install [Dart](https://dart.dev/get-dart), or Flutter, which bundles Dart, and make sure `dart` is on your `PATH`. | ||
|
|
||
| Before analyzing, resolve your project's packages with `dart pub get`, or `flutter pub get` for a Flutter project. The CLI never runs it for you. Without the resolved packages, every `package:` import is unresolvable: the CLI warns and skips the checks that depend on them for that run. | ||
|
|
||
| or | ||
| ## Manual configuration | ||
|
|
||
| ```yaml | ||
| runtimes: | ||
| - [email protected] | ||
| tools: | ||
| - [email protected] | ||
| Install the Codacy Analysis CLI and initialize the repository. Initialization writes `.codacy/codacy.config.json`, which `analyze` requires: pulling it from Codacy Cloud with `init --remote` means the local run uses the same Dart Analyzer patterns as your repository's **Code patterns** page. | ||
|
|
||
| ```bash | ||
| npm i -g @codacy/analysis-cli | ||
| codacy-analysis init --remote <gh|gl|bb> <ORGANIZATION> <REPOSITORY> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 MEDIUM RISK Document the authentication steps required for both remote configuration initialization and result uploads before running these commands.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. False positive. Authentication is the first step of the shared client-side tool instructions included at the top of this page ( 🤖 Generated by /pr-fixup command |
||
| ``` | ||
|
|
||
| ## Manual configuration | ||
| Then resolve your packages, run the analysis, and upload the results: | ||
|
|
||
| ```bash | ||
| codacy-cli install | ||
| codacy-cli analyze -t dartanalyzer -o dartanalyzer.sarif | ||
| codacy-cli upload -s dartanalyzer.sarif -c $COMMIT_SHA -t CODACY_PROJECT_TOKEN | ||
| dart pub get | ||
| codacy-analysis analyze --tool dartanalyzer --output-format sarif --output dartanalyzer.sarif | ||
| codacy-analysis upload dartanalyzer.sarif --commit $COMMIT_SHA | ||
| ``` | ||
|
|
||
| **If you're using an account API token**, you must also provide the flags `-p`, `-o`, and `-r`. You can obtain the values for these flags from the URL of your repository dashboard on Codacy: | ||
| **If you're using an account API token**, you must also provide the `--repository` flag with your provider, organization, and repository name. You can obtain these values from the URL of your repository dashboard on Codacy: | ||
|
|
||
| ```bash | ||
| codacy-cli install | ||
| codacy-cli analyze -t dartanalyzer -o dartanalyzer.sarif | ||
| codacy-cli analyze -t dartanalyzer -o dartanalyzer.sarif -c $COMMIT_SHA -a CODACY_API_TOKEN -p provider (gh|gl|bb) -o ORGANIZATION -r REPOSITORY | ||
| dart pub get | ||
| codacy-analysis analyze --tool dartanalyzer --output-format sarif --output dartanalyzer.sarif | ||
| codacy-analysis upload dartanalyzer.sarif --commit $COMMIT_SHA --repository <gh|gl|bb> <ORGANIZATION> <REPOSITORY> | ||
| ``` | ||
|
|
||
| !!! note | ||
| `--tool` matches against the tool IDs in your `.codacy/codacy.config.json`, and only tools listed there run. If `--tool dartanalyzer` doesn't match your setup, check that file for the ID it recorded. | ||
|
|
||
| ## GitHub Action | ||
|
|
||
| The [Codacy Analysis CLI GitHub Action](https://github.com/codacy/analysis-cli-action) runs the same `codacy-analysis` CLI as the manual configuration above. If your repository has no committed `.codacy/codacy.config.json`, the action fetches the repository's configuration from Codacy with your token. | ||
|
|
||
| On `pull_request` events, the action uploads the results for the pull request's head commit. Check out that commit with `ref:` as in the examples below, otherwise line numbers can point at the wrong lines. | ||
|
|
||
| The examples set up Dart and resolve the packages before running the action. For a Flutter project, use a Flutter setup action and `flutter pub get` instead. | ||
|
|
||
| ### Using a project token | ||
|
|
||
| {% raw %} | ||
| ```yml | ||
| - name: Run Codacy CLI | ||
| uses: codacy/codacy-cli-v2-action@main | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| project-token: CODACY_PROJECT_TOKEN | ||
| ref: ${{ github.event.pull_request.head.sha || github.sha }} | ||
|
|
||
| - uses: dart-lang/setup-dart@v1 | ||
|
|
||
| - run: dart pub get | ||
|
|
||
| - name: Run Codacy Analysis CLI | ||
| uses: codacy/analysis-cli-action@v1 | ||
| with: | ||
| project-token: ${{ secrets.CODACY_PROJECT_TOKEN }} | ||
| tool: dartanalyzer | ||
| upload_report: true | ||
| upload: true | ||
| ``` | ||
| {% endraw %} | ||
|
|
||
| ### Using an account API token | ||
|
|
||
| The action takes the provider, organization, and repository from the workflow. Set `provider`, `owner`, and `repository` only if the repository is on Codacy under different names. | ||
|
|
||
| {% raw %} | ||
| ```yml | ||
| - name: Run Codacy CLI | ||
| uses: codacy/codacy-cli-v2-action@main | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| api_token: CODACY_API_TOKEN | ||
| ref: ${{ github.event.pull_request.head.sha || github.sha }} | ||
|
|
||
| - uses: dart-lang/setup-dart@v1 | ||
|
|
||
| - run: dart pub get | ||
|
|
||
| - name: Run Codacy Analysis CLI | ||
| uses: codacy/analysis-cli-action@v1 | ||
| with: | ||
| api-token: ${{ secrets.CODACY_API_TOKEN }} | ||
| tool: dartanalyzer | ||
| upload_report: true | ||
| provider: gh | ||
| owner: codacy-acme | ||
| repository: sample-dart-project | ||
| upload: true | ||
| ``` | ||
| {% endraw %} | ||
|
|
||
| !!! warning "Tokens should be stored in the repository secrets." | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 MEDIUM RISK
Preserve the existing
#important-conceptsanchor alongside the new heading so existing deep links continue to work.TIPReact 👍 if this review is right, or reply with what's wrong and how it could be better to help improve the reviewer.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dismissing. The old "Important concepts" section described CLI v2's
.codacy/codacy.yaml, which no longer applies, so an anchor that lands readers on SDK setup would be misleading. A stale#important-conceptslink still opens the page, just at the top. No internal link uses it:mkdocs build --strictpasses.🤖 Generated by /pr-fixup command