From 161a4f58b9f31ac37c1016e9ea0df1e85c09f468 Mon Sep 17 00:00:00 2001 From: Dima Date: Fri, 17 Jan 2025 13:18:50 +0300 Subject: [PATCH] mv syntaxCheck to separate class, add publish to allure --- resources/globalConfiguration.json | 5 +- resources/schema.json | 10 +- .../configuration/SyntaxCheckOptions.groovy | 20 ++-- .../jenkins/library/steps/SyntaxCheck.groovy | 96 +++++++++++++++++++ vars/pipeline1C.groovy | 16 +++- vars/syntaxCheck.groovy | 58 +---------- 6 files changed, 135 insertions(+), 70 deletions(-) create mode 100644 src/ru/pulsar/jenkins/library/steps/SyntaxCheck.groovy diff --git a/resources/globalConfiguration.json b/resources/globalConfiguration.json index 7e0e6e01..82688c94 100644 --- a/resources/globalConfiguration.json +++ b/resources/globalConfiguration.json @@ -64,7 +64,6 @@ }, "syntaxCheck": { "groupErrorsByMetadata": true, - "pathToJUnitReport": "./build/out/jUnit/syntax.xml", "exceptionFile": "./tools/syntax-check-exception-file.txt", "checkModes": [ "-ThinClient", @@ -79,7 +78,9 @@ "-CheckUseSynchronousCalls", "-DistributiveModules" ], - "vrunnerSettings": "./tools/vrunner.json" + "vrunnerSettings": "./tools/vrunner.json", + "publishToAllureReport": false, + "publishToJUnitReport": true }, "smoke": { "vrunnerSettings": "./tools/vrunner.json", diff --git a/resources/schema.json b/resources/schema.json index 5e03b5db..9158b856 100644 --- a/resources/schema.json +++ b/resources/schema.json @@ -378,9 +378,13 @@ "type" : "boolean", "description" : "Группировать выявленные ошибки по объектам метаданных.\n По умолчанию включено.\n " }, - "pathToJUnitReport" : { - "type" : "string", - "description" : "Путь к файлу отчета jUnit\n По умолчанию содержит значение \"./build/out/jUnit/syntax.xml\"\n " + "publishToAllureReport" : { + "type" : "boolean", + "description" : "Выполнять публикацию результатов в отчет Allure.\n По умолчанию выключено.\n " + }, + "publishToJUnitReport" : { + "type" : "boolean", + "description" : "Выполнять публикацию результатов в отчет JUnit.\n По умолчанию включено.\n " }, "vrunnerSettings" : { "type" : "string", diff --git a/src/ru/pulsar/jenkins/library/configuration/SyntaxCheckOptions.groovy b/src/ru/pulsar/jenkins/library/configuration/SyntaxCheckOptions.groovy index ded2357e..acd8425d 100644 --- a/src/ru/pulsar/jenkins/library/configuration/SyntaxCheckOptions.groovy +++ b/src/ru/pulsar/jenkins/library/configuration/SyntaxCheckOptions.groovy @@ -7,11 +7,6 @@ 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("""Группировать выявленные ошибки по объектам метаданных. По умолчанию включено. """) @@ -31,14 +26,25 @@ class SyntaxCheckOptions implements Serializable { """) String vrunnerSettings = "./tools/vrunner.json" + @JsonPropertyDescription("""Выполнять публикацию результатов в отчет Allure. + По умолчанию выключено. + """) + boolean publishToAllureReport + + @JsonPropertyDescription("""Выполнять публикацию результатов в отчет JUnit. + По умолчанию включено. + """) + boolean publishToJUnitReport + @Override @NonCPS String toString() { return "SyntaxCheckOptions{" + - "pathToJUnitReport='" + pathToJUnitReport + '\'' + ", groupErrorsByMetadata=" + groupErrorsByMetadata + ", checkModes=" + checkModes + ", vrunnerSettings=" + vrunnerSettings + - '}'; + ", publishToAllureReport=" + publishToAllureReport + + ", publishToJUnitReport=" + publishToJUnitReport + + '}' } } diff --git a/src/ru/pulsar/jenkins/library/steps/SyntaxCheck.groovy b/src/ru/pulsar/jenkins/library/steps/SyntaxCheck.groovy new file mode 100644 index 00000000..7b820845 --- /dev/null +++ b/src/ru/pulsar/jenkins/library/steps/SyntaxCheck.groovy @@ -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 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/**") + } + } + } +} \ No newline at end of file diff --git a/vars/pipeline1C.groovy b/vars/pipeline1C.groovy index 867e3830..fbd54449 100644 --- a/vars/pipeline1C.groovy +++ b/vars/pipeline1C.groovy @@ -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 + } + } } } } diff --git a/vars/syntaxCheck.groovy b/vars/syntaxCheck.groovy index b879fdb4..9d650852 100644 --- a/vars/syntaxCheck.groovy +++ b/vars/syntaxCheck.groovy @@ -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) }