783943badd996d60e505d577175e345b562a8402
[openwrt/staging/nbd.git] / .github / workflows / build.yml
1 name: Build sub target
2
3 on:
4 workflow_call:
5 inputs:
6 target:
7 required: true
8 type: string
9 testing:
10 type: boolean
11 build_toolchain:
12 type: boolean
13 include_feeds:
14 type: boolean
15 build_full:
16 type: boolean
17 build_all_modules:
18 type: boolean
19 build_all_kmods:
20 type: boolean
21 build_all_boards:
22 type: boolean
23
24 permissions:
25 contents: read
26
27 jobs:
28 setup_build:
29 name: Setup build ${{ inputs.target }}
30 runs-on: ubuntu-latest
31 outputs:
32 owner_lc: ${{ steps.lower_owner.outputs.owner_lc }}
33 ccache_hash: ${{ steps.ccache_hash.outputs.ccache_hash }}
34 container_tag: ${{ steps.determine_tools_container.outputs.container_tag }}
35
36 steps:
37 - name: Checkout
38 uses: actions/checkout@v3
39
40 - name: Set lower case owner name
41 id: lower_owner
42 run: |
43 OWNER_LC=$(echo "${{ github.repository_owner }}" \
44 | tr '[:upper:]' '[:lower:]')
45 echo "owner_lc=$OWNER_LC" >> $GITHUB_OUTPUT
46
47 - name: Generate ccache hash
48 id: ccache_hash
49 run: |
50 CCACHE_HASH=$(md5sum include/kernel-* | awk '{ print $1 }' \
51 | md5sum | awk '{ print $1 }')
52 echo "ccache_hash=$CCACHE_HASH" >> $GITHUB_OUTPUT
53
54 # Per branch tools container tag
55 # By default stick to latest
56 # For official test targetting openwrt stable branch
57 # Get the branch or parse the tag and push dedicated tools containers
58 # For local test to use the correct container for stable release testing
59 # you need to use for the branch name a prefix of openwrt-[0-9][0-9].[0-9][0-9]-
60 - name: Determine tools container tag
61 id: determine_tools_container
62 run: |
63 CONTAINER_TAG=latest
64 if [ -n "${{ github.base_ref }}" ]; then
65 if echo "${{ github.base_ref }}" | grep -q -E '^openwrt-[0-9][0-9]\.[0-9][0-9]$'; then
66 CONTAINER_TAG="${{ github.base_ref }}"
67 fi
68 elif [ ${{ github.ref_type }} == "branch" ]; then
69 if echo "${{ github.ref_name }}" | grep -q -E '^openwrt-[0-9][0-9]\.[0-9][0-9]$'; then
70 CONTAINER_TAG=${{ github.ref_name }}
71 elif echo "${{ github.ref_name }}" | grep -q -E '^openwrt-[0-9][0-9]\.[0-9][0-9]-'; then
72 CONTAINER_TAG="$(echo ${{ github.ref_name }} | sed 's/^\(openwrt-[0-9][0-9]\.[0-9][0-9]\)-.*/\1/')"
73 fi
74 elif [ ${{ github.ref_type }} == "tag" ]; then
75 if echo "${{ github.ref_name }}" | grep -q -E '^v[0-9][0-9]\.[0-9][0-9]\..+'; then
76 CONTAINER_TAG=openwrt-"$(echo ${{ github.ref_name }} | sed 's/^v\([0-9][0-9]\.[0-9][0-9]\)\..\+/\1/')"
77 fi
78 fi
79 echo "Tools container to use tools:$CONTAINER_TAG"
80 echo "container_tag=$CONTAINER_TAG" >> $GITHUB_OUTPUT
81
82 build:
83 name: Build ${{ inputs.target }}
84 needs: setup_build
85 runs-on: ubuntu-latest
86
87 container: ghcr.io/${{ needs.setup_build.outputs.owner_lc }}/tools:${{ needs.setup_build.outputs.container_tag }}
88
89 permissions:
90 contents: read
91 packages: read
92
93 steps:
94 - name: Checkout master directory
95 uses: actions/checkout@v3
96 with:
97 path: openwrt
98
99 - name: Checkout packages feed
100 if: inputs.include_feeds == true
101 uses: actions/checkout@v3
102 with:
103 repository: openwrt/packages
104 path: openwrt/feeds/packages
105
106 - name: Checkout luci feed
107 if: inputs.include_feeds == true
108 uses: actions/checkout@v3
109 with:
110 repository: openwrt/luci
111 path: openwrt/feeds/luci
112
113 - name: Checkout routing feed
114 if: inputs.include_feeds == true
115 uses: actions/checkout@v3
116 with:
117 repository: openwrt/routing
118 path: openwrt/feeds/routing
119
120 - name: Checkout telephony feed
121 if: inputs.include_feeds == true
122 uses: actions/checkout@v3
123 with:
124 repository: openwrt/telephony
125 path: openwrt/feeds/telephony
126
127 - name: Fix permission
128 run: |
129 chown -R buildbot:buildbot openwrt
130
131 - name: Initialization environment
132 run: |
133 TARGET=$(echo ${{ inputs.target }} | cut -d "/" -f 1)
134 SUBTARGET=$(echo ${{ inputs.target }} | cut -d "/" -f 2)
135 echo "TARGET=$TARGET" >> "$GITHUB_ENV"
136 echo "SUBTARGET=$SUBTARGET" >> "$GITHUB_ENV"
137
138 - name: Update & Install feeds
139 if: inputs.include_feeds == true
140 shell: su buildbot -c "sh -e {0}"
141 working-directory: openwrt
142 run: |
143 ./scripts/feeds update -a
144 ./scripts/feeds install -a
145
146 - name: Parse toolchain file
147 if: inputs.build_toolchain == false
148 id: parse-toolchain
149 working-directory: openwrt
150 run: |
151 TOOLCHAIN_PATH=snapshots
152
153 if [ -n "${{ github.base_ref }}" ]; then
154 if echo "${{ github.base_ref }}" | grep -q -E '^openwrt-[0-9][0-9]\.[0-9][0-9]$'; then
155 major_ver="$(echo ${{ github.base_ref }} | sed 's/^openwrt-/v/')"
156 fi
157 elif [ "${{ github.ref_type }}" = "branch" ]; then
158 if echo "${{ github.ref_name }}" | grep -q -E '^openwrt-[0-9][0-9]\.[0-9][0-9]$'; then
159 major_ver="$(echo ${{ github.ref_name }} | sed 's/^openwrt-/v/')"
160 elif echo "${{ github.ref_name }}" | grep -q -E '^openwrt-[0-9][0-9]\.[0-9][0-9]-'; then
161 major_ver="$(echo ${{ github.ref_name }} | sed 's/^openwrt-\([0-9][0-9]\.[0-9][0-9]\)-.*/v\1/')"
162 fi
163 elif [ "${{ github.ref_type }}" = "tag" ]; then
164 if echo "${{ github.ref_name }}" | grep -q -E '^v[0-9][0-9]\.[0-9][0-9]\..+'; then
165 major_ver="$(echo ${{ github.ref_name }} | sed 's/^\(v[0-9][0-9]\.[0-9][0-9]\)\..\+/\1/')"
166 fi
167 fi
168
169 if [ -n "$major_ver" ]; then
170 git fetch --tags
171 latest_tag="$(git tag --sort=-creatordate -l $major_ver* | head -n1)"
172 if [ -n "$latest_tag" ]; then
173 TOOLCHAIN_PATH=releases/$(echo $latest_tag | sed 's/^v//')
174 fi
175 fi
176
177 SUMS_FILE="https://downloads.cdn.openwrt.org/$TOOLCHAIN_PATH/targets/${{ env.TARGET }}/${{ env.SUBTARGET }}/sha256sums"
178 if curl $SUMS_FILE | grep -q ".*openwrt-toolchain.*tar.xz"; then
179 TOOLCHAIN_STRING="$( curl $SUMS_FILE | grep ".*openwrt-toolchain.*tar.xz")"
180 TOOLCHAIN_FILE=$(echo "$TOOLCHAIN_STRING" | sed -n -e 's/.*\(openwrt-toolchain.*\).tar.xz/\1/p')
181 TOOLCHAIN_SHA256=$(echo "$TOOLCHAIN_STRING" | cut -d ' ' -f 1)
182
183 echo "toolchain-type=external_toolchain" >> $GITHUB_OUTPUT
184 elif curl $SUMS_FILE | grep -q ".*openwrt-sdk.*tar.xz"; then
185 TOOLCHAIN_STRING="$( curl $SUMS_FILE | grep ".*openwrt-sdk.*tar.xz")"
186 TOOLCHAIN_FILE=$(echo "$TOOLCHAIN_STRING" | sed -n -e 's/.*\(openwrt-sdk.*\).tar.xz/\1/p')
187 TOOLCHAIN_SHA256=$(echo "$TOOLCHAIN_STRING" | cut -d ' ' -f 1)
188
189 echo "toolchain-type=external_sdk" >> $GITHUB_OUTPUT
190 fi
191
192 echo "TOOLCHAIN_FILE=$TOOLCHAIN_FILE" >> "$GITHUB_ENV"
193 echo "TOOLCHAIN_SHA256=$TOOLCHAIN_SHA256" >> "$GITHUB_ENV"
194 echo "TOOLCHAIN_PATH=$TOOLCHAIN_PATH" >> "$GITHUB_ENV"
195
196 - name: Cache external toolchain/sdk
197 if: inputs.build_toolchain == false
198 id: cache-external-toolchain
199 uses: actions/cache@v3
200 with:
201 path: openwrt/${{ env.TOOLCHAIN_FILE }}
202 key: ${{ env.TOOLCHAIN_FILE }}-${{ steps.parse-toolchain.outputs.toolchain-type }}-${{ env.TOOLCHAIN_SHA256 }}
203
204 - name: Cache ccache
205 uses: actions/cache@v3
206 with:
207 path: openwrt/.ccache
208 key: ccache-kernel-${{ env.TARGET }}/${{ env.SUBTARGET }}-${{ needs.setup_build.outputs.ccache_hash }}
209 restore-keys: |
210 ccache-kernel-${{ env.TARGET }}/${{ env.SUBTARGET }}-
211
212 - name: Download external toolchain/sdk
213 if: inputs.build_toolchain == false && steps.cache-external-toolchain.outputs.cache-hit != 'true'
214 shell: su buildbot -c "sh -e {0}"
215 working-directory: openwrt
216 run: |
217 wget -O - https://downloads.cdn.openwrt.org/${{ env.TOOLCHAIN_PATH }}/targets/${{ env.TARGET }}/${{ env.SUBTARGET }}/${{ env.TOOLCHAIN_FILE }}.tar.xz \
218 | tar --xz -xf -
219
220 - name: Extract prebuilt tools
221 shell: su buildbot -c "sh -e {0}"
222 working-directory: openwrt
223 run: ./scripts/ext-tools.sh --tools /tools.tar
224
225 - name: Configure testing kernel
226 if: inputs.testing == true
227 shell: su buildbot -c "sh -e {0}"
228 working-directory: openwrt
229 run: |
230 echo CONFIG_TESTING_KERNEL=y >> .config
231
232 - name: Configure all kernel modules
233 if: inputs.build_all_kmods == true
234 shell: su buildbot -c "sh -e {0}"
235 working-directory: openwrt
236 run: |
237 echo CONFIG_ALL_KMODS=y >> .config
238
239 - name: Configure all modules
240 if: inputs.build_all_modules == true
241 shell: su buildbot -c "sh -e {0}"
242 working-directory: openwrt
243 run: |
244 echo CONFIG_ALL=y >> .config
245
246 - name: Configure all boards
247 if: inputs.build_all_boards == true
248 shell: su buildbot -c "sh -e {0}"
249 working-directory: openwrt
250 run: |
251 echo CONFIG_TARGET_MULTI_PROFILE=y >> .config
252 echo CONFIG_TARGET_PER_DEVICE_ROOTFS=y >> .config
253 echo CONFIG_TARGET_ALL_PROFILES=y >> .config
254
255 - name: Configure external toolchain
256 if: inputs.build_toolchain == false && steps.parse-toolchain.outputs.toolchain-type == 'external_toolchain'
257 shell: su buildbot -c "sh -e {0}"
258 working-directory: openwrt
259 run: |
260 echo CONFIG_DEVEL=y >> .config
261 echo CONFIG_AUTOREMOVE=y >> .config
262 echo CONFIG_CCACHE=y >> .config
263
264 ./scripts/ext-toolchain.sh \
265 --toolchain ${{ env.TOOLCHAIN_FILE }}/toolchain-* \
266 --overwrite-config \
267 --config ${{ env.TARGET }}/${{ env.SUBTARGET }}
268
269 - name: Adapt external sdk to external toolchain format
270 if: inputs.build_toolchain == false && steps.parse-toolchain.outputs.toolchain-type == 'external_sdk' && steps.cache-external-toolchain.outputs.cache-hit != 'true'
271 shell: su buildbot -c "sh -e {0}"
272 working-directory: openwrt
273 run: |
274 TOOLCHAIN_DIR=${{ env.TOOLCHAIN_FILE }}/staging_dir/$(ls ${{ env.TOOLCHAIN_FILE }}/staging_dir | grep toolchain)
275 TOOLCHAIN_BIN=$TOOLCHAIN_DIR/bin
276 OPENWRT_DIR=$(pwd)
277
278 # Find target name from toolchain info.mk
279 GNU_TARGET_NAME=$(cat $TOOLCHAIN_DIR/info.mk | grep TARGET_CROSS | sed 's/^TARGET_CROSS=\(.*\)-$/\1/')
280
281 cd $TOOLCHAIN_BIN
282
283 # Revert sdk wrapper scripts applied to all the bins
284 for app in $(find . -name "*.bin"); do
285 TARGET_APP=$(echo $app | sed 's/\.\/\.\(.*\)\.bin/\1/')
286 rm $TARGET_APP
287 mv .$TARGET_APP.bin $TARGET_APP
288 done
289
290 # Setup the wrapper script in the sdk toolchain dir simulating an external toolchain build
291 cp $OPENWRT_DIR/target/toolchain/files/wrapper.sh $GNU_TARGET_NAME-wrapper.sh
292 for app in cc gcc g++ c++ cpp ld as ; do
293 [ -f $GNU_TARGET_NAME-$app ] && mv $GNU_TARGET_NAME-$app $GNU_TARGET_NAME-$app.bin
294 ln -sf $GNU_TARGET_NAME-wrapper.sh $GNU_TARGET_NAME-$app
295 done
296
297 - name: Configure external toolchain with sdk
298 if: inputs.build_toolchain == false && steps.parse-toolchain.outputs.toolchain-type == 'external_sdk'
299 shell: su buildbot -c "sh -e {0}"
300 working-directory: openwrt
301 run: |
302 echo CONFIG_DEVEL=y >> .config
303 echo CONFIG_AUTOREMOVE=y >> .config
304 echo CONFIG_CCACHE=y >> .config
305
306 ./scripts/ext-toolchain.sh \
307 --toolchain ${{ env.TOOLCHAIN_FILE }}/staging_dir/toolchain-* \
308 --overwrite-config \
309 --config ${{ env.TARGET }}/${{ env.SUBTARGET }}
310
311 - name: Configure internal toolchain
312 if: inputs.build_toolchain == true
313 shell: su buildbot -c "sh -e {0}"
314 working-directory: openwrt
315 run: |
316 echo CONFIG_DEVEL=y >> .config
317 echo CONFIG_AUTOREMOVE=y >> .config
318 echo CONFIG_CCACHE=y >> .config
319
320 echo "CONFIG_TARGET_${{ env.TARGET }}=y" >> .config
321 echo "CONFIG_TARGET_${{ env.TARGET }}_${{ env.SUBTARGET }}=y" >> .config
322
323 make defconfig
324
325 - name: Show configuration
326 shell: su buildbot -c "sh -e {0}"
327 working-directory: openwrt
328 run: ./scripts/diffconfig.sh
329
330 - name: Build tools
331 shell: su buildbot -c "sh -e {0}"
332 working-directory: openwrt
333 run: make tools/install -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
334
335 - name: Build toolchain
336 shell: su buildbot -c "sh -e {0}"
337 working-directory: openwrt
338 run: make toolchain/install -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
339
340 - name: Build Kernel
341 shell: su buildbot -c "sh -e {0}"
342 working-directory: openwrt
343 run: make target/compile -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
344
345 - name: Build Kernel Kmods
346 shell: su buildbot -c "sh -e {0}"
347 working-directory: openwrt
348 run: make package/linux/compile -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
349
350 - name: Build everything
351 if: inputs.build_full == true
352 shell: su buildbot -c "sh -e {0}"
353 working-directory: openwrt
354 run: make -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
355
356 - name: Upload logs
357 if: failure()
358 uses: actions/upload-artifact@v3
359 with:
360 name: ${{ env.TARGET }}-${{ env.SUBTARGET }}-logs
361 path: "openwrt/logs"