Commit | Line | Data |
---|---|---|
b3517f3f | 1 | ;;; GNU Guix --- Functional package management for GNU |
2c33901f | 2 | ;;; Copyright © 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org> |
b3517f3f LC |
3 | ;;; |
4 | ;;; This file is part of GNU Guix. | |
5 | ;;; | |
6 | ;;; GNU Guix is free software; you can redistribute it and/or modify it | |
7 | ;;; under the terms of the GNU General Public License as published by | |
8 | ;;; the Free Software Foundation; either version 3 of the License, or (at | |
9 | ;;; your option) any later version. | |
10 | ;;; | |
11 | ;;; GNU Guix is distributed in the hope that it will be useful, but | |
12 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | ;;; GNU General Public License for more details. | |
15 | ;;; | |
16 | ;;; You should have received a copy of the GNU General Public License | |
17 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. | |
18 | ||
19 | (define-module (guix ci) | |
20 | #:use-module (guix http-client) | |
a85a74ce LC |
21 | #:use-module (guix json) |
22 | #:use-module (json) | |
a3b72a8f | 23 | #:use-module (srfi srfi-1) |
a85a74ce | 24 | #:use-module (ice-9 match) |
b3517f3f LC |
25 | #:export (build? |
26 | build-id | |
27 | build-derivation | |
28 | build-system | |
29 | build-status | |
30 | build-timestamp | |
31 | ||
a3b72a8f LC |
32 | checkout? |
33 | checkout-commit | |
34 | checkout-input | |
35 | ||
36 | evaluation? | |
37 | evaluation-id | |
38 | evaluation-spec | |
39 | evaluation-complete? | |
40 | evaluation-checkouts | |
41 | ||
b3517f3f LC |
42 | %query-limit |
43 | queued-builds | |
a3b72a8f LC |
44 | latest-builds |
45 | latest-evaluations | |
a85a74ce | 46 | evaluations-for-commit)) |
b3517f3f LC |
47 | |
48 | ;;; Commentary: | |
49 | ;;; | |
50 | ;;; This module provides a client to the HTTP interface of the Hydra and | |
51 | ;;; Cuirass continuous integration (CI) tools. | |
52 | ;;; | |
53 | ;;; Code: | |
54 | ||
a85a74ce LC |
55 | (define-json-mapping <build> make-build build? |
56 | json->build | |
57 | (id build-id "id") ;integer | |
b3517f3f LC |
58 | (derivation build-derivation) ;string | #f |
59 | (system build-system) ;string | |
a85a74ce | 60 | (status build-status "buildstatus" ) ;integer |
b3517f3f LC |
61 | (timestamp build-timestamp)) ;integer |
62 | ||
a85a74ce LC |
63 | (define-json-mapping <checkout> make-checkout checkout? |
64 | json->checkout | |
a3b72a8f LC |
65 | (commit checkout-commit) ;string (SHA1) |
66 | (input checkout-input)) ;string (name) | |
67 | ||
a85a74ce LC |
68 | (define-json-mapping <evaluation> make-evaluation evaluation? |
69 | json->evaluation | |
a3b72a8f | 70 | (id evaluation-id) ;integer |
2c33901f | 71 | (spec evaluation-spec "specification") ;string |
a85a74ce LC |
72 | (complete? evaluation-complete? "in-progress" |
73 | (match-lambda | |
74 | (0 #t) | |
75 | (_ #f))) ;Boolean | |
76 | (checkouts evaluation-checkouts "checkouts" ;<checkout>* | |
77 | (lambda (checkouts) | |
78 | (map json->checkout | |
79 | (vector->list checkouts))))) | |
a3b72a8f | 80 | |
b3517f3f LC |
81 | (define %query-limit |
82 | ;; Max number of builds requested in queries. | |
83 | 1000) | |
84 | ||
85 | (define (json-fetch url) | |
86 | (let* ((port (http-fetch url)) | |
87 | (json (json->scm port))) | |
88 | (close-port port) | |
89 | json)) | |
90 | ||
b3517f3f LC |
91 | (define* (queued-builds url #:optional (limit %query-limit)) |
92 | "Return the list of queued derivations on URL." | |
93 | (let ((queue (json-fetch (string-append url "/api/queue?nr=" | |
94 | (number->string limit))))) | |
a85a74ce | 95 | (map json->build (vector->list queue)))) |
b3517f3f | 96 | |
a3b72a8f LC |
97 | (define* (latest-builds url #:optional (limit %query-limit) |
98 | #:key evaluation system) | |
99 | "Return the latest builds performed by the CI server at URL. If EVALUATION | |
100 | is an integer, restrict to builds of EVALUATION. If SYSTEM is true (a system | |
101 | string such as \"x86_64-linux\"), restrict to builds for SYSTEM." | |
102 | (define* (option name value #:optional (->string identity)) | |
103 | (if value | |
104 | (string-append "&" name "=" (->string value)) | |
105 | "")) | |
106 | ||
b3517f3f | 107 | (let ((latest (json-fetch (string-append url "/api/latestbuilds?nr=" |
a3b72a8f LC |
108 | (number->string limit) |
109 | (option "evaluation" evaluation | |
110 | number->string) | |
111 | (option "system" system))))) | |
b3517f3f LC |
112 | ;; Note: Hydra does not provide a "derivation" field for entries in |
113 | ;; 'latestbuilds', but Cuirass does. | |
a85a74ce | 114 | (map json->build (vector->list latest)))) |
a3b72a8f LC |
115 | |
116 | (define* (latest-evaluations url #:optional (limit %query-limit)) | |
117 | "Return the latest evaluations performed by the CI server at URL." | |
118 | (map json->evaluation | |
a85a74ce LC |
119 | (vector->list |
120 | (json->scm | |
121 | (http-fetch (string-append url "/api/evaluations?nr=" | |
122 | (number->string limit))))))) | |
a3b72a8f LC |
123 | |
124 | ||
125 | (define* (evaluations-for-commit url commit #:optional (limit %query-limit)) | |
126 | "Return the evaluations among the latest LIMIT evaluations that have COMMIT | |
127 | as one of their inputs." | |
128 | (filter (lambda (evaluation) | |
129 | (find (lambda (checkout) | |
130 | (string=? (checkout-commit checkout) commit)) | |
131 | (evaluation-checkouts evaluation))) | |
132 | (latest-evaluations url limit))) |