Skip to content
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

Публикация результатов синтаксического контроля в Allure #148

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ val junitVersion = "5.11.0"
val spockVersion = "1.3-groovy-2.4"
val groovyVersion = "2.4.21"
val slf4jVersion = "2.0.16"
val jsonschemaVersion = "4.36.0"
val jsonschemaVersion = "4.37.0"

dependencies {
implementation("org.codehaus.groovy", "groovy-all", groovyVersion)
Expand Down
5 changes: 3 additions & 2 deletions resources/globalConfiguration.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
},
"syntaxCheck": {
"groupErrorsByMetadata": true,
"pathToJUnitReport": "./build/out/jUnit/syntax.xml",
"exceptionFile": "./tools/syntax-check-exception-file.txt",
"checkModes": [
"-ThinClient",
Expand All @@ -79,7 +78,9 @@
"-CheckUseSynchronousCalls",
"-DistributiveModules"
],
"vrunnerSettings": "./tools/vrunner.json"
"vrunnerSettings": "./tools/vrunner.json",
"publishToAllureReport": false,
"publishToJUnitReport": true
},
"smoke": {
"vrunnerSettings": "./tools/vrunner.json",
Expand Down
26 changes: 15 additions & 11 deletions resources/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,11 @@
"properties" : {
"coverage" : {
"type" : "boolean",
"description" : "Выполнять замер покрытия",
"default" : "false"
"description" : "Выполнять замер покрытия"
nixel2007 marked this conversation as resolved.
Show resolved Hide resolved
},
"dbgsPort" : {
"type" : "integer",
"description" : "Порт, на котором будет запущен сервер отладки для замера покрытия",
"default" : "1550"
"description" : "Порт, на котором будет запущен сервер отладки для замера покрытия"
nixel2007 marked this conversation as resolved.
Show resolved Hide resolved
},
"vrunnerSteps" : {
"description" : "Шаги, запускаемые через vrunner.\n В каждой строке передается отдельная команда \n vrunner и ее аргументы (например, \"vanessa --settings ./tools/vrunner.json\").\n По умолчанию содержит одну команду \"vanessa --settings ./tools/vrunner.json\".\n ",
Expand Down Expand Up @@ -250,12 +248,12 @@
"coverage" : {
"type" : "boolean",
"description" : "Выполнять замер покрытия",
"default" : "false"
"default" : false
},
"dbgsPort" : {
"type" : "integer",
"description" : "Порт, на котором будет запущен сервер отладки для замера покрытия",
"default" : "1550"
"default" : 1550
},
"publishToAllureReport" : {
"type" : "boolean",
Expand Down Expand Up @@ -378,9 +376,15 @@
"type" : "boolean",
"description" : "Группировать выявленные ошибки по объектам метаданных.\n По умолчанию включено.\n "
},
"pathToJUnitReport" : {
"type" : "string",
"description" : "Путь к файлу отчета jUnit\n По умолчанию содержит значение \"./build/out/jUnit/syntax.xml\"\n "
"publishToAllureReport" : {
"type" : "boolean",
"description" : "Выполнять публикацию результатов в отчет Allure.\n По умолчанию выключено.\n ",
"default": false
},
"publishToJUnitReport" : {
"type" : "boolean",
"description" : "Выполнять публикацию результатов в отчет JUnit.\n По умолчанию включено.\n ",
"default": true
},
"vrunnerSettings" : {
"type" : "string",
Expand Down Expand Up @@ -469,12 +473,12 @@
"coverage" : {
"type" : "boolean",
"description" : "Выполнять замер покрытия",
"default" : "false"
"default" : false
},
"dbgsPort" : {
"type" : "integer",
"description" : "Порт, на котором будет запущен сервер отладки для замера покрытия",
"default" : "1550"
"default" : 1550
},
"publishToAllureReport" : {
"type" : "boolean",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@ package ru.pulsar.jenkins.library.configuration

import com.cloudbees.groovy.cps.NonCPS
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.annotation.JsonPropertyDescription

@JsonIgnoreProperties(ignoreUnknown = true)
class SyntaxCheckOptions implements Serializable {

@JsonPropertyDescription("""Путь к файлу отчета jUnit
По умолчанию содержит значение "./build/out/jUnit/syntax.xml"
""")
String pathToJUnitReport = "./build/out/jUnit/syntax.xml"

@JsonPropertyDescription("""Группировать выявленные ошибки по объектам метаданных.
По умолчанию включено.
""")
Expand All @@ -31,14 +28,27 @@ class SyntaxCheckOptions implements Serializable {
""")
String vrunnerSettings = "./tools/vrunner.json"

@JsonPropertyDescription("""Выполнять публикацию результатов в отчет Allure.
По умолчанию выключено.
""")
@JsonProperty(defaultValue = "false")
boolean publishToAllureReport = false

@JsonPropertyDescription("""Выполнять публикацию результатов в отчет JUnit.
По умолчанию включено.
""")
@JsonProperty(defaultValue = "true")
boolean publishToJUnitReport = true

@Override
@NonCPS
String toString() {
return "SyntaxCheckOptions{" +
"pathToJUnitReport='" + pathToJUnitReport + '\'' +
", groupErrorsByMetadata=" + groupErrorsByMetadata +
", checkModes=" + checkModes +
", vrunnerSettings=" + vrunnerSettings +
'}';
", publishToAllureReport=" + publishToAllureReport +
", publishToJUnitReport=" + publishToJUnitReport +
'}'
}
}
3 changes: 3 additions & 0 deletions src/ru/pulsar/jenkins/library/steps/PublishAllure.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class PublishAllure implements Serializable {
if (config.stageFlags.smoke && config.smokeTestOptions.publishToAllureReport) {
safeUnstash(SmokeTest.ALLURE_STASH)
}
if (config.stageFlags.syntaxCheck && config.syntaxCheckOptions.publishToAllureReport) {
safeUnstash(SyntaxCheck.ALLURE_STASH)
}

def env = steps.env()

Expand Down
96 changes: 96 additions & 0 deletions src/ru/pulsar/jenkins/library/steps/SyntaxCheck.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package ru.pulsar.jenkins.library.steps

import hudson.FilePath
import ru.pulsar.jenkins.library.IStepExecutor
import ru.pulsar.jenkins.library.configuration.JobConfiguration
import ru.pulsar.jenkins.library.ioc.ContextRegistry
import ru.pulsar.jenkins.library.utils.FileUtils
import ru.pulsar.jenkins.library.utils.Logger
import ru.pulsar.jenkins.library.utils.VRunner

class SyntaxCheck {

public static final String ALLURE_STASH = 'syntax-check-allure'

private final JobConfiguration config

SyntaxCheck(JobConfiguration config) {
this.config = config
}

def run() {
IStepExecutor steps = ContextRegistry.getContext().getStepExecutor()

Logger.printLocation()

if (!config.stageFlags.syntaxCheck) {
Logger.println("Syntax-check step is disabled")
return
}

def env = steps.env()

def options = config.syntaxCheckOptions

List<String> logosConfig = ["LOGOS_CONFIG=$config.logosConfig"]
steps.withEnv(logosConfig) {
steps.installLocalDependencies()

String junitReport = "build/out/jUnit/syntax-check/syntax-check.xml"
FilePath pathToJUnitReport = FileUtils.getFilePath("$env.WORKSPACE/$junitReport")
String junitReportDir = FileUtils.getLocalPath(pathToJUnitReport.getParent())

String allureReport = "build/out/allure/syntax-check/allure.xml"
FilePath pathToAllureReport = FileUtils.getFilePath("$env.WORKSPACE/$allureReport")
String allureReportDir = FileUtils.getLocalPath(pathToAllureReport.getParent())

String vrunnerPath = VRunner.getVRunnerPath()
String command = "$vrunnerPath syntax-check --ibconnection \"/F./build/ib\""

// Временно убрал передачу параметра.
// См. https://github.com/vanessa-opensource/vanessa-runner/issues/361
// command += " --workspace $env.WORKSPACE"

if (options.groupErrorsByMetadata) {
command += ' --groupbymetadata'
}

if (options.publishToJUnitReport) {
steps.createDir(junitReportDir)
command += " --junitpath $pathToJUnitReport"
}

if (options.publishToAllureReport) {
steps.createDir(allureReportDir)
command += " --allure-results2 $allureReportDir"
}

FilePath vrunnerSettings = FileUtils.getFilePath("$env.WORKSPACE/$options.vrunnerSettings")
if (vrunnerSettings.exists()) {
command += " --settings $vrunnerSettings"
}

if (!options.exceptionFile.empty && steps.fileExists(options.exceptionFile)) {
command += " --exception-file $options.exceptionFile"
}

if (options.checkModes.length > 0) {
def checkModes = options.checkModes.join(" ")
command += " --mode $checkModes"
}

// Запуск синтакс-проверки
VRunner.exec(command, true)

if (options.publishToAllureReport) {
steps.stash(ALLURE_STASH, "$allureReportDir/**", true)
steps.archiveArtifacts("$allureReportDir/**")
}

if (options.publishToJUnitReport) {
steps.junit("$junitReportDir/*.xml", true)
steps.archiveArtifacts("$junitReportDir/**")
}
}
Comment on lines +82 to +94
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Рекомендуется улучшить обработку ошибок

При выполнении команды и архивации отчетов отсутствует явная обработка исключений, что может затруднить диагностику проблем.

Предлагаемый рефакторинг:

     def run() {
         // ... existing code ...
+        try {
             VRunner.exec(command, true)
 
             if (options.publishToAllureReport) {
                 steps.stash(ALLURE_STASH, "$allureReportDir/**", true)
                 steps.archiveArtifacts("$allureReportDir/**")
             }
 
             if (options.publishToJUnitReport) {
                 steps.junit("$junitReportDir/*.xml", true)
                 steps.archiveArtifacts("$junitReportDir/**")
             }
+        } catch (Exception e) {
+            Logger.println("Ошибка при выполнении синтаксической проверки: ${e.message}")
+            throw e
+        }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Запуск синтакс-проверки
VRunner.exec(command, true)
if (options.publishToAllureReport) {
steps.stash(ALLURE_STASH, "$allureReportDir/**", true)
steps.archiveArtifacts("$allureReportDir/**")
}
if (options.publishToJUnitReport) {
steps.junit("$junitReportDir/*.xml", true)
steps.archiveArtifacts("$junitReportDir/**")
}
}
// Запуск синтакс-проверки
try {
VRunner.exec(command, true)
if (options.publishToAllureReport) {
steps.stash(ALLURE_STASH, "$allureReportDir/**", true)
steps.archiveArtifacts("$allureReportDir/**")
}
if (options.publishToJUnitReport) {
steps.junit("$junitReportDir/*.xml", true)
steps.archiveArtifacts("$junitReportDir/**")
}
} catch (Exception e) {
Logger.println("Ошибка при выполнении синтаксической проверки: ${e.message}")
throw e
}
}

}
}
16 changes: 13 additions & 3 deletions vars/pipeline1C.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,19 @@ void call() {
beforeAgent true
expression { config.stageFlags.syntaxCheck }
}
steps {
timeout(time: config.timeoutOptions.syntaxCheck, unit: TimeUnit.MINUTES) {
syntaxCheck config
stages {
stage('Распаковка ИБ') {
steps {
unzipInfobase()
}
}

stage('Выполнение синтаксического контроля') {
steps {
timeout(time: config.timeoutOptions.syntaxCheck, unit: TimeUnit.MINUTES) {
syntaxCheck config
}
}
}
}
}
Expand Down
58 changes: 3 additions & 55 deletions vars/syntaxCheck.groovy
Original file line number Diff line number Diff line change
@@ -1,64 +1,12 @@
import hudson.FilePath
import ru.pulsar.jenkins.library.configuration.JobConfiguration
import ru.pulsar.jenkins.library.ioc.ContextRegistry
import ru.pulsar.jenkins.library.utils.FileUtils
import ru.pulsar.jenkins.library.utils.VRunner
import ru.pulsar.jenkins.library.steps.SyntaxCheck

def call(JobConfiguration config) {

ContextRegistry.registerDefaultContext(this)

// TODO: Вынести в отдельный класс по аналогии с SonarScanner
def syntaxCheck = new SyntaxCheck(config)
syntaxCheck.run()

printLocation()

if (!config.stageFlags.syntaxCheck) {
echo("Syntax-check step is disabled")
return
}

def options = config.syntaxCheckOptions

installLocalDependencies()

unzipInfobase()

FilePath pathToJUnitReport = FileUtils.getFilePath("$env.WORKSPACE/$options.pathToJUnitReport")

String outPath = pathToJUnitReport.getParent()
createDir(outPath)

String vrunnerPath = VRunner.getVRunnerPath();
String command = "$vrunnerPath syntax-check --ibconnection \"/F./build/ib\""

// Временно убрал передачу параметра.
// См. https://github.com/vanessa-opensource/vanessa-runner/issues/361
// command += " --workspace $env.WORKSPACE"

if (options.groupErrorsByMetadata) {
command += ' --groupbymetadata'
}

command += " --junitpath $pathToJUnitReport";

FilePath vrunnerSettings = FileUtils.getFilePath("$env.WORKSPACE/$options.vrunnerSettings")
if (vrunnerSettings.exists()) {
command += " --settings $vrunnerSettings";
}

if (!options.exceptionFile.empty && fileExists(options.exceptionFile)) {
command += " --exception-file $options.exceptionFile"
}

if (options.checkModes.length > 0) {
def checkModes = options.checkModes.join(" ")
command += " --mode $checkModes"
}

// Запуск синтакс-проверки
VRunner.exec(command, true)

junit allowEmptyResults: true, testResults: FileUtils.getLocalPath(pathToJUnitReport)

archiveArtifacts FileUtils.getLocalPath(pathToJUnitReport)
}
Loading