forked from openwrt/gh-action-sdk
-
Notifications
You must be signed in to change notification settings - Fork 2
/
entrypoint.sh
executable file
·191 lines (157 loc) · 3.95 KB
/
entrypoint.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
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
182
183
184
185
186
187
188
189
190
191
#!/bin/bash
set -ef
GROUP=
group() {
endgroup
echo "::group:: $1"
GROUP=1
}
endgroup() {
if [ -n "$GROUP" ]; then
echo "::endgroup::"
fi
GROUP=
}
trap 'endgroup' ERR
FEEDNAME="${FEEDNAME:-action}"
BUILD_LOG="${BUILD_LOG:-1}"
if [ -n "$KEY_BUILD" ]; then
echo "$KEY_BUILD" > key-build
CONFIG_SIGNED_PACKAGES="y"
fi
if [ -z "$NO_DEFAULT_FEEDS" ]; then
sed \
-e 's,https://git.openwrt.org/feed/,https://github.com/openwrt/,' \
-e 's,https://git.openwrt.org/openwrt/,https://github.com/openwrt/,' \
-e 's,https://git.openwrt.org/project/,https://github.com/openwrt/,' \
feeds.conf.default > feeds.conf
fi
echo "src-link $FEEDNAME /feed/" >> feeds.conf
ALL_CUSTOM_FEEDS="$FEEDNAME "
#shellcheck disable=SC2153
for EXTRA_FEED in $EXTRA_FEEDS; do
echo "$EXTRA_FEED" | tr '|' ' ' >> feeds.conf
ALL_CUSTOM_FEEDS+="$(echo "$EXTRA_FEED" | cut -d'|' -f2) "
done
group "feeds.conf"
cat feeds.conf
endgroup
group "feeds update -a"
./scripts/feeds update -a
endgroup
group "make defconfig"
make defconfig
endgroup
if [ -z "$PACKAGES" ]; then
# compile all packages in feed
for FEED in $ALL_CUSTOM_FEEDS; do
group "feeds install -p $FEED -f -a"
./scripts/feeds install -p "$FEED" -f -a
endgroup
done
RET=0
make \
BUILD_LOG="$BUILD_LOG" \
CONFIG_SIGNED_PACKAGES="$CONFIG_SIGNED_PACKAGES" \
IGNORE_ERRORS="$IGNORE_ERRORS" \
CONFIG_AUTOREMOVE=y \
V="$V" \
-j "$(nproc)" || RET=$?
else
# compile specific packages with checks
for PKG in $PACKAGES; do
for FEED in $ALL_CUSTOM_FEEDS; do
group "feeds install -p $FEED -f $PKG"
./scripts/feeds install -p "$FEED" -f "$PKG"
endgroup
done
group "make package/$PKG/download"
make \
BUILD_LOG="$BUILD_LOG" \
IGNORE_ERRORS="$IGNORE_ERRORS" \
"package/$PKG/download" V=s
endgroup
group "make package/$PKG/check"
make \
BUILD_LOG="$BUILD_LOG" \
IGNORE_ERRORS="$IGNORE_ERRORS" \
"package/$PKG/check" V=s 2>&1 | \
tee logtmp
endgroup
RET=${PIPESTATUS[0]}
if [ "$RET" -ne 0 ]; then
echo_red "=> Package check failed: $RET)"
exit "$RET"
fi
badhash_msg="HASH does not match "
badhash_msg+="|HASH uses deprecated hash,"
badhash_msg+="|HASH is missing,"
if grep -qE "$badhash_msg" logtmp; then
echo "Package HASH check failed"
exit 1
fi
PATCHES_DIR=$(find /feed -path "*/$PKG/patches")
if [ -d "$PATCHES_DIR" ] && [ -z "$NO_REFRESH_CHECK" ]; then
group "make package/$PKG/refresh"
make \
BUILD_LOG="$BUILD_LOG" \
IGNORE_ERRORS="$IGNORE_ERRORS" \
"package/$PKG/refresh" V=s
endgroup
if ! git -C "$PATCHES_DIR" diff --quiet -- .; then
echo "Dirty patches detected, please refresh and review the diff"
git -C "$PATCHES_DIR" checkout -- .
exit 1
fi
group "make package/$PKG/clean"
make \
BUILD_LOG="$BUILD_LOG" \
IGNORE_ERRORS="$IGNORE_ERRORS" \
"package/$PKG/clean" V=s
endgroup
fi
FILES_DIR=$(find /feed -path "*/$PKG/files")
if [ -d "$FILES_DIR" ] && [ -z "$NO_SHFMT_CHECK" ]; then
find "$FILES_DIR" -name "*.init" -exec shfmt -w -sr -s '{}' \;
if ! git -C "$FILES_DIR" diff --quiet -- .; then
echo "init script must be formatted. Please run through shfmt -w -sr -s"
git -C "$FILES_DIR" checkout -- .
exit 1
fi
fi
done
make \
-f .config \
-f tmp/.packagedeps \
-f <(echo "\$(info \$(sort \$(package-y) \$(package-m)))"; echo -en "a:\n\t@:") \
| tr ' ' '\n' > enabled-package-subdirs.txt
RET=0
for PKG in $PACKAGES; do
if ! grep -m1 -qE "(^|/)$PKG$" enabled-package-subdirs.txt; then
echo "::warning file=$PKG::Skipping $PKG due to unsupported architecture"
continue
fi
make \
BUILD_LOG="$BUILD_LOG" \
IGNORE_ERRORS="$IGNORE_ERRORS" \
CONFIG_AUTOREMOVE=y \
V="$V" \
-j "$(nproc)" \
"package/$PKG/compile" || {
RET=$?
break
}
done
fi
if [ "$INDEX" = '1' ];then
group "make package/index"
make package/index
endgroup
fi
if [ -d bin/ ]; then
mv bin/ /artifacts/
fi
if [ -d logs/ ]; then
mv logs/ /artifacts/
fi
exit "$RET"