blob: 6e78e543167f37f5f437580548c6f953e07918e1 (
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
|
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail
[[ $(whoami) == "root" ]] || exit 1
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
function ENV_SETUP() {
eselect news read --quiet all
eselect ruby set 1
if [[ ! -d /etc/portage/env/ ]]; then
mkdir /etc/portage/env/
fi
echo 'FEATURES="${FEATURES} test keepwork"' > /etc/portage/env/test
if [[ ! -d $SCRIPT_DIR/ci-logs/ ]]; then
mkdir "$SCRIPT_DIR/ci-logs"
fi
}
function SETUP () {
cp /var/lib/portage/world /var/lib/portage/world.original
echo "" > /etc/portage/package.accept_keywords
echo "=$PACKAGE doc" > /etc/portage/package.use
echo "=$PACKAGE test" > /etc/portage/package.env
if [[ -e /usr/portage/packages/$PACKAGE.tbz2 ]]; then
rm "/usr/portage/packages/$PACKAGE.tbz2"
fi
if [[ $TYPE == "next_target" ]]; then
mkdir -p "$SCRIPT_DIR/overlay"
mkdir -p "$SCRIPT_DIR/overlay/$CATEGORY/$NAME"
cp "/usr/portage/$CATEGORY/$NAME/$NAME-$VERSION.ebuild" "$SCRIPT_DIR/overlay/$CATEGORY/$NAME"
cp "/usr/portage/$CATEGORY/$NAME/metadata.xml" "$SCRIPT_DIR/overlay/$CATEGORY/$NAME"
cp -r "/usr/portage/$CATEGORY/$NAME/files" "$SCRIPT_DIR/overlay/$CATEGORY/$NAME" || true
(
cd "$SCRIPT_DIR/overlay/$CATEGORY/$NAME"
sed -i -e "/^USE_RUBY/s/=\"/=\"$NEXT_TARGET /" "$NAME-$VERSION.ebuild"
repoman manifest
repoman full
)
fi
set +e
emerge --pretend --quiet "=$PACKAGE"
if [[ $? == 1 ]]; then
emerge --autounmask-write "=$PACKAGE"
etc-update --automode -5
fi
set -e
}
function EMERGE() {
set +e
timeout 1000 emerge --usepkg --buildpkg "=$PACKAGE"
LOG "$?"
set -e
}
function LOG() {
DATE=$(date +%s)
SHA1=$(sha1sum "/usr/portage/$CATEGORY/$NAME/$NAME-$VERSION.ebuild" | awk '{print $1}')
mkdir -p "$SCRIPT_DIR/ci-logs/$SHA1/$TYPE/builds/$DATE"
emerge --info "=$PACKAGE" > "$SCRIPT_DIR/ci-logs/$SHA1/$TYPE/builds/$DATE/emerge-info"
emerge -pqv "=$PACKAGE" > "$SCRIPT_DIR/ci-logs/$SHA1/$TYPE/builds/$DATE/emerge-pqv"
cp "/var/tmp/portage/$PACKAGE/temp/build.log" "$SCRIPT_DIR/ci-logs/$SHA1/$TYPE/builds/$DATE/build.log"
cp "/var/tmp/portage/$PACKAGE/temp/environment" "$SCRIPT_DIR/ci-logs/$SHA1/$TYPE/builds/$DATE/environment"
gem list > "$SCRIPT_DIR/ci-logs/$SHA1/$TYPE/builds/$DATE/gem-list"
if [[ $1 == 0 ]]; then
RESULT="\e[0;32mBUILD SUCCEEDED\e[0m"
echo "succeeded" > "$SCRIPT_DIR/ci-logs/$SHA1/$TYPE/builds/$DATE/result"
elif [[ $1 == 1 ]]; then
RESULT="\e[0;31mBUILD FAILED\e[0m"
echo "failed" > "$SCRIPT_DIR/ci-logs/$SHA1/$TYPE/builds/$DATE/result"
elif [[ $1 == 124 ]]; then
RESULT="\e[0;31mBUILD TIMED OUT\e[0m"
echo "timed out" > "$SCRIPT_DIR/ci-logs/$SHA1/$TYPE/builds/$DATE/result"
else
RESULT="\e[0;31mBUILD UNKNOWN\e[0m"
echo "unknown" > "$SCRIPT_DIR/ci-logs/$SHA1/$TYPE/builds/$DATE/result"
fi
chmod 755 -R "$SCRIPT_DIR/ci-logs/$SHA1/$TYPE/builds/$DATE"
}
function CLEANUP() {
mv /var/lib/portage/world.original /var/lib/portage/world
rm -r /var/tmp/portage/* || true
emerge --depclean --quiet
echo -e "$PACKAGE : $RESULT"
if [[ $TYPE == "next_target" ]]; then
rm -r "$SCRIPT_DIR/overlay"
fi
}
ENV_SETUP
PKG_ARR=($(qatom "$1"))
CATEGORY="${PKG_ARR[0]}"
NAME="${PKG_ARR[1]}"
if [[ ${PKG_ARR[3]:=foo} == "foo" ]]; then
VERSION="${PKG_ARR[2]}"
else
VERSION="${PKG_ARR[2]}-${PKG_ARR[3]}"
fi
if [[ $# -eq 1 ]]; then
TYPE="current_target"
PACKAGE=$1
SETUP
EMERGE
CLEANUP
elif [[ $# -eq 2 ]]; then
TYPE="current_target"
PACKAGE=$1
SETUP
EMERGE
CLEANUP
TYPE="next_target"
PACKAGE=$1
NEXT_TARGET=$2
SETUP
EMERGE
CLEANUP
fi
|