Qodana 2023.3 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

The qodana.yaml file

To configure Qodana for inspecting two projects, you need to create two separate qodana.yaml files. Qodana also expects qodana.yaml to be contained in the root folder of the monorepo project. This means that before running Qodana on the project from the backend/ folder, that project's qodana.yaml file needs to be copied to both the root folder and the frontend/ folder. If you plan to run Qodana using Docker, you can copy files using the bootstrap configuration option in qodana.yaml, for example:

bootstrap: cp qodana-backend.yaml qodana.yaml
bootstrap: cp qodana-frontend.yaml qodana.yaml

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.

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. Here is the snippet for the backend project:

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

Here is the snippet for the frontend project:

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

These snippets use the QODANA_TOKEN variables that refer to project tokens. The --source-directory option specifies which project directory to inspect. 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

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

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: 'Use qodana-backend config' run: cp ./qodana-backend.yaml ./qodana.yaml - name: 'Qodana Backend' uses: JetBrains/qodana-action@v2023.3 with: args: | --source-directory,backend, 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: 'Use qodana-frontend config' run: cp ./qodana-frontend.yaml ./qodana.yaml - name: 'Qodana Frontend' uses: JetBrains/qodana-action@v2023.3 with: args: | --source-directory,frontend, artifact-name: qodana-frontend env: QODANA_TOKEN: ${{ secrets.QODANA_TOKEN_FRONTEND }}

View inspection results

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

Last modified: 12 April 2024