Skip to content

Commit

Permalink
PipelineGenerator.getBuildableMatrixAxes uses MultiplatformGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
samrocketman committed Jul 29, 2023
1 parent ac1de3b commit cce1a39
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 42 deletions.
47 changes: 9 additions & 38 deletions src/main/groovy/net/gleske/jervis/lang/PipelineGenerator.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -303,40 +303,7 @@ pipeline_generator.stashMap['html']['includes']
the YAML configuration.
*/
List getBuildableMatrixAxes() {
// TODO move code to platformGenerator.getBuildableMatrixAxes()
// - Should include platformGenerator 'platform' and 'os'.
// - Implement platformGenerator.getYamlMatrixAxes from the collection
// of LifecycleGenerator objects.
List matrix_axis_maps = generator.yaml_matrix_axes.collect { axis ->
generator.matrixGetAxisValue(axis).split().collect {
[(axis): it]
}
}
if(generator.yaml_matrix_axes.size() < 2) {
matrix_axis_maps = matrix_axis_maps[0]
}
else {
// - Creates a list of lists which contain maps to be summed into
// one list of maps with every possible matrix combination.
// - Create a groovy cartesian product of the maps and then sum
// each list of maps together
matrix_axis_maps = matrix_axis_maps.combinations()*.sum()
}
//return all maps (or some maps allowed via filter)
matrix_axis_maps.findAll {
if(generator.matrixExcludeFilter()) {
Binding binding = new Binding()
it.each { k, v ->
binding.setVariable(k, v)
}
//filter out the combinations (returns a boolean true or false)
new GroovyShell(binding).evaluate(generator.matrixExcludeFilter())
}
else {
//if there's no matrix exclude filter then include everything
true
}
}
this.platformGenerator.getBuildableMatrixAxes()
}

/**
Expand Down Expand Up @@ -403,9 +370,15 @@ pipeline_generator.stashMap['html']['includes']
Convert a matrix axis to use unfriendly names for stash comparison.
*/
private Map convertMatrixAxis(Map matrix_axis) {
String platform = matrix_axis.platform ?: this.platformGenerator.defaultPlatform
String os = matrix_axis.os ?: this.platformGenerator.defaultOS
Map new_axis = [:]
matrix_axis.each { k, v ->
new_axis[k] = (generator.matrix_fullName_by_friendly[v]?:v) - ~/^${k}:/
if(k in ['os', 'platform']) {
new_axis[k] = v
return
}
new_axis[k] = (this.platformGenerator.platform_generators[platform][os].matrix_fullName_by_friendly[v]?:v) - ~/^${k}:/
}
new_axis
}
Expand All @@ -421,11 +394,9 @@ pipeline_generator.stashMap['html']['includes']
the Jenkins job. Used by <tt>withEnvSecretWrapper()</tt> method.
*/
List getSecretPairsEnv() {
// TODO platformGenerator.generator.plainmap secrets can be pulled from
// default generator.
List<Map> secretPairs = []
List<String> secretEnv = []
generator.plainmap.each { k, v ->
getGenerator().plainmap.each { k, v ->
secretPairs << [var: k, password: v]
secretEnv << "${k}=${v}"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ class PipelineGeneratorTest extends GroovyTestCase {
@Test public void test_PipelineGenerator_getBuildableMatrixAxes_matrix() {
generator.loadYamlString('language: java\nenv: ["world=hello", "world=goodby"]\njdk:\n - openjdk6\n - openjdk7')
def pipeline_generator = new PipelineGenerator(generator)
assert pipeline_generator.getBuildableMatrixAxes() == [[env:'env0', jdk:'jdk0'], [env:'env1', jdk:'jdk0'], [env:'env0', jdk:'jdk1'], [env:'env1', jdk:'jdk1']]
assert pipeline_generator.getBuildableMatrixAxes() == [[platform: 'none', os: 'none', env:'env0', jdk:'jdk0'], [platform: 'none', os: 'none', env:'env1', jdk:'jdk0'], [platform: 'none', os: 'none', env:'env0', jdk:'jdk1'], [platform: 'none', os: 'none', env:'env1', jdk:'jdk1']]
//account for matrix include axes
generator.loadYamlString('language: java\nenv: ["world=hello", "world=goodbye"]\njdk:\n - openjdk6\n - openjdk7\nmatrix:\n include:\n - {env: "world=hello", jdk: openjdk6}\n - {env: "world=goodbye", jdk: openjdk7}')
pipeline_generator = new PipelineGenerator(generator)
assert pipeline_generator.getBuildableMatrixAxes() == [[env:'env0', jdk:'jdk0'], [env:'env1', jdk:'jdk1']]
assert pipeline_generator.getBuildableMatrixAxes() == [[platform: 'none', os: 'none', env:'env0', jdk:'jdk0'], [platform: 'none', os: 'none', env:'env1', jdk:'jdk1']]
//account for inverse matrix exclude axes
generator.loadYamlString('language: java\nenv: ["world=hello", "world=goodbye"]\njdk:\n - openjdk6\n - openjdk7\nmatrix:\n exclude:\n - {env: "world=hello", jdk: openjdk6}\n - {env: "world=goodbye", jdk: openjdk7}')
pipeline_generator = new PipelineGenerator(generator)
assert pipeline_generator.getBuildableMatrixAxes() == [[env:'env1', jdk:'jdk0'], [env:'env0', jdk:'jdk1']]
assert pipeline_generator.getBuildableMatrixAxes() == [[platform: 'none', os: 'none', env:'env1', jdk:'jdk0'], [platform: 'none', os: 'none', env:'env0', jdk:'jdk1']]
}
@Test public void test_PipelineGenerator_getBuildableMatrixAxes_nonmatrix() {
generator.loadYamlString('language: java\nenv: "world=hello"\njdk:\n - openjdk6')
Expand Down Expand Up @@ -1510,7 +1510,7 @@ class PipelineGeneratorTest extends GroovyTestCase {
""".stripMargin().trim()
generator.loadYamlString(yaml)
def pipeline_generator = new PipelineGenerator(generator)
List result = [['python':'python0', 'jdk':'jdk0'], ['python':'python1', 'jdk':'jdk0'], ['python':'python0', 'jdk':'jdk1'], ['python':'python1', 'jdk':'jdk1']]
List result = [[platform: 'none', os: 'none', 'python':'python0', 'jdk':'jdk0'], [platform: 'none', os: 'none', 'python':'python1', 'jdk':'jdk0'], [platform: 'none', os: 'none', 'python':'python0', 'jdk':'jdk1'], [platform: 'none', os: 'none', 'python':'python1', 'jdk':'jdk1']]
assert pipeline_generator.getBuildableMatrixAxes() == result
}
@Test public void test_PipelineGenerator_getYaml() {
Expand Down

0 comments on commit cce1a39

Please sign in to comment.