summaryrefslogtreecommitdiffstats
path: root/sssd-nightly.sh
blob: 1552f1dfdeec956476e28f7ab11be238e9b3f4b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/bin/bash

function finish { #(exit code)
    rm -f /local/sgallagh/.sssd-build.lock

    if [ x$scratch_build != x ]; then
        exit $1
    fi

    recipients="ipa-and-samba-team-automation@redhat.com"

    if [ $1 -eq 0 ]; then
        successful="successfully"
    else
        successful="unsuccessfully"
    fi

    echo "Build completed $successful" | /bin/mailx -a $LOGFILE -s "SSSD automated build report for $datestamp" $recipients
    exit $1
}

if [ -e "/local/sgallagh/.sssd-build.lock" ]; then
    exit -1
fi

touch /local/sgallagh/.sssd-build.lock

mkdir -p /local/sgallagh/logs
cd /local/sgallagh
nextversion=$1
if [ x$nextversion == x ]; then
    nextversion=0.0.1
fi
datestamp=`date +%Y%m%d%H`
today=`date +%Y%m%d`
git_repo=$2
if [ x$git_repo == x ]; then
    git_repo=git://git.fedorahosted.org/sssd.git
    repodir=/local/sgallagh/repos
else
    scratch_build=1
    repodir=/local/sgallagh/repos/scratch
fi
if [ x$3 == x ]; then
    gitbranch=$3
else
    gitbranch=master
fi

LOGFILE=/local/sgallagh/logs/nightly-$datestamp.log

echo "===== BUILD STARTED AT `date` =====" >> $LOGFILE

echo "===== CHECKING OUT CODE =====" >> $LOGFILE
rm -Rf sssd-$datestamp #Remove an incomplete previous run
git clone $git_repo sssd-$datestamp >> $LOGFILE 2>&1
cd sssd-$datestamp
if [ x$gitbranch != x ]; then
    git branch $gitbranch origin/$gitbranch >> $LOGFILE 2>&1 || finish 96
    git checkout $gitbranch >> $LOGFILE 2>&1 || finish 97
fi
commit_id=`git log -1 --pretty=format:%h`

# If this is a scratch build, always run it
if [ x$scratch_build == x ]; then
    # See if the commit_id is different from the last run
    old_commit_id=`cat /local/sgallagh/.commit`
    if [ x$commit_id == x$old_commit_id ]; then
        cd /local/sgallagh && rm -Rf sssd-$datestamp
        rm -f $LOGFILE
        rm -f /local/sgallagh/.sssd-build.lock
        exit 0
    fi
fi

echo "===== Summary of Commits =====" >> $LOGFILE
git shortlog HEAD ^$old_commit_id >> $LOGFILE

cd /local/sgallagh/sssd-$datestamp
prereleaseversion=".${datestamp}git${commit_id}"
echo $nextversion > VERSION
echo $prereleaseversion >> VERSION
rpmversion=$nextversion-0$prereleaseversion

mv contrib/sssd.spec.in contrib/sssd.spec.in.orig && \
sed -e "s/make %/make CFLAGS=\"-ggdb3 -O0\" %/" < contrib/sssd.spec.in.orig > contrib/sssd.spec.in

echo "===== CONFIGURING CODE =====" >> $LOGFILE
autoreconf -i -f >> $LOGFILE 2>&1  || finish 1
./configure >> $LOGFILE 2>&1 || finish 2
make srpms >> $LOGFILE 2>&1 || finish 3
cd rpmbuild/SRPMS

echo "===== BUILDING RHEL 6 i386 =====" >> $LOGFILE
cd /local/sgallagh/sssd-$datestamp/rpmbuild/SRPMS
mv sssd-$rpmversion.fc11.src.rpm \
   sssd-$rpmversion.el6.src.rpm
mock -r epel-6-i386 sssd-$rpmversion.el6.src.rpm >> $LOGFILE 2>&1 || failed=1
if [ $failed ]; then
    cat /var/lib/mock/epel-6-i386/result/build.log >> $LOGFILE
    finish 6
fi

echo "===== BUILDING RHEL 6 x86_64 =====" >> $LOGFILE
mock -r epel-6-x86_64 sssd-$rpmversion.el6.src.rpm >> $LOGFILE 2>&1 || failed=1
if [ $failed ]; then
    cat /var/lib/mock/epel-6-x86_64/result/build.log >> $LOGFILE
    finish 7
fi

echo "===== CREATING RHEL 6 i586 YUM REPOSITORY ====" >> $LOGFILE
mkdir -p $repodir/rhel6/SRPMS
mkdir -p $repodir/rhel6/i386/DEBUGINFO
mkdir -p $repodir/rhel6/i386/RPMS
cp /var/lib/mock/epel-6-i386/result/sssd-$rpmversion.el6.src.rpm $repodir/rhel6/SRPMS
cp /var/lib/mock/epel-6-i386/result/sssd-debuginfo-$rpmversion.el6.i386.rpm $repodir/rhel6/i386/DEBUGINFO
cp /var/lib/mock/epel-6-i386/result/*.el6.i386.rpm $repodir/rhel6/i386/RPMS
rm -f $repodir/rhel6/i386/RPMS/sssd-debuginfo-$rpmversion.el6.i386.rpm

createrepo --update -s sha1 $repodir/rhel6/SRPMS > /dev/null
if [ $? -eq 0 ]; then
    echo "RHEL6 SRPM Repo updated" >> $LOGFILE
else
    echo "RHEL6 SRPM Repo not updated" >> $LOGFILE
fi

createrepo --update -s sha1 $repodir/rhel6/i386/DEBUGINFO > /dev/null
if [ $? -eq 0 ]; then
    echo "RHEL6 i386 DEBUGINFO Repo updated" >> $LOGFILE
else
    echo "RHEL6 i386 DEBUGINFO Repo not updated" >> $LOGFILE
fi

createrepo --update -s sha1 $repodir/rhel6/i386/RPMS > /dev/null
if [ $? -eq 0 ]; then
    echo "RHEL6 i386 RPM Repo updated" >> $LOGFILE
else
    echo "RHEL6 i386 RPM Repo not updated" >> $LOGFILE
fi

echo "===== CREATING RHEL 6 x86_86 YUM REPOSITORY ====" >> $LOGFILE
mkdir -p $repodir/rhel6/x86_64/DEBUGINFO
mkdir -p $repodir/rhel6/x86_64/RPMS
cp /var/lib/mock/epel-6-x86_64/result/sssd-debuginfo-$rpmversion.el6.x86_64.rpm $repodir/rhel6/x86_64/DEBUGINFO
cp /var/lib/mock/epel-6-i386/result/sssd-debuginfo-$rpmversion.el6.i386.rpm $repodir/rhel6/x86_64/DEBUGINFO
cp /var/lib/mock/epel-6-x86_64/result/*.el6.x86_64.rpm $repodir/rhel6/x86_64/RPMS
rm -f $repodir/rhel6/x86_64/RPMS/sssd-debuginfo-$rpmversion.el6.i386.rpm
cp /var/lib/mock/epel-6-i386/result/sssd-client-$rpmversion.el6.i386.rpm $repodir/rhel6/x86_64/RPMS

createrepo --update -s sha1 $repodir/rhel6/x86_64/DEBUGINFO > /dev/null
if [ $? -eq 0 ]; then
    echo "RHEL6 x86_64 DEBUGINFO Repo updated" >> $LOGFILE
else
    echo "RHEL6 x86_64 DEBUGINFO Repo not updated" >> $LOGFILE
fi

createrepo --update -s sha1 $repodir/rhel6/x86_64/RPMS > /dev/null
if [ $? -eq 0 ]; then
    echo "RHEL6 x86_64 RPM Repo updated" >> $LOGFILE
else
    echo "RHEL6 x86_64 RPM Repo not updated" >> $LOGFILE
fi

echo "===== Removing Source Tree =====" >> $LOGFILE
cd /local/sgallagh && rm -Rf sssd-$datestamp

#Save the commit id for the next time
if [ x$scratch_build == x ]; then
    echo $commit_id > /local/sgallagh/.commit
fi

echo "===== Cleaning old logs =====" >> $LOGFILE
find /local/sgallagh/logs -type f -daystart -ctime +6 -name "nightly-*.log" -exec rm -f {} \;

echo "===== Cleaning old RPMS =====" >> $LOGFILE
find /local/sgallagh/repos/rhel6 -type f -daystart -ctime +6 -name "sssd-*" -exec rm -f {} \;
find /local/sgallagh/repos/rhel6 -type f -daystart -ctime +6 -name "lib*" -exec rm -f {} \;

echo "===== BUILD CONCLUDED AT `date` =====" >> $LOGFILE

finish 0