-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathci_notify.scala
76 lines (61 loc) · 2.34 KB
/
ci_notify.scala
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* Author: Fabian Huch, TU Muenchen
Build job to trigger ci pipelines.
*/
package isabelle.tools_collection
import isabelle.*
import java.net.{HttpURLConnection, URL}
import java.io.{BufferedReader, IOException, InputStreamReader, OutputStreamWriter}
object CI_Notify {
def post(url: URL, params: Map[String, String], body: String): String =
try {
val conn = url.openConnection().asInstanceOf[HttpURLConnection]
conn.setRequestMethod("POST")
conn.setDoOutput(true)
params.foreach { case (param, value) => conn.setRequestProperty(param, value) }
val writer = new OutputStreamWriter(conn.getOutputStream)
writer.write(body)
writer.flush()
File.read_stream(conn.getInputStream)
} catch {
case _: IOException => error("Could not read from " + url.toString)
}
def dispatch(options: Options): CI_Build.Result = {
try {
// linter (github action)
post(
new URL("https://api.github.com/repos/isabelle-prover/isabelle-linter/dispatches"),
Map(
"Accept" -> "application/vnd.github+json",
"Authorization" -> ("Bearer " + options.string("ci_github_dispatch_token"))),
"{\"event_type\":\"isabelle-update\"}")
// context build (github action)
post(
new URL("https://api.github.com/repos/isabelle-prover/isabelle-context-build/dispatches"),
Map(
"Accept" -> "application/vnd.github+json",
"Authorization" -> ("Bearer " + options.string("ci_github_dispatch_token"))),
"{\"event_type\":\"isabelle-update\"}")
// findfacts
post(
new URL("https://api.github.com/repos/Dacit/findfacts/dispatches"),
Map(
"Accept" -> "application/vnd.github+json",
"Authorization" -> ("Bearer " + options.string("ci_github_dispatch_token"))),
"{\"event_type\":\"isabelle-update\"}")
// new tools here
CI_Build.Result.ok
} catch {
case ERROR(msg) =>
println("POST request failed: " + quote(msg))
CI_Build.Result.error
}
}
val ci_notify = CI_Build.Job(
"notify", "notifies external ci pipelines",
CI_Build.Local("notify", 1, 1, false),
CI_Build.Build_Config(
documents = false, clean = false, post_hook = (_, options, _) => dispatch(options))
)
}
class CI_Builds extends Isabelle_CI_Builds(
CI_Notify.ci_notify)