Ignore dead ocaml-* packages.
[goaljobs-goals.git] / libguestfs_upstream.ml
1 (* This goal script is responsible for:
2  *  - testing each new commit to the libguestfs source repo
3  *  - checking for new upstream releases of libguestfs
4  *  - testing new upstream releases
5  *  - packaging them as a source tarball
6  *  - testing the source tarball on a variety of systems
7  *  - if all the above works, uploading the external website
8  * Note this doesn't build the Fedora releases.  See 'libguestfs_fedora.ml'.
9  *)
10
11 open Goaljobs
12 open Printf
13 open Config
14 open Libguestfs
15
16 (* Enable debugging. *)
17 let () =
18   Unix.putenv "LIBGUESTFS_DEBUG" "1";
19   Unix.putenv "LIBGUESTFS_TRACE" "1"
20
21 (* Log program output. *)
22 let from = "rjones@redhat.com"
23 let to_ = "rjones@redhat.com"
24 (*
25 let logfile = log_program_output ()
26 let () = eprintf "logging to %s\n%!" logfile
27 *)
28
29 let package = "libguestfs"
30
31 (* Goal: the website has been updated to 'version'. *)
32 let rec goal website_updated version =
33   target (url_exists version.url &&
34             (if version.is_stable then
35                url_exists version.python_url
36              else true)
37          );
38
39   require (tarball_created version);
40   require (tarball_tested version);
41
42   (* Python sdists only generated for stable releases. *)
43   if version.is_stable then (
44     require (python_tarball_created version);
45     require (python_tarball_tested version)
46   );
47
48   (* We only update the website for the development releases. *)
49   if not version.is_stable then
50     require (website_built version);
51
52   require (website_checked_in version);
53   if version.is_stable then
54     require (python_website_checked_in version);
55   require (website_rsync_done version)
56
57 (* Goal: website has been rsync'd. *)
58 and website_rsync_done version =
59   target (url_contains_string "http://libguestfs.org" version.version &&
60           url_exists version.url);
61
62   sh "
63     cd %s
64     ./.rsync
65   " libguestfs_website_repo
66
67 (* Goal: Tarball added to repository and checked in. *)
68 and website_checked_in version =
69   let key = sprintf "libguestfs_website_checked_in_%s" version.version in
70   target (memory_exists key);
71   onrun (fun () -> memory_set key "1");
72
73   require (tarball_created version);
74   require (tarball_tested version);
75
76   sh "
77     cd %s
78     cp %s/tarballs/%s %s
79     git add %s
80     git add *.txt *.html
81     git commit -m \"Version %s\"
82   " libguestfs_website_repo
83     buildtmp version.tarball version.urlpath
84     version.urlpath
85     version.version
86
87 (* Goal: website (local copy) has been built. *)
88 and website_built version =
89   let index_file = sprintf "%s/index.html" libguestfs_website_repo in
90   target (file_contains_string index_file version.version);
91
92   require (tarball_created version);
93   require (tarball_tested version);
94
95   (* We should only update the website on development releases. *)
96   assert (not version.is_stable);
97
98   sh "
99     tar zxf %s/tarballs/%s
100     cd %s
101
102     echo %s > localconfigure
103     chmod +x localconfigure
104     echo %s > localenv
105
106     ./localconfigure
107     make V=1
108     make maintainer-upload-website WEBSITEDIR=%s
109   " buildtmp version.tarball
110     version.package_version
111     (quote (libguestfs_localconfigure `Tarball))
112     (quote (libguestfs_localenv (supermin version)))
113     (quote libguestfs_website_repo)
114
115 (* Goal: the tarball has passed the required set of tests before
116  * a release is allowed.
117  *)
118 and tarball_tested version =
119   let key = sprintf "libguestfs_tarball_tested_%s" version.version in
120   target (memory_exists key);
121   onrun (fun () -> memory_set key "1");
122
123   require (tarball_created version);
124
125   sh "
126     tar zxf %s/tarballs/%s
127     cd %s
128
129     echo %s > localconfigure
130     chmod +x localconfigure
131     echo %s > localenv
132
133     ./localconfigure
134     make V=1
135     make check-release
136   " buildtmp version.tarball
137     version.package_version
138     (quote (libguestfs_localconfigure `Tarball))
139     (quote (libguestfs_localenv (supermin version)))
140
141 (* Goal: the tarball has been created from git. *)
142 and tarball_created version =
143   let filename = sprintf "%s/tarballs/%s" buildtmp version.tarball in
144   target (file_exists filename);
145
146   require (repo_up_to_date version.branch);
147
148   let repodir = sprintf "%s/repos/%s-%s" buildtmp package version.branch in
149
150   (* Branches <= 1.32 are tagged with "1.32.11",
151    * branches >= 1.33 are tagged with "v1.33.11".
152    *)
153   let version_tag =
154     if version.minor >= 33 then "v" ^ version.version
155     else version.version in
156
157   sh "
158     cp -a %s libguestfs
159     cd libguestfs
160     git reset --hard %s
161
162     echo %s > localconfigure
163     chmod +x localconfigure
164     echo %s > localenv
165
166     ./localconfigure
167
168     # Ensure the po-docs are updated.  Grrr this is ugly ...
169     make ||:
170     rm po-docs/podfiles
171     make -C po-docs update-po
172
173     make V=1
174     make dist
175
176     # Ensure redhat hardening flags didn't leak into the tarball.
177     # https://bugzilla.redhat.com/show_bug.cgi?id=1214506
178     if zcat %s | grep -q redhat-hardened; then exit 1; fi
179
180     mv %s %s/tarballs/%s
181   " repodir
182     version_tag
183     (quote (libguestfs_localconfigure `Git))
184     (quote (libguestfs_localenv (supermin version)))
185     version.tarball
186     version.tarball buildtmp version.tarball
187
188 (* Goal: test a commit. *)
189 and commit_tested branch commit =
190   onfail (
191     fun _ ->
192       let subject = sprintf "goal: %s: FAILED" goalname in
193       mailto ~from ~subject (*~attach:[logfile]*) to_
194   );
195
196   let key = sprintf "libguestfs_commit_tested_%s" commit in
197   target (memory_exists key);
198   onrun (fun () -> memory_set key "1");
199
200   require (repo_up_to_date branch);
201
202   let repodir = sprintf "%s/repos/%s-%s" buildtmp package branch in
203
204   sh "
205     cp -a %s libguestfs
206     cd libguestfs
207     git reset --hard %s
208
209     echo %s > localconfigure
210     chmod +x localconfigure
211     echo %s > localenv
212
213     ./localconfigure
214     make V=1
215     make check-release
216   " repodir
217     commit
218     (quote (libguestfs_localconfigure `Git))
219     (quote (libguestfs_localenv None))
220
221 and repo_up_to_date branch =
222   git_force branch
223
224 (* Goals for Python sdists. *)
225 and python_website_checked_in version =
226   let key = sprintf "libguestfs_python_website_checked_in_%s" version.version in
227   target (memory_exists key);
228   onrun (fun () -> memory_set key "1");
229
230   require (python_tarball_created version);
231   require (python_tarball_tested version);
232
233   sh "
234     cd %s
235     cp %s/tarballs/%s %s
236     git add %s
237     git commit -m \"Python sdist version %s\"
238   " libguestfs_website_repo
239     buildtmp version.python_tarball version.python_urlpath
240     version.python_urlpath
241     version.version
242
243 and python_tarball_tested version =
244   let key = sprintf "libguestfs_python_tarball_tested_%s" version.version in
245   target (memory_exists key);
246   onrun (fun () -> memory_set key "1");
247
248   require (python_tarball_created version);
249
250   sh "
251     virtualenv venv
252     source ./venv/bin/activate
253     pip install %s/tarballs/%s
254   " buildtmp version.python_tarball
255
256 and python_tarball_created version =
257   let filename = sprintf "%s/tarballs/%s" buildtmp version.python_tarball in
258   target (file_exists filename);
259
260   require (tarball_created version);
261
262   sh "
263     tar zxf %s/tarballs/%s
264     cd %s
265
266     echo %s > localconfigure
267     chmod +x localconfigure
268     echo %s > localenv
269
270     ./localconfigure
271     make V=1
272     make -C python sdist
273     cp python/dist/%s %s
274   " buildtmp version.tarball
275     version.package_version
276     (quote (libguestfs_localconfigure `Tarball))
277     (quote (libguestfs_localenv (supermin version)))
278     version.python_tarball filename
279
280 let () =
281   (* Add a periodic job to check for new git commits and test them. *)
282   every libguestfs_query_mins minutes ~name:"new libguestfs commit" (
283     fun () ->
284       require (repo_up_to_date "master");
285       let commit = git_latest_commit "master" in
286       require (commit_tested "master" commit);
287   );
288
289   (* Periodic job to build new tarballs. *)
290   every libguestfs_query_mins minutes ~name:"new libguestfs version" (
291     fun () ->
292       require (repo_up_to_date "master");
293       let version = git_latest_version "master" in
294       require (website_updated version)
295   )
296
297 (* Allow these jobs to run from the command line. *)
298 let () =
299   publish "commit" (
300     function
301     | [commit] -> require (commit_tested "master" commit)
302     | [branch; commit] -> require (commit_tested branch commit)
303     | _ ->
304       failwith "use './libguestfs_upstream commit [<branch>] <commit>'"
305   );
306   publish "release" (
307     function
308     | [version] -> require (website_updated (vernames version))
309     | _ ->
310       failwith "use './libguestfs_upstream release <version>'"
311   )