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

Добавил стадию документирования Swagger #63

Open
wants to merge 22 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
00df82f
Поправил таймаут
kozstlink Nov 10, 2021
06dca77
Update README.md
nixel2007 Nov 8, 2021
c440d05
Возможность загрузки базы из хранилища, если исходники в формате EDT
kozstlink Nov 15, 2021
fd3700c
Возможность загрузки базы из хранилища, если исходники в формате EDT
kozstlink Nov 15, 2021
7712b80
Update pipeline1C.groovy
kuzja086 Nov 15, 2021
2343ddf
Правки
kozstlink Nov 17, 2021
f09b9a4
Merge branch 'firstBitSemenovskaya:develop' into develop
kuzja086 Nov 17, 2021
b970133
Возможность загрузки базы из хранилища, если исходники в формате EDT
kozstlink Nov 15, 2021
1b8c2e8
Возможность загрузки базы из хранилища, если исходники в формате EDT
kozstlink Nov 15, 2021
6fc81d8
Update pipeline1C.groovy
kuzja086 Nov 15, 2021
06c6c1d
Правки
kozstlink Nov 17, 2021
696f7b1
Update pipeline1C.groovy
kuzja086 Nov 20, 2021
577460b
Merge branch 'firstBitSemenovskaya:develop' into develop
kuzja086 Nov 20, 2021
f5ae473
Merge remote-tracking branch 'origin/develop'
kozstlink Nov 20, 2021
15d346f
Merge branch 'firstBitSemenovskaya:develop' into SwagerUpdate
kuzja086 Nov 29, 2021
713c423
Доработка стадии документирования swagger
kozstlink Nov 29, 2021
c8259bf
Рефакторинг
kozstlink Dec 3, 2021
312e775
Рефакторинг
kozstlink Dec 3, 2021
b2d5f38
Рефакторинг
kozstlink Dec 3, 2021
8a39f16
Рефакторинг
nixel2007 Dec 3, 2021
380027f
Test PublishHTML
kozstlink Dec 6, 2021
c5cb8fa
Test PublishHTML
kozstlink Dec 8, 2021
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
3 changes: 2 additions & 1 deletion resources/globalConfiguration.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"bdd": false,
"syntaxCheck": false,
"edtValidate": false,
"smoke": false
"smoke": false,
"swagger": false
},
"initInfobase": {
"initMethod": "fromStorage",
Expand Down
4 changes: 4 additions & 0 deletions resources/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@
"bdd" : {
"type" : "boolean",
"description" : "Запуск BDD сценариев включен"
},
"swagger" : {
"type" : "boolean",
"description" : "Подготовка Swagger документации"
}
}
},
Expand Down
4 changes: 4 additions & 0 deletions src/ru/pulsar/jenkins/library/configuration/StageFlags.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class StageFlags implements Serializable {
@JsonPropertyDescription("Запуск BDD сценариев включен")
boolean bdd

@JsonPropertyDescription("Подготовка Swagger документации")
boolean swagger

@Override
@NonCPS
String toString() {
Expand All @@ -34,6 +37,7 @@ class StageFlags implements Serializable {
", smoke=" + smoke +
", initSteps=" + initSteps +
", bdd=" + bdd +
", swagger=" + swagger +
'}';
}

Expand Down
52 changes: 52 additions & 0 deletions src/ru/pulsar/jenkins/library/steps/Swagger.groovy
Original file line number Diff line number Diff line change
@@ -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){
Copy link
Member

Choose a reason for hiding this comment

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

Разве там несколько сайтов? Я не пробовал запускать ещё, но думал, что там каталог с набором файлов и единственным index.html.

Если он там один, то достаточно один раз вызвать publishHTML на каталог

Copy link
Member

Choose a reason for hiding this comment

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

посмотрел, да, там их несколько.

раньше у publishHTML была особенность - его нельзя было вызывать несколько раз. нужно было подготовить массив из описаний публикаций и вызывать publishHTML один раз, передавая туда массив.

Logger.println(it.name)
Logger.println(it.path)
steps.cmd("bootprint openapi $it.path $OUT_HTML")
Copy link
Member

@nixel2007 nixel2007 Dec 8, 2021

Choose a reason for hiding this comment

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

Потыкал bootprint, страшненький :)
может привычный swagger-ui использовать?
https://github.com/swagger-api/swagger-ui
у него есть standalone-запуск

}
publishHTML (target : [allowMissing: false,
alwaysLinkToLastBuild: true,
keepAll: true,
reportDir: $OUT_HTML,
reportFiles: 'index.html',
reportName: 'Swagger API',
reportTitles: 'API $it.name'])

steps.archiveArtifacts(OUT)
nixel2007 marked this conversation as resolved.
Show resolved Hide resolved
}
}
19 changes: 19 additions & 0 deletions src/ru/pulsar/jenkins/library/utils/OscriptModules.groovy
Original file line number Diff line number Diff line change
@@ -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;
}
}
15 changes: 15 additions & 0 deletions vars/pipeline1C.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,21 @@ void call() {
sonarScanner config
}
}

stage('Документирование'){
parallel {
nixel2007 marked this conversation as resolved.
Show resolved Hide resolved
stage('Swagger') {
agent {
label 'oscript'
}
steps {
script {
swagger config
}
}
}
}
}
}

post('post-stage') {
Expand Down
11 changes: 11 additions & 0 deletions vars/swagger.groovy
Original file line number Diff line number Diff line change
@@ -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()
}