forked from morytyann/gh-action-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·186 lines (157 loc) · 4.33 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
#!/bin/bash
set -euo pipefail
# Logging functions
log() { printf '[%s] %s\n' "$(date '+%Y-%m-%d %H:%M:%S')" "${*}" >&2; }
log_error() { log "ERROR: ${*}"; }
log_info() { log "INFO: ${*}"; }
log_debug() { [[ "${V:-}" =~ ^(sc|s)$ ]] && log "DEBUG: ${*}"; }
# Stack to track nested groups
declare -a GROUP_STACK=()
# GitHub Actions group helpers with stacking support
group() {
if [[ "${GITHUB_ACTIONS:-}" == "true" ]]; then
echo "::group::${1}"
fi
GROUP_STACK+=("${1}")
log "BEGIN: ${1}"
}
endgroup() {
if [[ ${#GROUP_STACK[@]} -gt 0 ]]; then
if [[ "${GITHUB_ACTIONS:-}" == "true" ]]; then
echo "::endgroup::"
fi
log "END: ${GROUP_STACK[-1]}"
unset 'GROUP_STACK[${#GROUP_STACK[@]}-1]'
fi
}
cleanup() {
local exit_code=$?
while [[ ${#GROUP_STACK[@]} -gt 0 ]]; do
if [[ ${exit_code} -ne 0 ]]; then
log_error "Failed during: ${GROUP_STACK[-1]}"
fi
endgroup
done
exit "${exit_code}"
}
trap cleanup EXIT
FEEDNAME="${FEEDNAME:-action}"
ALL_CUSTOM_FEEDS="${FEEDNAME} "
if [[ -f setup.sh ]]; then
log_info "Executing setup script"
bash setup.sh
fi
if [[ -n "${KEY_BUILD:-}" ]]; then
log_info "Installing build signing key"
echo "${KEY_BUILD}" >key-build
CONFIG_SIGNED_PACKAGES="y"
fi
if [[ -n "${PRIVATE_KEY:-}" ]]; then
log_info "Installing private signing key"
echo "${PRIVATE_KEY}" >private-key.pem
CONFIG_SIGNED_PACKAGES="y"
fi
if [[ -z "${NO_DEFAULT_FEEDS:-}" ]]; then
log_info "Configuring default feeds"
sed -e 's,https://git.openwrt.org/\(feed\|openwrt\|project\)/,https://github.com/openwrt/,' \
feeds.conf.default >feeds.conf
fi
echo "src-link ${FEEDNAME} /feed/" >>feeds.conf
group "Extra Feeds Configuration"
if [[ -n "${EXTRA_FEEDS:-}" ]]; then
while read -r feed; do
log_info "Adding additional feed: ${feed}"
echo "${feed}" | tr '|' ' ' >>feeds.conf
ALL_CUSTOM_FEEDS+="$(echo "${feed}" | cut -d'|' -f2) "
./scripts/feeds list -r ${feed}
done <<<"${EXTRA_FEEDS}"
fi
endgroup
group "Feed Configuration"
./scripts/feeds list -s
log_info "Updating feed repositories"
./scripts/feeds update -a
./scripts/feeds install -p ${FEEDNAME} -a -d n
endgroup
group "Default Configuration"
log_info "Generating build configuration"
make defconfig
endgroup
build_package() {
local pkg="${1}"
local feed
for feed in ${ALL_CUSTOM_FEEDS}; do
log_info "Installing ${pkg} from feed ${feed}"
if ! ./scripts/feeds install -p "${feed}" -d m -f "${pkg}"; then
log_error "Installation failed for ${pkg} from ${feed}"
return 1
fi
done
log_info "Downloading ${pkg}"
if ! make "package/${pkg}/download" V=s; then
log_error "Download failed for ${pkg}"
return 1
fi
log_info "Verifying ${pkg}"
if ! make "package/${pkg}/check" V=s; then
log_error "Verification failed for ${pkg}"
return 1
fi
log_info "Compiling ${pkg}"
if ! make "package/${pkg}/compile" \
CONFIG_AUTOREMOVE=y \
V="${V:-}" \
-j "$(nproc)"; then
log_error "Compilation failed for ${pkg}"
return 1
fi
return 0
}
if [[ -z "${PACKAGES:-}" ]]; then
group "Full Build"
for feed in ${ALL_CUSTOM_FEEDS}; do
group "Installing ${feed}"
log_info "Installing all packages from ${feed}"
if ! ./scripts/feeds install -p "${feed}" -d m -f -a; then
log_error "Feed installation failed: ${feed}"
exit 1
fi
endgroup
done
group "Build"
log_info "Starting build"
if ! make \
CONFIG_AUTOREMOVE=y \
V="${V:-}" \
-j "$(nproc)"; then
log_error "Build failed"
exit 1
fi
endgroup
endgroup
else
group "Package Build"
for pkg in ${PACKAGES}; do
group "Building ${pkg}"
if ! build_package "${pkg}"; then
log_error "Package build failed: ${pkg}"
exit 1
fi
endgroup
done
endgroup
fi
if [[ "${INDEX:-0}" == "1" ]]; then
group "Index Generation"
log_info "Generating package index"
if ! make package/index; then
log_error "Index generation failed"
exit 1
fi
endgroup
fi
if [ -d bin/ ]; then
mv -v bin /artifacts/
fi
log_info "Build completed"
exit 0