summaryrefslogtreecommitdiff
path: root/examples/scala-js/ci/scalajs-matrix-build.groovy
blob: f2a661a016b8a2a81f80ece8bce2fc9ef04d8d10 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
out.println("Trying to run matrix ${params.matrix}")

out.println("Loading ci/matrix.xml")

def matrixFile = build.properties.moduleRoot.child("ci/matrix.xml")
def fact = javax.xml.parsers.DocumentBuilderFactory.newInstance()
def builder = fact.newDocumentBuilder()

ciMatrix = builder.parse(matrixFile.read())

out.println("Loading relevant definitions")

buildDefs = []

fetchMatrix(params.matrix)

def fetchMatrix(matrixName) {
  def matrix = ciMatrix.getElementById(matrixName)
  def list = matrix.getElementsByTagName("run")
  for (int i = 0; i < list.getLength(); ++i) {
    handleRun(list.item(i))
  }
}

def handleRun(run) {
  def attrs = run.getAttributes()
  def matrixAttr = attrs.getNamedItem("matrix")
  def taskAttr = attrs.getNamedItem("task")
  if (matrixAttr != null)
    fetchMatrix(matrixAttr.getValue())
  else if (taskAttr != null)
    fetchTask(taskAttr.getValue(), run)
}

def fetchTask(taskName, runElem) {
  def taskElem = ciMatrix.getElementById(taskName)
  def taskStr = taskElem.getTextContent()
  def fullTaskName = taskName

  runElem.getElementsByTagName("v").each { v ->
    def name = v.getAttribute("n")
    def value = v.getTextContent()
    taskStr = taskStr.replace('$' + name, value)
    fullTaskName += " $name=$value"
  }

  out.println("Found task: $fullTaskName")

  buildDefs.add({
    build("scalajs-task-worker",
      refspec: params.refspec,
      sha1: params.sha1,
      taskCommand: taskStr)
  })
}

parallel(buildDefs)