This patch contains the code changes to check the commit id in
[kvmfornfv.git] / ci / apex_build.sh
1 #!/bin/bash
2
3 function checkout_commit() {
4 build_dir=/opt/kvmfornfv/
5 mkdir -p /tmp/kvmfornfv
6 SRC=/tmp/kvmfornfv
7 source ${build_dir}/ci/apex.conf
8 cd $SRC
9 #Cloning into /tmp/kvmfornfv from local repository
10 git clone $build_dir $SRC
11 if [ "$branch" == "master" ] || [ "$branch" == "danube" ];then
12    echo "Checking out on $branch branch"
13    echo "Commit-id is ${commit_id}"
14    git checkout -f ${commit_id}
15    if [ $? -ne 0 ];then
16       echo "Please check the commit-id provided in apex.conf"
17       exit 1
18    fi
19 fi
20 mkdir ${output_dir}
21 }
22
23 output_dir="$1"
24 checkout_commit
25
26 kernel_src_dir=$SRC/kernel
27 rpmbuild_dir=$SRC/kvmfornfv_rpmbuild.$$
28 artifact_dir=${rpmbuild_dir}/RPMS/x86_64
29 mkdir -p $artifact_dir
30 config_file="${kernel_src_dir}/arch/x86/configs/opnfv.config"
31
32 usage () {
33     echo "usage: ${0} output_dir"
34     exit 1
35 }
36
37
38 if [[ -z "$@" ]]; then
39     usage
40 fi
41
42 if [ ! -d ${output_dir} -o ! -w ${output_dir} ] ; then
43     echo "${0}: Output directory '${output_dir}' does not exist or cannot \
44           be written"
45     exit 1
46 fi
47
48 if [ ! -d ${kernel_src_dir} ] ; then
49     echo "${0}: Directory '${kernel_src_dir}' does not exist, run this script \
50           from the root of kvmfornfv source tree"
51     exit 1
52 fi
53
54 if [ ! -f ${config_file} ] ; then
55     echo "${0}: ${config_file} does not exist"
56     exit 1
57 fi
58
59 echo
60 echo "Build"
61 echo
62
63 cp -f ${config_file} "${kernel_src_dir}/.config"
64
65 # Make timestamp part of version string for automated kernel boot verification
66 date "+-%y%m%d%H%M" > "${kernel_src_dir}/localversion-zzz"
67
68 (cd ${kernel_src_dir}; make RPMOPTS="--define '_topdir ${rpmbuild_dir}'" rpm-pkg)
69 if [ ${?} -ne 0 ] ; then
70     echo "${0}: Kernel build failed"
71     rm -rf ${rpmbuild_dir}
72     exit 1
73 fi
74
75 cp -f ${artifact_dir}/* ${output_dir}
76 mv ${output_dir}/* ${build_dir}/build_output/
77
78 rm -rf ${rpmbuild_dir}
79 #cleaning the /tmp
80 rm -rf ${SRC}