diff --git a/resources/globalConfiguration.json b/resources/globalConfiguration.json index 8f79812d..bbe15a69 100644 --- a/resources/globalConfiguration.json +++ b/resources/globalConfiguration.json @@ -14,7 +14,8 @@ "bdd": false, "syntaxCheck": false, "edtValidate": false, - "smoke": false + "smoke": false, + "swagger": false }, "initInfobase": { "initMethod": "fromStorage", diff --git a/resources/schema.json b/resources/schema.json index 0532694c..177bee9d 100644 --- a/resources/schema.json +++ b/resources/schema.json @@ -62,6 +62,10 @@ "bdd" : { "type" : "boolean", "description" : "Запуск BDD сценариев включен" + }, + "swagger" : { + "type" : "boolean", + "description" : "Подготовка Swagger документации" } } }, diff --git a/src/ru/pulsar/jenkins/library/configuration/StageFlags.groovy b/src/ru/pulsar/jenkins/library/configuration/StageFlags.groovy index 2fdcbe74..908e375a 100644 --- a/src/ru/pulsar/jenkins/library/configuration/StageFlags.groovy +++ b/src/ru/pulsar/jenkins/library/configuration/StageFlags.groovy @@ -24,6 +24,9 @@ class StageFlags implements Serializable { @JsonPropertyDescription("Запуск BDD сценариев включен") boolean bdd + @JsonPropertyDescription("Подготовка Swagger документации") + boolean swagger + @Override @NonCPS String toString() { @@ -34,6 +37,7 @@ class StageFlags implements Serializable { ", smoke=" + smoke + ", initSteps=" + initSteps + ", bdd=" + bdd + + ", swagger=" + swagger + '}'; } diff --git a/src/ru/pulsar/jenkins/library/steps/Swagger.groovy b/src/ru/pulsar/jenkins/library/steps/Swagger.groovy new file mode 100644 index 00000000..71d2a27b --- /dev/null +++ b/src/ru/pulsar/jenkins/library/steps/Swagger.groovy @@ -0,0 +1,52 @@ +package ru.pulsar.jenkins.library.steps + +import groovy.io.FileType +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.Logger +import ru.pulsar.jenkins.library.utils.OscriptModules + +class Swagger { + public static final String OUT = 'build/out/swagger/' + public static final String OUT_HTML = 'build/out/swagger/html/' + + private final JobConfiguration config; + + Swagger(JobConfiguration config) { + this.config = config + } + + def run() { + if (!config.stageFlags.swagger) { + Logger.println("Swagger documentation is disabled") + return + } + + IStepExecutor steps = ContextRegistry.getContext().getStepExecutor() + + Logger.printLocation() + + steps.installLocalDependencies() + + String swaggerPath = OscriptModules.getAppExecutable("swagger"); + + steps.cmd(swaggerPath + " generate --src-path $config.srcDir --out $OUT") + + def dir = new File("$env.WORKSPACE/$OUT") + dir.eachFile(FileType.FILES){ + Logger.println(it.name) + Logger.println(it.path) + steps.cmd("bootprint openapi $it.path $OUT_HTML") + } + publishHTML (target : [allowMissing: false, + alwaysLinkToLastBuild: true, + keepAll: true, + reportDir: $OUT_HTML, + reportFiles: 'index.html', + reportName: 'Swagger API', + reportTitles: 'API $it.name']) + + steps.archiveArtifacts(OUT) + } +} \ No newline at end of file diff --git a/src/ru/pulsar/jenkins/library/utils/OscriptModules.groovy b/src/ru/pulsar/jenkins/library/utils/OscriptModules.groovy new file mode 100644 index 00000000..7dd17487 --- /dev/null +++ b/src/ru/pulsar/jenkins/library/utils/OscriptModules.groovy @@ -0,0 +1,19 @@ +package ru.pulsar.jenkins.library.utils + +import ru.pulsar.jenkins.library.IStepExecutor +import ru.pulsar.jenkins.library.ioc.ContextRegistry + +class OscriptModules { + static String getAppExecutable(String executableName) { + + IStepExecutor steps = ContextRegistry.getContext().getStepExecutor() + + String executableBinary = steps.isUnix() ? executableName : "${executableName}.bat"; + String executablePath = "oscript_modules/bin/$executableBinary"; + if (!steps.fileExists(executablePath)) { + executablePath = executableBinary; + } + + return executablePath; + } +} \ No newline at end of file diff --git a/vars/pipeline1C.groovy b/vars/pipeline1C.groovy index efab2c46..e428a7d5 100644 --- a/vars/pipeline1C.groovy +++ b/vars/pipeline1C.groovy @@ -201,6 +201,21 @@ void call() { sonarScanner config } } + + stage('Документирование'){ + parallel { + stage('Swagger') { + agent { + label 'oscript' + } + steps { + script { + swagger config + } + } + } + } + } } post('post-stage') { diff --git a/vars/swagger.groovy b/vars/swagger.groovy new file mode 100644 index 00000000..8bd14061 --- /dev/null +++ b/vars/swagger.groovy @@ -0,0 +1,11 @@ +import ru.pulsar.jenkins.library.configuration.JobConfiguration +import ru.pulsar.jenkins.library.ioc.ContextRegistry +import ru.pulsar.jenkins.library.steps.Swagger + +def call(JobConfiguration config) { + ContextRegistry.registerDefaultContext(this) + + def swagger = new Swagger(config) + swagger.run() +} +