Reverse the order of Fedora builds so we build Rawhide first.
[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.29-development", "master";    (* Rawhide follows development. *)
26   "1.29-development", "f22";       (* F22 follows development (for now). *)
27   "1.28-stable", "f21";            (* F21 follows 1.28. *)
28   "1.26-stable", "f20";            (* F20 follows 1.26. *)
29 ]
30
31 (* Goal: Latest website version has been built in every branch. *)
32 let rec goal all () =
33   List.iter (
34     fun (wbranch, fbranch) ->
35       match website_latest_version wbranch with
36       | None -> ()
37       | Some version ->
38         require (fedora_built version fbranch)
39   ) branches
40
41 (* Goal: Fedora has a successful build of 'version' on 'branch'. *)
42 and fedora_built version branch =
43   let specfile = fedora_specfile package branch in
44
45   target (file_contains_string specfile version.version &&
46             match koji_build_state (fedora_verrel package branch) with
47             | `Complete | `Building -> true
48             | _ -> false);
49
50   require (sources_uploaded version branch);
51   require (specfile_pushed version branch);
52
53   koji_build ~wait:true package branch
54
55 and sources_uploaded version branch =
56   let repodir = fedora_repo package branch in
57   let sources = repodir // "sources" in
58   let key = sprintf "libguestfs_fedora_sources_uploaded_%s" version.version in
59
60   target (file_contains_string sources version.version &&
61             memory_exists key);
62   onrun (fun () -> memory_set key "1");
63
64   require (repodir_up_to_date repodir);
65
66   sh "
67     cd %s
68     fedpkg new-sources %s/%s
69   " repodir libguestfs_website_repo version.urlpath
70
71 and specfile_updated version branch =
72   let repodir = fedora_repo package branch in
73   let specfile = fedora_specfile package branch in
74
75   target (file_contains_string specfile version.version);
76
77   require (repodir_up_to_date repodir);
78
79   (* Hairy specfile editing. *)
80   sh "
81     cd %s
82     email=\"Richard W.M. Jones <rjones@redhat.com>\"
83     date=`date +\"%%a %%b %%d %%Y\"`
84     cp libguestfs.spec libguestfs.spec.old
85     sed < libguestfs.spec.old \\
86     -e \"s/^Version:.*/Version:       %s/\" \\
87     -e \"s/^Release:.*/Release:       1%%{?dist}/\" \\
88     -e \"/^%%changelog/a \\
89 * $date $email - 1:%s-1\\\\n\\
90 - New upstream version %s.\\\\n\\
91 \" > libguestfs.spec
92     rm libguestfs.spec.old
93   " repodir version.version version.version version.version
94
95 and specfile_committed version branch =
96   let repodir = fedora_repo package branch in
97   let key = sprintf "libguestfs_fedora_specfile_committed_%s" 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 = sprintf "libguestfs_fedora_specfile_pushed_%s" version.version in
112
113   target (memory_exists key);
114   onrun (fun () -> memory_set key "1");
115
116   require (repodir_up_to_date repodir);
117   require (specfile_committed version branch);
118
119   sh "
120     cd %s
121     fedpkg push
122   " repodir
123
124 and repodir_up_to_date repodir =
125   sh "
126     cd %s
127     git fetch
128   " repodir;
129   if not (git_has_local_changes repodir) then
130     sh "
131       cd %s
132       git pull --rebase
133     " repodir