forked from uyuni-project/uyuni
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild
executable file
·99 lines (86 loc) · 4.22 KB
/
build
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
#!/usr/bin/env bash
LOOKASIDE="http://koji.spacewalkproject.org/kojifiles/lookaside-static"
STATUS_ALL=0
GITROOT=$(pwd)/$(git rev-parse --show-cdup)
# For pull requests just compare target branch and github merge commit,
# TRAVIS_COMMIT_RANGE is unusable because there is commit from master
# and if pull request modifies old version, range is big and many files
# differ (may be bug in travis)
if [ "$TRAVIS_PULL_REQUEST" == "false" ] ; then
COMMIT_RANGE=$TRAVIS_COMMIT_RANGE
else
COMMIT_RANGE=$TRAVIS_BRANCH...FETCH_HEAD
fi
echo "Commit range: $COMMIT_RANGE"
CHANGED_FILES=$(git diff --name-only $COMMIT_RANGE)
# loop all packages
for package in $GITROOT/rel-eng/packages/* ; do
prefix=$(cat $package | awk '{print $2}')
package_basename=$(basename $package)
latest_tag=$package_basename-$(cat $package | awk '{print $1}')
if echo "$CHANGED_FILES" | grep -q "^$prefix" ; then
# process package
echo -en "travis_fold:start:$package_basename-build\\r"
echo "Building $package_basename..."
cd $GITROOT$prefix
# can we describe latest tag? tito fails if not
echo "Describing latest tag"
# doesn't make sense to fetch history if the tag isn't there anyway
if git ls-remote origin $latest_tag | grep -q $latest_tag ; then
until git describe $latest_tag ; do
git_depth=$((git_depth + 2000))
echo "Tag not found, fetching git history with depth $git_depth"
git fetch --depth=$git_depth 2>&1 | grep "[new tag]" | wc -l | xargs echo "New tags:"
done
else
echo "Tag not in remote, not pushed?"
fi
# we may need third party dependencies for creating SRPM
if grep -q "NoTgzBuilder" tito.props ; then
echo "Tito NoTgzBuilder found, getting sources"
version=$(rpmspec -q --srpm --qf "%{version}" $package_basename.spec)
wget -r -nd -np -nv -R "index.html*" -e robots=off $LOOKASIDE/$package_basename-$version/
# need to commit downloaded sources for Tito
git add . && git commit -am "Adding sources"
fi
echo -en "travis_fold:start:$package_basename-mock\\r"
echo "Running builder"
mkdir -p /tmp/mock/$package_basename
sudo chown -R 1000 /tmp/mock/$package_basename
# build SRPM
docker run --rm --privileged=true -v $GITROOT:/git -v /tmp/mock/$package_basename:/out -e PACKAGE=$prefix -e DIST=spacewalk-nightly-fedora27 spacewalkproject/docker-builder
status=$?
echo -en "travis_fold:end:$package_basename-mock\\r"
if [ $status -eq 0 ] ; then
STATUS_MSG="Building $package_basename succeeded!"
# build in koji if tag was pushed
tag_commit=$(git rev-parse $latest_tag^{commit})
if [ -f ~/.koji/.spacewalk.cert ] && [ "$TRAVIS_PULL_REQUEST" == "false" ] && git rev-list $TRAVIS_COMMIT_RANGE | grep -q "$tag_commit" ; then
echo "Tag present, releasing to Koji"
# workarround - git ls-remote ./. on Travis doesn't work with shallow clones (bug?)
mv $GITROOT/.git/shallow $GITROOT/.git/shallow.org
tito release koji
mv $GITROOT/.git/shallow.org $GITROOT/.git/shallow
fi
else
STATUS_MSG="Building $package_basename failed with code: $status, see logs."
# output logs
echo -en "travis_fold:start:$package_basename-build-log\\r"
echo "# build.log"
cat /tmp/mock/$package_basename/build.log
echo -en "travis_fold:end:$package_basename-build-log\\r"
echo -en "travis_fold:start:$package_basename-root-log\\r"
echo "# root.log"
cat /tmp/mock/$package_basename/root.log
echo -en "travis_fold:end:$package_basename-root-log\\r"
echo -en "travis_fold:start:$package_basename-state-log\\r"
echo "# state.log"
cat /tmp/mock/$package_basename/state.log
echo -en "travis_fold:end:$package_basename-state-log\\r"
fi
STATUS_ALL=$((STATUS_ALL+status))
echo -en "travis_fold:end:$package_basename-build\\r"
echo $STATUS_MSG
fi
done
exit $STATUS_ALL