libguestfs: Use python3 for builds and the Python PIP package.
[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.41-development", "master";    (* Rawhide follows development. *)*)
26   "1.40-stable", "master";
27   "1.40-stable", "f29";            (* F29 follows development. *)
28   "1.38-stable", "f28";            (* F28 follows 1.38. *)
29   "1.38-stable", "f27";            (* F27 follows 1.38. *)
30 ]
31
32 (* Goal: Latest website version has been built in every branch. *)
33 let rec goal all () =
34   List.iter (
35     fun (wbranch, fbranch) ->
36       match website_latest_version wbranch with
37       | None -> ()
38       | Some version ->
39         require (fedora_built version fbranch)
40   ) branches
41
42 (* Goal: Fedora has a successful build of 'version' on 'branch'. *)
43 and fedora_built version branch =
44   let specfile = fedora_specfile package branch in
45
46   target (file_contains_string specfile version.version &&
47             match koji_build_state (fedora_verrel package branch) with
48             | `Complete | `Building -> true
49             | _ -> false);
50
51   require (sources_uploaded version branch);
52   require (specfile_pushed version branch);
53
54   koji_build ~wait:true package branch
55
56 and sources_uploaded version branch =
57   let repodir = fedora_repo package branch in
58   let sources = repodir // "sources" in
59   let key = sprintf "libguestfs_fedora_sources_uploaded_%s" version.version in
60
61   target (file_contains_string sources version.version &&
62             memory_exists key);
63   onrun (fun () -> memory_set key "1");
64
65   require (repodir_up_to_date repodir);
66
67   if not version.is_stable then (
68     sh "
69       cd %s
70       fedpkg new-sources %s/%s
71     " repodir libguestfs_download_repo version.urlpath
72   ) else (
73     sh "
74       cd %s
75       fedpkg new-sources %s/%s %s/%s.sig
76     "  repodir
77        libguestfs_download_repo version.urlpath
78        libguestfs_download_repo version.urlpath
79   )
80
81 and specfile_updated version branch =
82   let repodir = fedora_repo package branch in
83   let specfile = fedora_specfile package branch in
84
85   target (file_contains_string specfile version.version);
86
87   require (repodir_up_to_date repodir);
88
89   (* Hairy specfile editing. *)
90   sh "
91     cd %s
92     email=\"Richard W.M. Jones <rjones@redhat.com>\"
93     date=`date +\"%%a %%b %%d %%Y\"`
94     cp libguestfs.spec libguestfs.spec.old
95     sed < libguestfs.spec.old \\
96     -e \"s/^Version:.*/Version:       %s/\" \\
97     -e \"s/^Release:.*/Release:       1%%{?dist}/\" \\
98     -e \"/^%%changelog/a \\
99 * $date $email - 1:%s-1\\\\n\\
100 - New upstream version %s.\\\\n\\
101 \" > libguestfs.spec
102     rm libguestfs.spec.old
103   " repodir version.version version.version version.version
104
105 and specfile_committed version branch =
106   let repodir = fedora_repo package branch in
107   let key = sprintf "libguestfs_fedora_specfile_committed_%s_%s"
108     branch version.version in
109
110   target (memory_exists key);
111   onrun (fun () -> memory_set key "1");
112
113   require (specfile_updated version branch);
114
115   sh "
116     cd %s
117     fedpkg commit -c
118   " repodir
119
120 and specfile_pushed version branch =
121   let repodir = fedora_repo package branch in
122   let key =
123     sprintf "libguestfs_fedora_specfile_pushed_%s_%s" branch version.version in
124
125   target (memory_exists key);
126   onrun (fun () -> memory_set key "1");
127
128   require (repodir_up_to_date repodir);
129   require (specfile_committed version branch);
130
131   sh "
132     cd %s
133     fedpkg push
134   " repodir
135
136 and repodir_up_to_date repodir =
137   sh "
138     cd %s
139     git fetch
140   " repodir;
141   if not (git_has_local_changes repodir) then
142     sh "
143       cd %s
144       git pull --rebase
145     " repodir