Qodana 2024.2 Help

Inspect a monorepo project

A monorepo is a repository containing several projects, for example:

root/ backend/ frontend/ .git/

In this example, the backend/ folder contains a Java project, the frontend/ folder contains a JavaScript project, and the .git/ folder contains VCS-related information.

This section explains how to prepare and inspect a monorepo using:

Prepare your project

Configuration files

To configure Qodana for inspecting two projects, you need to create two YAML-formatted configuration files, one for each linter. In this example, these will be the qodana-backend.yaml and qodana-frontend.yaml files.

When Qodana runs, it uses the .git/ folder for linking detected problems to the corresponding source code in a Git repository, and for exploring inspection reports from within your IDE.

Here are the contents of the root/ folder:

root/ backend/ frontend/ .git/ qodana-backend.yaml qodana-frontend.yaml

Qodana Cloud

You can view inspection reports using Qodana Cloud. On the Qodana Cloud website, create one project for storing inspection reports for the frontend project, and another one for the backend project.

After you create the projects, you can use their project tokens for running Qodana.

Run Qodana

Because each Qodana linter can inspect a specific set of programming languages, Qodana CLI and Docker images of Qodana need to be run twice over the monorepo repository, once for each project contained in it.

These snippets use the QODANA_TOKEN variables that refer to project tokens. The --source-directory option specifies which project folder to inspect. The --config option specifies which Qodana configuration file to employ. Here is the snippet for the backend project:

qodana scan \   -e QODANA_TOKEN="<cloud-project-token-for-backend-project>" \   --source-directory backend \   --config qodana-backend.yaml

Here is the snippet for the frontend project:

qodana scan \   -e QODANA_TOKEN="<cloud-project-token-for-frontend-project>" \   --source-directory frontend \   --config qodana-frontend.yaml

These snippets use the QODANA_TOKEN variables that refer to project tokens. The --source-directory option specifies which project directory to inspect. The --config option specifies which Qodana configuration file to employ. Here is the snippet for the backend project:

docker run \   -v "$PWD":/data/project/ \   -e QODANA_TOKEN="<cloud-project-token-for-backend-project>" \   jetbrains/qodana-jvm:latest \   --source-directory backend \   --config qodana-backend.yaml

Here is the snippet for the frontend project:

docker run \   -v "$PWD":/data/project/ \   -e QODANA_TOKEN="<cloud-project-token-for-frontend-project>" \   jetbrains/qodana-js:latest \   --source-directory frontend \   --config qodana-frontend.yaml

You can use the Qodana Scan GitHub action for running Qodana on GitHub as explained in this procedure.

  1. On the Settings tab of the GitHub UI, create the QODANA_TOKEN_BACKEND and QODANA_TOKEN_FRONTEND encrypted secrets and save the project tokens generated in Qodana Cloud as their values.

  2. On the Actions tab of the GitHub UI, set up a new workflow and create the .github/workflows/code_quality.yml file.

  3. Save this workflow configuration to the .github/workflows/code_quality.yml file:

    name: Qodana on: workflow_dispatch: pull_request: push: jobs: qodana-backend: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 with: fetch-depth: 0 - name: 'Qodana Backend' uses: JetBrains/qodana-action@v2024.2 with: args: | --source-directory,backend,--config,qodana-backend.yaml artifact-name: qodana-backend env: QODANA_TOKEN: ${{ secrets.QODANA_TOKEN_BACKEND }} qodana-frontend: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 with: fetch-depth: 0 - name: 'Qodana Frontend' uses: JetBrains/qodana-action@v2024.2 with: args: | --source-directory,frontend,--config,qodana-frontend.yaml artifact-name: qodana-frontend env: QODANA_TOKEN: ${{ secrets.QODANA_TOKEN_FRONTEND }}

View inspection results

Congratulations, now you can navigate to Qodana Cloud and review the inspection results for each project inside your monorepo project!

Last modified: 01 August 2024