f24 & f25 are now (or nearly) dead.
[goaljobs-goals.git] / libguestfs_fedora.ml
1 (* Handle Fedora builds of libguestfs. *)
2
3 open Goaljobs
4
5 open Printf
6
7 open Config
8 open Fedora
9 open Git
10 open Libguestfs
11
12 (* Enable debugging. *)
13 let () =
14   Unix.putenv "LIBGUESTFS_DEBUG" "1";
15   Unix.putenv "LIBGUESTFS_TRACE" "1"
16
17 (* Log program output. *)
18 let from = "rjones@redhat.com"
19 let to_ = "rjones@redhat.com"
20
21 let package = "libguestfs"
22
23 (* How branches in libguestfs upstream map to branches in Fedora. *)
24 let branches = [
25   "1.37-development", "master";    (* Rawhide follows development. *)
26   "1.37-development", "f27";       (* F27 follows development. *)
27   "1.36-stable", "f26";            (* F26 follows 1.36. *)
28 ]
29
30 (* Goal: Latest website version has been built in every branch. *)
31 let rec goal all () =
32   List.iter (
33     fun (wbranch, fbranch) ->
34       match website_latest_version wbranch with
35       | None -> ()
36       | Some version ->
37         require (fedora_built version fbranch)
38   ) branches
39
40 (* Goal: Fedora has a successful build of 'version' on 'branch'. *)
41 and fedora_built version branch =
42   let specfile = fedora_specfile package branch in
43
44   target (file_contains_string specfile version.version &&
45             match koji_build_state (fedora_verrel package branch) with
46             | `Complete | `Building -> true
47             | _ -> false);
48
49   require (sources_uploaded version branch);
50   require (specfile_pushed version branch);
51
52   koji_build ~wait:true package branch
53
54 and sources_uploaded version branch =
55   let repodir = fedora_repo package branch in
56   let sources = repodir // "sources" in
57   let key = sprintf "libguestfs_fedora_sources_uploaded_%s" version.version in
58
59   target (file_contains_string sources version.version &&
60             memory_exists key);
61   onrun (fun () -> memory_set key "1");
62
63   require (repodir_up_to_date repodir);
64
65   sh "
66     cd %s
67     fedpkg new-sources %s/%s
68   " repodir libguestfs_download_repo version.urlpath
69
70 and specfile_updated version branch =
71   let repodir = fedora_repo package branch in
72   let specfile = fedora_specfile package branch in
73
74   target (file_contains_string specfile version.version);
75
76   require (repodir_up_to_date repodir);
77
78   (* Hairy specfile editing. *)
79   sh "
80     cd %s
81     email=\"Richard W.M. Jones <rjones@redhat.com>\"
82     date=`date +\"%%a %%b %%d %%Y\"`
83     cp libguestfs.spec libguestfs.spec.old
84     sed < libguestfs.spec.old \\
85     -e \"s/^Version:.*/Version:       %s/\" \\
86     -e \"s/^Release:.*/Release:       1%%{?dist}/\" \\
87     -e \"/^%%changelog/a \\
88 * $date $email - 1:%s-1\\\\n\\
89 - New upstream version %s.\\\\n\\
90 \" > libguestfs.spec
91     rm libguestfs.spec.old
92   " repodir version.version version.version version.version
93
94 and specfile_committed version branch =
95   let repodir = fedora_repo package branch in
96   let key = sprintf "libguestfs_fedora_specfile_committed_%s_%s"
97     branch version.version in
98
99   target (memory_exists key);
100   onrun (fun () -> memory_set key "1");
101
102   require (specfile_updated version branch);
103
104   sh "
105     cd %s
106     fedpkg commit -c
107   " repodir
108
109 and specfile_pushed version branch =
110   let repodir = fedora_repo package branch in
111   let key =
112     sprintf "libguestfs_fedora_specfile_pushed_%s_%s" branch version.version in
113
114   target (memory_exists key);
115   onrun (fun () -> memory_set key "1");
116
117   require (repodir_up_to_date repodir);
118   require (specfile_committed version branch);
119
120   sh "
121     cd %s
122     fedpkg push
123   " repodir
124
125 and repodir_up_to_date repodir =
126   sh "
127     cd %s
128     git fetch
129   " repodir;
130   if not (git_has_local_changes repodir) then
131     sh "
132       cd %s
133       git pull --rebase
134     " repodir