mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-14 11:03:09 +02:00
reduce redunadancy in md files for doc generation
This commit is contained in:
parent
d2b6be4e25
commit
47ba7ff035
@ -1,41 +1,15 @@
|
||||
import groovy.io.FileType;
|
||||
import groovy.io.FileType
|
||||
import org.yaml.snakeyaml.Yaml
|
||||
import org.codehaus.groovy.control.CompilerConfiguration
|
||||
import com.sap.piper.GenerateDocumentation
|
||||
import com.sap.piper.DefaultValueCache
|
||||
import java.util.regex.Matcher
|
||||
import groovy.text.StreamingTemplateEngine
|
||||
|
||||
//
|
||||
// Collects helper functions for rendering the docu
|
||||
//
|
||||
class TemplateHelper {
|
||||
|
||||
static replaceParagraph(def textIn, int level, name, replacement) {
|
||||
|
||||
boolean insideParagraph = false
|
||||
def textOut = ''
|
||||
|
||||
textIn.eachLine {
|
||||
|
||||
line ->
|
||||
|
||||
if(insideParagraph && line ==~ "^#{1,${level}} .*\$") {
|
||||
insideParagraph = false
|
||||
}
|
||||
|
||||
if(! insideParagraph) {
|
||||
textOut += "${line}\n"
|
||||
}
|
||||
|
||||
if(line ==~ "^#{${level}} ${name}.*\$") {
|
||||
insideParagraph = true
|
||||
textOut += "${replacement}\n\n"
|
||||
}
|
||||
}
|
||||
|
||||
textOut
|
||||
}
|
||||
|
||||
static createParametersTable(Map parameters) {
|
||||
|
||||
def t = ''
|
||||
@ -61,6 +35,10 @@ class TemplateHelper {
|
||||
t.trim()
|
||||
}
|
||||
|
||||
static createParametersSection(Map parameters) {
|
||||
createParametersTable(parameters) + '\n' + createParameterDescriptionSection(parameters)
|
||||
}
|
||||
|
||||
static createStepConfigurationSection(Map parameters) {
|
||||
|
||||
def t = '''|We recommend to define values of step parameters via [config.yml file](../configuration.md).
|
||||
@ -332,7 +310,7 @@ class Helper {
|
||||
|
||||
stepsDir.traverse(type: FileType.FILES, maxDepth: 0) {
|
||||
if(it.getName().endsWith('.groovy')) {
|
||||
def scriptName = (it =~ /vars\/(.*)\.groovy/)[0][1]
|
||||
def scriptName = (it =~ /vars\${File.separator}(.*)\.groovy/)[0][1]
|
||||
def stepScript = gse.createScript("${scriptName}.groovy", new Binding())
|
||||
for (def method in stepScript.getClass().getMethods()) {
|
||||
if(method.getName() == 'call' && method.getAnnotation(GenerateDocumentation) != null) {
|
||||
@ -457,20 +435,15 @@ void renderStep(stepName, stepProperties) {
|
||||
return
|
||||
}
|
||||
|
||||
def text = theStepDocu.text
|
||||
if(stepProperties.description) {
|
||||
text = TemplateHelper.replaceParagraph(text, 2, 'Description', '\n' + stepProperties.description)
|
||||
}
|
||||
if(stepProperties.parameters) {
|
||||
def binding = [
|
||||
docGenStepName : stepName,
|
||||
docGenDescription : 'Description\n\n' + stepProperties.description,
|
||||
docGenParameters : 'Parameters\n\n' + TemplateHelper.createParametersSection(stepProperties.parameters),
|
||||
docGenConfiguration : 'Step configuration\n\n' + TemplateHelper.createStepConfigurationSection(stepProperties.parameters)
|
||||
]
|
||||
def template = new StreamingTemplateEngine().createTemplate(theStepDocu.text)
|
||||
String text = template.make(binding)
|
||||
|
||||
text = TemplateHelper.replaceParagraph(text, 2, 'Parameters', '\n' +
|
||||
TemplateHelper.createParametersTable(stepProperties.parameters) + '\n' +
|
||||
TemplateHelper.createParameterDescriptionSection(stepProperties.parameters))
|
||||
|
||||
|
||||
text = TemplateHelper.replaceParagraph(text, 2, 'Step configuration', '\n' +
|
||||
TemplateHelper.createStepConfigurationSection(stepProperties.parameters))
|
||||
}
|
||||
theStepDocu.withWriter { w -> w.write text }
|
||||
}
|
||||
|
||||
|
@ -1,20 +1,14 @@
|
||||
# checkChangeInDevelopment
|
||||
# ${docGenStepName}
|
||||
|
||||
## Description
|
||||
|
||||
Content here is generated from corresponnding step, see `vars`.
|
||||
## ${docGenDescription}
|
||||
|
||||
## Prerequisites
|
||||
|
||||
* **[Change Management Client 2.0.0 or compatible version](http://central.maven.org/maven2/com/sap/devops/cmclient/dist.cli/)** - available for download on Maven Central.
|
||||
|
||||
## Parameters
|
||||
## ${docGenParameters}
|
||||
|
||||
Content here is generated from corresponnding step, see `vars`.
|
||||
|
||||
## Step configuration
|
||||
|
||||
Content here is generated from corresponnding step, see `vars`.
|
||||
## ${docGenConfiguration}
|
||||
|
||||
## Exceptions
|
||||
|
||||
|
@ -1,20 +1,14 @@
|
||||
# dockerExecute
|
||||
# ${docGenStepName}
|
||||
|
||||
## Description
|
||||
## ${docGenDescription}
|
||||
|
||||
Content here is generated from corresponnding step, see `vars`.
|
||||
|
||||
## Parameters
|
||||
|
||||
Content here is generated from corresponnding step, see `vars`.
|
||||
## ${docGenParameters}
|
||||
|
||||
## Kubernetes support
|
||||
|
||||
If the Jenkins is setup on a Kubernetes cluster, then you can execute the closure inside a container of a pod by setting an environment variable `ON_K8S` to `true`. However, it will ignore `containerPortMappings`, `dockerOptions` and `dockerVolumeBind` values.
|
||||
|
||||
## Step configuration
|
||||
|
||||
Content here is generated from corresponnding step, see `vars`.
|
||||
## ${docGenConfiguration}
|
||||
|
||||
## Side effects
|
||||
|
||||
|
@ -1,8 +1,6 @@
|
||||
# dockerExecuteOnKubernetes
|
||||
# ${docGenStepName}
|
||||
|
||||
## Description
|
||||
|
||||
Content here is generated from corresponnding step, see `vars`.
|
||||
## ${docGenDescription}
|
||||
|
||||
## Prerequisites
|
||||
|
||||
@ -11,13 +9,9 @@ Content here is generated from corresponnding step, see `vars`.
|
||||
|
||||
![Jenkins environment variable configuration](../images/k8s_env.png)
|
||||
|
||||
## Parameters
|
||||
## ${docGenParameters}
|
||||
|
||||
Content here is generated from corresponnding step, see `vars`.
|
||||
|
||||
## Step configuration
|
||||
|
||||
Content here is generated from corresponnding step, see `vars`.
|
||||
## ${docGenConfiguration}
|
||||
|
||||
## Side effects
|
||||
|
||||
|
@ -1,18 +1,12 @@
|
||||
# uiVeri5ExecuteTests
|
||||
# ${docGenStepName}
|
||||
|
||||
## Description
|
||||
|
||||
Content here is generated from corresponnding step, see `vars`.
|
||||
## ${docGenDescription}
|
||||
|
||||
## Prerequisites
|
||||
|
||||
## Parameters
|
||||
## ${docGenParameters}
|
||||
|
||||
Content here is generated from corresponnding step, see `vars`.
|
||||
|
||||
## Step configuration
|
||||
|
||||
Content here is generated from corresponnding step, see `vars`.
|
||||
## ${docGenConfiguration}
|
||||
|
||||
## Exceptions
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user