-
Notifications
You must be signed in to change notification settings - Fork 7
/
build-nightly.sh
executable file
·126 lines (101 loc) · 3.3 KB
/
build-nightly.sh
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
#!/bin/bash
set -e
# Global nightly building script for buddycloud projects
# Iterates over all the project in the projects folder,
# checks if there is new commit for it github that was not built yet
# and builds it.
# Build variables
DEBFULLNAME="Abmar Barros (buddycloud Packaging)"
DEBEMAIL="[email protected]"
DIR_NAME="$(dirname $0)"
CURRENT_DIR="$(cd $DIR_NAME; pwd)"
PROJECTS_DIR=$CURRENT_DIR/projects
BUILD_DIR=$CURRENT_DIR/build
DATE=$(date +%Y%m%d)
DATE_REPR=$(date -R)
DOWNLOAD_ROOT=/var/web/downloads.buddycloud.com/packages/debian/nightly
function process {
PROJECT_FOLDER=$1
echo "Processing project $PROJECT_FOLDER"
source $PROJECT_FOLDER/configure
# Setting project properties
PROJECT_PATH=$BUILD_DIR/$PROJECT_NAME
mkdir -p $PROJECT_PATH
GIT_PATH=$PROJECT_PATH/git
# Updating git folder
if [ -d "$GIT_PATH" ]; then
cd $GIT_PATH
git clean -xdf
git reset --hard
git pull
else
git clone $GIT_URL $GIT_PATH
fi
cd $GIT_PATH
REV="$(git log -1 --pretty=format:%h)"
if [ ! -f ../prev.rev ]; then
git log --max-parents=0 HEAD --pretty=format:%h > ../prev.rev
fi
REV_PREV="$(cat ../prev.rev)"
DEB_CREATED=$(ls ../$PROJECT_NAME*.git.$REV*.deb || true)
if [ -z "$DEB_CREATED" ]; then
echo "Last build failed, building again."
rm -rf ../$PROJECT_NAME*.git.$REV* || true
OPT_FORCE=true
else
unset OPT_FORCE
fi
if [ "$REV" == "$REV_PREV" ]; then
if [ -z "$OPT_FORCE" ]; then
echo "Last build successful. No need to build!"
return
fi
CHANGELOG=" * : No changes"
else
# convert svn changelog into deb changelog.
# strip duplicate blank lines too
CHANGELOG="$(git log $REV_PREV..$REV --pretty=format:'[ %an ]%n>%s' | ../../../gitcl2deb.sh)"
fi
BUILD_VERSION="${DIST_VERSION}+dev${DATE}.git.${REV}"
DIST_REVISION="${BUILD_VERSION}-1"
SOURCE="${PACKAGE}-${BUILD_VERSION}"
ORIG_TGZ="${PACKAGE}_${BUILD_VERSION}.orig.tar.gz"
echo "Building orig.tar.gz ..."
git archive --format=tar "--prefix=${SOURCE}/" "${REV}" | gzip >"../${ORIG_TGZ}"
echo -e "${PACKAGE} (${DIST_REVISION}) ${DIST}; urgency=low\n\n\
${CHANGELOG}\n\n\
-- ${DEBFULLNAME} <${DEBEMAIL}> ${DATE_REPR}\n"\
> $PROJECT_FOLDER/debian/changelog
if [ -f $PROJECT_PATH/changelog.rev ]; then
cat $PROJECT_PATH/changelog.rev >>$PROJECT_FOLDER/debian/changelog
fi
cd $PROJECT_PATH
tar xzf $ORIG_TGZ
cd $SOURCE
rsync -a $PROJECT_FOLDER/debian .
# Building debian package
if [ "${BUILD_ARCH}" == "all" ]; then
LOGFILE=$PROJECT_PATH/${PACKAGE}_${BUILD_VERSION}_${BUILD_ARCH}.log
debuild | tee $LOGFILE
else
IFS=',' read -ra ARCHS <<< "${BUILD_ARCH}"
for ARCH in "${ARCHS[@]}"; do
LOGFILE=$PROJECT_PATH/${PACKAGE}_${BUILD_VERSION}_${ARCH}.log
debuild -a${ARCH} | tee $LOGFILE || true
done
fi
# Save previous build info
echo "$REV" > $PROJECT_PATH/prev.rev
cp $PROJECT_FOLDER/debian/changelog $PROJECT_PATH/changelog.rev
# Copy packages to download folder
DOWNLOAD_PACKAGE_DIR=$DOWNLOAD_ROOT/$PACKAGE/$SOURCE
mkdir -p $DOWNLOAD_PACKAGE_DIR
rsync -a $PROJECT_PATH/${PACKAGE}_${BUILD_VERSION}* $DOWNLOAD_PACKAGE_DIR --exclude=*.build
}
if [ $# -ne 0 ]; then
process $1
exit
fi
for PROJECT_FOLDER_PATH in $PROJECTS_DIR/*; do
process $PROJECT_FOLDER_PATH
done