Code coverage in Qodana from Space Automation

106 views Asked by At

I'm trying to set up Space automation to run and upload my code coverage to Qodana cloud.

I can run the coverage and see it in Qodana locally from Intellij, but I'm struggling to find how I can do this with Space automation. It will analyse my code, but not the code coverage.

This is my space automation script

.space.kts

job("Qodana") {
  startOn {
    gitPush {
      anyBranchMatching {
        +"main"
      }
    }
    codeReviewOpened{}
  }
  container("jetbrains/qodana-jvm") {
    env["QODANA_TOKEN"] = "{{ project:qodana-token }}"
    shellScript {
      content = "qodana"
    }
  }
}

and my qodana.yaml

version: "1.0"

#Specify inspection profile for code analysis
profile:
  name: qodana.recommended

#Enable inspections
include:
  - name: CheckDependencyLicenses

projectJDK: 17 #(Applied in CI/CD pipeline)

#Specify Qodana linter for analysis (Applied in CI/CD pipeline)
linter: jetbrains/qodana-jvm:latest

What am I missing?

1

There are 1 answers

0
Java Devil On

I finally figured this out. Two problems I had:

  • I wasn't running the code coverage in my automation
  • Once I had that running, I then had to pass the results to the qodana scan.

To implement this I ended up with this .space.kts file

job("Build, tests and Qodana") {
  startOn {
    gitPush {
      anyBranchMatching {
        +"main"
      }
    }
    codeReviewOpened{}
  }

  container(displayName = "Run mvn install", image = "maven:latest") {
    shellScript {
      content = """
        mkdir ${'$'}JB_SPACE_FILE_SHARE_PATH/code-coverage
        mvn clean install
        cp -r ./.qodana/code-coverage ${'$'}JB_SPACE_FILE_SHARE_PATH/code-coverage
      """.trimIndent()
    }
  }

  container(displayName =  "Run Qodana", image = "jetbrains/qodana-jvm") {
    env["QODANA_TOKEN"] = "{{ project:qodana-token }}"
    shellScript {
      content = """
        cp -r ${'$'}JB_SPACE_FILE_SHARE_PATH/code-coverage /data/coverage
        qodana
      """.trimIndent()
    }
  }
}