summaryrefslogtreecommitdiffstats
path: root/sssd-nightly.sh
blob: d9b993bc28af8233a54a399ba57de6c4fb8bf719 (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
#!/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

    finishtime=`date`

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

if [ -e "/local/sgallagh/.sssd-build.lock" ]; then
	echo "Previous build still running. Is it stuck?"
    exit 0
fi

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

mkdir -p /local/sgallagh/logs

datestamp=`date +%Y%m%d.%H%M`

repodir=/local/sgallagh/repos
mkdir -p $repodir

if [ x$1 != x ]; then
    gitbranch=$1
else
    gitbranch=master
fi

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

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

echo "===== CHECKING OUT CODE =====" >> $LOGFILE

cd /local/sgallagh/sssd
git remote update >> $LOGFILE 2>&1 || finish 95
git reset --hard origin/$gitbranch >> $LOGFILE 2>&1 || finish 96

commit_id=`git log -1 --pretty=format:%h`

fullversion=`grep "\[VERSION_NUMBER\]" version.m4`

# Try X.Y.ZZ first
version=${fullversion:29:6}

# Try X.Y.Z
if [ "${version:5}" == "]" ]; then
    version=${fullversion:29:5}
fi

# See if the commit_id is different from the last run
old_commit_id=`cat /local/sgallagh/.commit_$gitbranch 2> /dev/null`
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

echo "===== Summary of Commits =====" >> $LOGFILE
git shortlog --no-merges HEAD ^$old_commit_id >> $LOGFILE 2>&1

# Disable optimizations
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
mv version.m4 version.m4.orig &&
sed -e "s/m4_define(\[PRERELEASE_VERSION_NUMBER\], \[.*\])/m4_define(\[PRERELEASE_VERSION_NUMBER\], \[.$datestamp.git`git log -1 --pretty=format:%h`\])/" < version.m4.orig > version.m4 2>> $LOGFILE
autoreconf -if >> $LOGFILE 2>&1  || finish 1
./configure >> $LOGFILE 2>&1 || finish 2
make srpm >> $LOGFILE 2>&1 || finish 3

echo "===== BUILDING FEDORA 15 =====" >> $LOGFILE
rm -Rf ${datestamp}_${gitbranch}_15
cd /local/sgallagh
/local/sgallagh/build_tools/koji-build.py --build_id=${datestamp}_${gitbranch}_15 \
    /local/sgallagh/sssd/rpmbuild/SRPMS/sssd-$version-0.$datestamp.git$commit_id.el6.src.rpm >> $LOGFILE 2>&1 || finish 4

echo "===== Creating Fedora 15 Repository =====" >> $LOGFILE
mkdir -p $repodir/$gitbranch/15/SRPMS
mkdir -p $repodir/$gitbranch/15/i386/DEBUGINFO
mkdir -p $repodir/$gitbranch/15/i386/RPMS
mkdir -p $repodir/$gitbranch/15/i386/logs
mkdir -p $repodir/$gitbranch/15/x86_64/DEBUGINFO
mkdir -p $repodir/$gitbranch/15/x86_64/RPMS
mkdir -p $repodir/$gitbranch/15/x86_64/logs

cp ${datestamp}_${gitbranch}_15/SRPMS/* \
   $repodir/$gitbranch/15/SRPMS
   
cp ${datestamp}_${gitbranch}_15/i386/DEBUGINFO/* \
   $repodir/$gitbranch/15/i386/DEBUGINFO

cp ${datestamp}_${gitbranch}_15/i386/RPMS/* \
   $repodir/$gitbranch/15/i386/RPMS
cp ${datestamp}_${gitbranch}_15/i386/RPMS/* \
   $repodir/$gitbranch/15/x86_64/RPMS

cp ${datestamp}_${gitbranch}_15/i386/logs/* \
   $repodir/$gitbranch/15/i386/logs
   
cp ${datestamp}_${gitbranch}_15/x86_64/DEBUGINFO/* \
   $repodir/$gitbranch/15/x86_64/DEBUGINFO

cp ${datestamp}_${gitbranch}_15/x86_64/RPMS/* \
   $repodir/$gitbranch/15/x86_64/RPMS

cp ${datestamp}_${gitbranch}_15/x86_64/logs/* \
   $repodir/$gitbranch/15/x86_64/logs

# Clean up old RPMs
rm -f `repomanage -k4 --old $repodir/$gitbranch/15`

createrepo $repodir/$gitbranch/15/SRPMS > /dev/null
if [ $? -eq 0 ]; then
    echo "Fedora 15 SRPM Repo updated" >> $LOGFILE
else
    echo "Fedora 15 SRPM Repo not updated" >> $LOGFILE
fi

createrepo $repodir/$gitbranch/15/i386/DEBUGINFO > /dev/null
if [ $? -eq 0 ]; then
    echo "Fedora 15 i386/DEBUGINFO Repo updated" >> $LOGFILE
else
    echo "Fedora 15 i386/DEBUGINFO Repo not updated" >> $LOGFILE
fi

createrepo $repodir/$gitbranch/15/i386/RPMS > /dev/null
if [ $? -eq 0 ]; then
    echo "Fedora 15 i386/RPMS Repo updated" >> $LOGFILE
else
    echo "Fedora 15 i386/RPMS Repo not updated" >> $LOGFILE
fi

createrepo $repodir/$gitbranch/15/x86_64/DEBUGINFO > /dev/null
if [ $? -eq 0 ]; then
    echo "Fedora 15 x86_64/DEBUGINFO Repo updated" >> $LOGFILE
else
    echo "Fedora 15 x86_64/DEBUGINFO Repo not updated" >> $LOGFILE
fi

createrepo $repodir/$gitbranch/15/x86_64/RPMS > /dev/null
if [ $? -eq 0 ]; then
    echo "Fedora 15 x86_64/RPMS Repo updated" >> $LOGFILE
else
    echo "Fedora 15 x86_64/RPMS Repo not updated" >> $LOGFILE
fi

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

echo "===== RSYNC the repositories =====" >> $LOGFILE
rsync -avz /local/sgallagh/repos/* sgallagh@fedorapeople.org:/srv/repos/gitsssd/sssd >> $LOGFILE 2>&1

echo $commit_id > /local/sgallagh/.commit_$gitbranch

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

finish 0