diff --git a/documentation/bin/createDocu.groovy b/documentation/bin/createDocu.groovy index ee8516417..a5fb01830 100644 --- a/documentation/bin/createDocu.groovy +++ b/documentation/bin/createDocu.groovy @@ -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,18 +35,22 @@ 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). | |In following sections of the config.yml the configuration is possible:\n\n'''.stripMargin() - t += '| parameter | general | step | stage |\n' - t += '|-----------|---------|------|-------|\n' + t += '| parameter | general | step/stage |\n' + t += '|-----------|---------|------------|\n' parameters.keySet().toSorted().each { def props = parameters.get(it) - t += "| `${it}` | ${props.GENERAL_CONFIG ? 'X' : ''} | ${props.STEP_CONFIG ? 'X' : ''} | ${props.STAGE_CONFIG ? 'X' : ''} |\n" + t += "| `${it}` | ${props.GENERAL_CONFIG ? 'X' : ''} | ${props.STEP_CONFIG ? 'X' : ''} |\n" } t.trim() @@ -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 } } @@ -544,8 +517,7 @@ def handleStep(stepName, prepareDefaultValuesStep, gse) { required: true, GENERAL_CONFIG: false, - STEP_CONFIG: false, - STAGE_CONFIG: false + STEP_CONFIG: false ] // END special handling for 'script' parameter diff --git a/documentation/docs/steps/checkChangeInDevelopment.md b/documentation/docs/steps/checkChangeInDevelopment.md index b164dce27..a3e30d438 100644 --- a/documentation/docs/steps/checkChangeInDevelopment.md +++ b/documentation/docs/steps/checkChangeInDevelopment.md @@ -1,20 +1,14 @@ -# checkChangeInDevelopment +# ${docGenStepName} -## Description - -Content here is generated from corresponding 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 corresponding step, see `vars`. - -## Step configuration - -Content here is generated from corresponding step, see `vars`. +## ${docGenConfiguration} ## Exceptions diff --git a/documentation/docs/steps/dockerExecute.md b/documentation/docs/steps/dockerExecute.md index bb327eb1e..9ed77b9a4 100644 --- a/documentation/docs/steps/dockerExecute.md +++ b/documentation/docs/steps/dockerExecute.md @@ -1,20 +1,14 @@ -# dockerExecute +# ${docGenStepName} -## Description +## ${docGenDescription} -Content here is generated from corresponding step, see `vars`. - -## Parameters - -Content here is generated from corresponding 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 corresponding step, see `vars`. +## ${docGenConfiguration} ## Side effects diff --git a/documentation/docs/steps/dockerExecuteOnKubernetes.md b/documentation/docs/steps/dockerExecuteOnKubernetes.md index 013ce042a..0c0ac7460 100644 --- a/documentation/docs/steps/dockerExecuteOnKubernetes.md +++ b/documentation/docs/steps/dockerExecuteOnKubernetes.md @@ -1,8 +1,6 @@ -# dockerExecuteOnKubernetes +# ${docGenStepName} -## Description - -Content here is generated from corresponding step, see `vars`. +## ${docGenDescription} ## Prerequisites @@ -11,13 +9,9 @@ Content here is generated from corresponding step, see `vars`. ![Jenkins environment variable configuration](../images/k8s_env.png) -## Parameters +## ${docGenParameters} -Content here is generated from corresponding step, see `vars`. - -## Step configuration - -Content here is generated from corresponding step, see `vars`. +## ${docGenConfiguration} ## Side effects diff --git a/documentation/docs/steps/karmaExecuteTests.md b/documentation/docs/steps/karmaExecuteTests.md index ba7b16a55..f64a4a51b 100644 --- a/documentation/docs/steps/karmaExecuteTests.md +++ b/documentation/docs/steps/karmaExecuteTests.md @@ -1,21 +1,15 @@ -# karmaExecuteTests +# ${docGenStepName} -## Description - -Content here is generated from corresponnding step, see `vars`. +## ${docGenDescription} ## Prerequisites * **running Karma tests** - have a NPM module with running tests executed with Karma * **configured WebDriver** - have the [`karma-webdriver-launcher`](https://github.com/karma-runner/karma-webdriver-launcher) package installed and a custom, WebDriver-based browser configured in Karma -## 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 diff --git a/documentation/docs/steps/npmExecute.md b/documentation/docs/steps/npmExecute.md index 619cb9cb1..ba9384961 100644 --- a/documentation/docs/steps/npmExecute.md +++ b/documentation/docs/steps/npmExecute.md @@ -1,16 +1,12 @@ -# npmExecute -## Description +# ${docGenStepName} -Content here is generated from corresponding step, see `vars`. -## Parameters +## ${docGenDescription} -Content here is generated from corresponding step, see `vars`. +## ${docGenParameters} -## Step configuration - -Content here is generated from corresponding step, see `vars`. +## ${docGenConfiguration} ## Exceptions diff --git a/documentation/docs/steps/uiVeri5ExecuteTests.md b/documentation/docs/steps/uiVeri5ExecuteTests.md index 25fe24fa8..dbe191e95 100644 --- a/documentation/docs/steps/uiVeri5ExecuteTests.md +++ b/documentation/docs/steps/uiVeri5ExecuteTests.md @@ -1,18 +1,12 @@ -# uiVeri5ExecuteTests +# ${docGenStepName} -## Description - -Content here is generated from corresponding step, see `vars`. +## ${docGenDescription} ## Prerequisites -## Parameters +## ${docGenParameters} -Content here is generated from corresponding step, see `vars`. - -## Step configuration - -Content here is generated from corresponding step, see `vars`. +## ${docGenConfiguration} ## Exceptions diff --git a/test/groovy/CheckChangeInDevelopmentTest.groovy b/test/groovy/CheckChangeInDevelopmentTest.groovy index 424e47e5b..f7230fee1 100644 --- a/test/groovy/CheckChangeInDevelopmentTest.groovy +++ b/test/groovy/CheckChangeInDevelopmentTest.groovy @@ -4,7 +4,7 @@ import org.junit.Test import org.junit.rules.ExpectedException import org.junit.rules.RuleChain -import com.sap.piper.GitUtils +import com.sap.piper.cm.BackendType import com.sap.piper.cm.ChangeManagement import com.sap.piper.cm.ChangeManagementException @@ -155,6 +155,23 @@ class CheckChangeInDevelopmentTest extends BasePiperTest { } + @Test + public void stageConfigIsNotConsideredWithParamKeysTest() { + + nullScript.commonPipelineEnvironment.configuration = [stages:[foo:[changeDocumentId:'12345']]] + ChangeManagement cm = getChangeManagementUtils(true, '') + + thrown.expect(IllegalArgumentException) + thrown.expectMessage('No changeDocumentId provided.') + + stepRule.step.checkChangeInDevelopment( + script: nullScript, + cmUtils: cm, + changeManagement: [type: BackendType.SOLMAN, + endpoint: 'https://example.org/cm'], + stageName: 'foo') + } + private ChangeManagement getChangeManagementUtils(boolean inDevelopment, String changeDocumentId = '001') { return new ChangeManagement(nullScript, null) {