Skip to content

Commit

Permalink
add coverage for yaxunit, fix smoke dbgs port
Browse files Browse the repository at this point in the history
  • Loading branch information
ovcharenko-di committed Aug 25, 2024
1 parent 5be230e commit 41a9c00
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 10 deletions.
8 changes: 8 additions & 0 deletions resources/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,14 @@
"publishToJUnitReport" : {
"type" : "boolean",
"description" : "Выполнять публикацию результатов в отчет JUnit.\n По умолчанию включено.\n "
},
"coverage" : {
"type" : "boolean",
"description" : "Выполнять замер покрытия"
},
"dbgsPort" : {
"type" : "integer",
"description" : "Порт, на котором будет запущен сервер отладки для замера покрытия"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class SmokeTestOptions implements Serializable {
Boolean coverage = false

@JsonPropertyDescription("Порт, на котором будет запущен сервер отладки для замера покрытия")
int dbgsPort = 1650
int dbgsPort = 1550

@Override
@NonCPS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ class YaxunitOptions implements Serializable {
""")
boolean publishToJUnitReport

@JsonPropertyDescription("Выполнять замер покрытия")
Boolean coverage = false

@JsonPropertyDescription("Порт, на котором будет запущен сервер отладки для замера покрытия")
int dbgsPort = 1550

@Override
@NonCPS
String toString() {
Expand All @@ -35,6 +41,8 @@ class YaxunitOptions implements Serializable {
", configPath='" + configPath +
", publishToAllureReport='" + publishToAllureReport +
", publishToJUnitReport='" + publishToJUnitReport +
", coverage='" + coverage +
", dbgsPort='" + dbgsPort +
'}'
}
}
20 changes: 14 additions & 6 deletions src/ru/pulsar/jenkins/library/steps/SonarScanner.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import ru.pulsar.jenkins.library.utils.VersionParser

class SonarScanner implements Serializable {

private final JobConfiguration config;
private final JobConfiguration config

SonarScanner(JobConfiguration config) {
this.config = config
Expand All @@ -27,7 +27,7 @@ class SonarScanner implements Serializable {
return
}

def env = steps.env();
def env = steps.env()

def sonarScannerBinary

Expand Down Expand Up @@ -63,21 +63,29 @@ class SonarScanner implements Serializable {
sonarCommand += " -Dsonar.externalIssuesReportPaths=build/out/edt-generic-issue.json"
}

if (config.stageFlags.bdd && config.bddOptions.coverage
|| config.stageFlags.smoke && config.smokeTestOptions.coverage) {
def stageFlags = config.stageFlags

if (stageFlags.bdd && config.bddOptions.coverage
|| stageFlags.smoke && config.smokeTestOptions.coverage
|| stageFlags.yaxunit && config.yaxunitOptions.coverage) {

StringJoiner coveragePathsConstructor = new StringJoiner(",")

if (config.stageFlags.bdd && config.bddOptions.coverage) {
if (stageFlags.bdd && config.bddOptions.coverage) {
steps.unstash(Bdd.COVERAGE_STASH_NAME)
coveragePathsConstructor.add(Bdd.COVERAGE_STASH_PATH)
}

if (config.stageFlags.smoke && config.smokeTestOptions.coverage) {
if (stageFlags.smoke && config.smokeTestOptions.coverage) {
steps.unstash(SmokeTest.COVERAGE_STASH_NAME)
coveragePathsConstructor.add(SmokeTest.COVERAGE_STASH_PATH)
}

if (stageFlags.yaxunit && config.yaxunitOptions.coverage) {
steps.unstash(Yaxunit.COVERAGE_STASH_NAME)
coveragePathsConstructor.add(Yaxunit.COVERAGE_STASH_PATH)
}

String coveragePaths = coveragePathsConstructor.toString()

sonarCommand += " -Dsonar.coverageReportPaths=${coveragePaths}"
Expand Down
32 changes: 29 additions & 3 deletions src/ru/pulsar/jenkins/library/steps/Yaxunit.groovy
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ru.pulsar.jenkins.library.steps

import hudson.FilePath
import org.apache.commons.lang.RandomStringUtils
import ru.pulsar.jenkins.library.IStepExecutor

import ru.pulsar.jenkins.library.configuration.JobConfiguration
Expand All @@ -16,6 +17,8 @@ class Yaxunit implements Serializable {
private final String DEFAULT_YAXUNIT_CONFIGURATION_RESOURCE = 'yaxunit.json'

public static final String YAXUNIT_ALLURE_STASH = 'yaxunit-allure'
public static final String COVERAGE_STASH_NAME = 'yaxunit-coverage'
public static final String COVERAGE_STASH_PATH = 'build/out/yaxunit-coverage.xml'

Yaxunit(JobConfiguration config) {
this.config = config
Expand Down Expand Up @@ -62,9 +65,28 @@ class Yaxunit implements Serializable {

}

// Выполяем команды
steps.withEnv(logosConfig) {
VRunner.exec(runTestsCommand, true)
def coverageOpts = config.coverageOptions
def port = options.dbgsPort
def lockableResource = RandomStringUtils.random(9, true, false)
if (options.coverage) {
lockableResource = "${env.NODE_NAME}_$port"
}

steps.lock(null, 1, lockableResource) {
if (options.coverage) {
steps.start("${coverageOpts.dbgsPath} --addr=127.0.0.1 --port=$port")
steps.start("${coverageOpts.coverage41CPath} start -i DefAlias -u http://127.0.0.1:$port -P $workspaceDir -s $srcDir -o $COVERAGE_STASH_PATH")
steps.cmd("${coverageOpts.coverage41CPath} check -i DefAlias -u http://127.0.0.1:$port")
}

// Выполняем команды
steps.withEnv(logosConfig) {
VRunner.exec(runTestsCommand, true)
}

if (options.coverage) {
steps.cmd("${coverageOpts.coverage41CPath} stop -i DefAlias -u http://127.0.0.1:$port")
}
}

// Сохраняем результаты
Expand All @@ -86,5 +108,9 @@ class Yaxunit implements Serializable {

steps.stash(YAXUNIT_ALLURE_STASH, "$allureReportDir/**", true)
}

if (options.coverage) {
steps.stash(COVERAGE_STASH_NAME, COVERAGE_STASH_PATH, true)
}
}
}

0 comments on commit 41a9c00

Please sign in to comment.