33 use_openwrt_container:
36 coverity_project_name:
39 coverity_check_packages:
41 coverity_compiler_template_list:
45 coverity_force_compile_packages:
53 build_external_toolchain:
55 upload_external_toolchain:
63 name: Setup build ${{ inputs.target }}/${{ inputs.subtarget }}
64 runs-on: ubuntu-latest
66 owner_lc: ${{ steps.lower_owner.outputs.owner_lc }}
67 ccache_hash: ${{ steps.ccache_hash.outputs.ccache_hash }}
68 container_tag: ${{ steps.determine_tools_container.outputs.container_tag }}
69 container_name: ${{ steps.determine_tools_container.outputs.container_name }}
73 uses: actions/checkout@v3
75 - name: Set lower case owner name
78 OWNER_LC=$(echo "${{ github.repository_owner }}" \
79 | tr '[:upper:]' '[:lower:]')
81 if [ ${{ inputs.use_openwrt_container }} == "true" ]; then
85 echo "owner_lc=$OWNER_LC" >> $GITHUB_OUTPUT
87 - name: Generate ccache hash
90 CCACHE_HASH=$(md5sum include/kernel-* | awk '{ print $1 }' \
91 | md5sum | awk '{ print $1 }')
92 echo "ccache_hash=$CCACHE_HASH" >> $GITHUB_OUTPUT
94 # Per branch tools container tag
95 # By default stick to latest
96 # For official test targetting openwrt stable branch
97 # Get the branch or parse the tag and push dedicated tools containers
98 # For local test to use the correct container for stable release testing
99 # you need to use for the branch name a prefix of openwrt-[0-9][0-9].[0-9][0-9]-
100 - name: Determine tools container tag
101 id: determine_tools_container
103 CONTAINER_NAME=${{ inputs.container_name }}
105 if [ -n "${{ github.base_ref }}" ]; then
106 if echo "${{ github.base_ref }}" | grep -q -E '^openwrt-[0-9][0-9]\.[0-9][0-9]$'; then
107 CONTAINER_TAG="${{ github.base_ref }}"
109 elif [ ${{ github.ref_type }} == "branch" ]; then
110 if echo "${{ github.ref_name }}" | grep -q -E '^openwrt-[0-9][0-9]\.[0-9][0-9]$'; then
111 CONTAINER_TAG=${{ github.ref_name }}
112 elif echo "${{ github.ref_name }}" | grep -q -E '^openwrt-[0-9][0-9]\.[0-9][0-9]-'; then
113 CONTAINER_TAG="$(echo ${{ github.ref_name }} | sed 's/^\(openwrt-[0-9][0-9]\.[0-9][0-9]\)-.*/\1/')"
115 elif [ ${{ github.ref_type }} == "tag" ]; then
116 if echo "${{ github.ref_name }}" | grep -q -E '^v[0-9][0-9]\.[0-9][0-9]\..+'; then
117 CONTAINER_TAG=openwrt-"$(echo ${{ github.ref_name }} | sed 's/^v\([0-9][0-9]\.[0-9][0-9]\)\..\+/\1/')"
121 if [ "$CONTAINER_NAME" = "toolchain" ]; then
122 GHCR_TOKEN=$(echo ${{ secrets.GITHUB_TOKEN }} | base64)
123 GHCR_HEADER="Authorization: Bearer ${GHCR_TOKEN}"
124 GHCR_MANIFEST_LINK=https://ghcr.io/v2/${{ steps.lower_owner.outputs.owner_lc }}/${{ inputs.container_name }}/manifests/${{ inputs.target }}-${{ inputs.subtarget }}-"$CONTAINER_TAG"
125 # Check if container exist
126 if [ $(curl -s -o /dev/null -w "%{http_code}" -H "$GHCR_HEADER" -I "$GHCR_MANIFEST_LINK") = 200 ]; then
127 CONTAINER_TAG=${{ inputs.target }}-${{ inputs.subtarget }}-"$CONTAINER_TAG"
133 echo "Tools container to use $CONTAINER_NAME:$CONTAINER_TAG"
134 echo "container_tag=$CONTAINER_TAG" >> $GITHUB_OUTPUT
135 echo "container_name=$CONTAINER_NAME" >> $GITHUB_OUTPUT
138 name: Build ${{ inputs.target }}/${{ inputs.subtarget }}
140 runs-on: ubuntu-latest
142 container: ghcr.io/${{ needs.setup_build.outputs.owner_lc }}/${{ needs.setup_build.outputs.container_name }}:${{ needs.setup_build.outputs.container_tag }}
149 - name: Checkout master directory
150 uses: actions/checkout@v3
154 - name: Checkout packages feed
155 if: inputs.include_feeds == true
156 uses: actions/checkout@v3
158 repository: openwrt/packages
159 path: openwrt/feeds/packages
161 - name: Checkout luci feed
162 if: inputs.include_feeds == true
163 uses: actions/checkout@v3
165 repository: openwrt/luci
166 path: openwrt/feeds/luci
168 - name: Checkout routing feed
169 if: inputs.include_feeds == true
170 uses: actions/checkout@v3
172 repository: openwrt/routing
173 path: openwrt/feeds/routing
175 - name: Checkout telephony feed
176 if: inputs.include_feeds == true
177 uses: actions/checkout@v3
179 repository: openwrt/telephony
180 path: openwrt/feeds/telephony
182 - name: Parse toolchain file
183 if: inputs.build_toolchain == false
185 working-directory: openwrt
187 if [ -d /external-toolchain/ ]; then
188 echo "toolchain-type=external_container" >> $GITHUB_OUTPUT
192 TOOLCHAIN_PATH=snapshots
194 if [ -n "${{ github.base_ref }}" ]; then
195 if echo "${{ github.base_ref }}" | grep -q -E '^openwrt-[0-9][0-9]\.[0-9][0-9]$'; then
196 major_ver="$(echo ${{ github.base_ref }} | sed 's/^openwrt-/v/')"
198 elif [ "${{ github.ref_type }}" = "branch" ]; then
199 if echo "${{ github.ref_name }}" | grep -q -E '^openwrt-[0-9][0-9]\.[0-9][0-9]$'; then
200 major_ver="$(echo ${{ github.ref_name }} | sed 's/^openwrt-/v/')"
201 elif echo "${{ github.ref_name }}" | grep -q -E '^openwrt-[0-9][0-9]\.[0-9][0-9]-'; then
202 major_ver="$(echo ${{ github.ref_name }} | sed 's/^openwrt-\([0-9][0-9]\.[0-9][0-9]\)-.*/v\1/')"
204 elif [ "${{ github.ref_type }}" = "tag" ]; then
205 if echo "${{ github.ref_name }}" | grep -q -E '^v[0-9][0-9]\.[0-9][0-9]\..+'; then
206 major_ver="$(echo ${{ github.ref_name }} | sed 's/^\(v[0-9][0-9]\.[0-9][0-9]\)\..\+/\1/')"
210 if [ -n "$major_ver" ]; then
212 latest_tag="$(git tag --sort=-creatordate -l $major_ver* | head -n1)"
213 if [ -n "$latest_tag" ]; then
214 TOOLCHAIN_PATH=releases/$(echo $latest_tag | sed 's/^v//')
218 SUMS_FILE="https://downloads.cdn.openwrt.org/$TOOLCHAIN_PATH/targets/${{ inputs.target }}/${{ inputs.subtarget }}/sha256sums"
219 if curl $SUMS_FILE | grep -q ".*openwrt-toolchain.*tar.xz"; then
220 TOOLCHAIN_STRING="$( curl $SUMS_FILE | grep ".*openwrt-toolchain.*tar.xz")"
221 TOOLCHAIN_FILE=$(echo "$TOOLCHAIN_STRING" | sed -n -e 's/.*\(openwrt-toolchain.*\).tar.xz/\1/p')
223 echo "toolchain-type=external_toolchain" >> $GITHUB_OUTPUT
224 elif curl $SUMS_FILE | grep -q ".*openwrt-sdk.*tar.xz"; then
225 TOOLCHAIN_STRING="$( curl $SUMS_FILE | grep ".*openwrt-sdk.*tar.xz")"
226 TOOLCHAIN_FILE=$(echo "$TOOLCHAIN_STRING" | sed -n -e 's/.*\(openwrt-sdk.*\).tar.xz/\1/p')
228 echo "toolchain-type=external_sdk" >> $GITHUB_OUTPUT
230 echo "toolchain-type=internal" >> $GITHUB_OUTPUT
233 echo "TOOLCHAIN_FILE=$TOOLCHAIN_FILE" >> "$GITHUB_ENV"
234 echo "TOOLCHAIN_PATH=$TOOLCHAIN_PATH" >> "$GITHUB_ENV"
236 - name: Fix permission
238 chown -R buildbot:buildbot openwrt
240 - name: Prepare prebuilt tools
241 shell: su buildbot -c "sh -e {0}"
242 working-directory: openwrt
244 mkdir -p staging_dir build_dir
245 ln -s /prebuilt_tools/staging_dir/host staging_dir/host
246 ln -s /prebuilt_tools/build_dir/host build_dir/host
248 ./scripts/ext-tools.sh --refresh
250 - name: Update & Install feeds
251 if: inputs.include_feeds == true
252 shell: su buildbot -c "sh -e {0}"
253 working-directory: openwrt
255 ./scripts/feeds update -a
256 ./scripts/feeds install -a
259 uses: actions/cache@v3
261 path: openwrt/.ccache
262 key: ccache-kernel-${{ inputs.target }}/${{ inputs.subtarget }}-${{ needs.setup_build.outputs.ccache_hash }}
264 ccache-kernel-${{ inputs.target }}/${{ inputs.subtarget }}-
266 - name: Download external toolchain/sdk
267 if: inputs.build_toolchain == false && steps.parse-toolchain.outputs.toolchain-type != 'internal' && steps.parse-toolchain.outputs.toolchain-type != 'external_container'
268 shell: su buildbot -c "sh -e {0}"
269 working-directory: openwrt
271 wget -O - https://downloads.cdn.openwrt.org/${{ env.TOOLCHAIN_PATH }}/targets/${{ inputs.target }}/${{ inputs.subtarget }}/${{ env.TOOLCHAIN_FILE }}.tar.xz \
274 - name: Configure testing kernel
275 if: inputs.testing == true
276 shell: su buildbot -c "sh -e {0}"
277 working-directory: openwrt
279 echo CONFIG_TESTING_KERNEL=y >> .config
281 - name: Configure all kernel modules
282 if: inputs.build_all_kmods == true
283 shell: su buildbot -c "sh -e {0}"
284 working-directory: openwrt
286 echo CONFIG_ALL_KMODS=y >> .config
288 - name: Configure all modules
289 if: inputs.build_all_modules == true
290 shell: su buildbot -c "sh -e {0}"
291 working-directory: openwrt
293 echo CONFIG_ALL=y >> .config
295 - name: Configure all boards
296 if: inputs.build_all_boards == true
297 shell: su buildbot -c "sh -e {0}"
298 working-directory: openwrt
300 echo CONFIG_TARGET_MULTI_PROFILE=y >> .config
301 echo CONFIG_TARGET_PER_DEVICE_ROOTFS=y >> .config
302 echo CONFIG_TARGET_ALL_PROFILES=y >> .config
304 - name: Configure external toolchain in container
305 if: inputs.build_toolchain == false && steps.parse-toolchain.outputs.toolchain-type == 'external_container'
306 shell: su buildbot -c "sh -e {0}"
307 working-directory: openwrt
309 echo CONFIG_DEVEL=y >> .config
310 echo CONFIG_AUTOREMOVE=y >> .config
311 echo CONFIG_CCACHE=y >> .config
313 ./scripts/ext-toolchain.sh \
314 --toolchain /external-toolchain/$(ls /external-toolchain/ | grep openwrt-toolchain)/toolchain-* \
316 --config ${{ inputs.target }}/${{ inputs.subtarget }}
318 - name: Configure external toolchain
319 if: inputs.build_toolchain == false && steps.parse-toolchain.outputs.toolchain-type == 'external_toolchain'
320 shell: su buildbot -c "sh -e {0}"
321 working-directory: openwrt
323 echo CONFIG_DEVEL=y >> .config
324 echo CONFIG_AUTOREMOVE=y >> .config
325 echo CONFIG_CCACHE=y >> .config
327 ./scripts/ext-toolchain.sh \
328 --toolchain ${{ env.TOOLCHAIN_FILE }}/toolchain-* \
330 --config ${{ inputs.target }}/${{ inputs.subtarget }}
332 - name: Adapt external sdk to external toolchain format
333 if: inputs.build_toolchain == false && steps.parse-toolchain.outputs.toolchain-type == 'external_sdk'
334 shell: su buildbot -c "sh -e {0}"
335 working-directory: openwrt
337 TOOLCHAIN_DIR=${{ env.TOOLCHAIN_FILE }}/staging_dir/$(ls ${{ env.TOOLCHAIN_FILE }}/staging_dir | grep toolchain)
338 TOOLCHAIN_BIN=$TOOLCHAIN_DIR/bin
341 # Find target name from toolchain info.mk
342 GNU_TARGET_NAME=$(cat $TOOLCHAIN_DIR/info.mk | grep TARGET_CROSS | sed 's/^TARGET_CROSS=\(.*\)-$/\1/')
346 # Revert sdk wrapper scripts applied to all the bins
347 for app in $(find . -name "*.bin"); do
348 TARGET_APP=$(echo $app | sed 's/\.\/\.\(.*\)\.bin/\1/')
350 mv .$TARGET_APP.bin $TARGET_APP
353 # Setup the wrapper script in the sdk toolchain dir simulating an external toolchain build
354 cp $OPENWRT_DIR/target/toolchain/files/wrapper.sh $GNU_TARGET_NAME-wrapper.sh
355 for app in cc gcc g++ c++ cpp ld as ; do
356 [ -f $GNU_TARGET_NAME-$app ] && mv $GNU_TARGET_NAME-$app $GNU_TARGET_NAME-$app.bin
357 ln -sf $GNU_TARGET_NAME-wrapper.sh $GNU_TARGET_NAME-$app
360 - name: Configure external toolchain with sdk
361 if: inputs.build_toolchain == false && steps.parse-toolchain.outputs.toolchain-type == 'external_sdk'
362 shell: su buildbot -c "sh -e {0}"
363 working-directory: openwrt
365 echo CONFIG_DEVEL=y >> .config
366 echo CONFIG_AUTOREMOVE=y >> .config
367 echo CONFIG_CCACHE=y >> .config
369 ./scripts/ext-toolchain.sh \
370 --toolchain ${{ env.TOOLCHAIN_FILE }}/staging_dir/toolchain-* \
372 --config ${{ inputs.target }}/${{ inputs.subtarget }}
374 - name: Configure internal toolchain
375 if: inputs.build_toolchain == true || steps.parse-toolchain.outputs.toolchain-type == 'internal'
376 shell: su buildbot -c "sh -e {0}"
377 working-directory: openwrt
379 echo CONFIG_DEVEL=y >> .config
380 echo CONFIG_AUTOREMOVE=y >> .config
381 echo CONFIG_CCACHE=y >> .config
383 echo "CONFIG_TARGET_${{ inputs.target }}=y" >> .config
384 echo "CONFIG_TARGET_${{ inputs.target }}_${{ inputs.subtarget }}=y" >> .config
388 - name: Show configuration
389 shell: su buildbot -c "sh -e {0}"
390 working-directory: openwrt
391 run: ./scripts/diffconfig.sh
394 shell: su buildbot -c "sh -e {0}"
395 working-directory: openwrt
396 run: make tools/install -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
398 - name: Build toolchain
399 shell: su buildbot -c "sh -e {0}"
400 working-directory: openwrt
401 run: make toolchain/install -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
404 if: inputs.build_kernel == true
405 shell: su buildbot -c "sh -e {0}"
406 working-directory: openwrt
407 run: make target/compile -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
409 - name: Build Kernel Kmods
410 if: inputs.build_kernel == true
411 shell: su buildbot -c "sh -e {0}"
412 working-directory: openwrt
413 run: make package/linux/compile -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
415 - name: Build everything
416 if: inputs.build_full == true
417 shell: su buildbot -c "sh -e {0}"
418 working-directory: openwrt
419 run: make -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
421 - name: Build external toolchain
422 if: inputs.build_external_toolchain == true
423 shell: su buildbot -c "sh -e {0}"
424 working-directory: openwrt
425 run: make target/toolchain/compile -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
427 - name: Coverity prepare toolchain
428 if: inputs.coverity_check_packages != ''
429 shell: su buildbot -c "sh -e {0}"
430 working-directory: openwrt
432 wget -q https://scan.coverity.com/download/linux64 --post-data "token=${{ secrets.coverity_api_token }}&project=${{ inputs.coverity_project_name }}" -O coverity.tar.gz
433 wget -q https://scan.coverity.com/download/linux64 --post-data "token=${{ secrets.coverity_api_token }}&project=${{ inputs.coverity_project_name }}&md5=1" -O coverity.tar.gz.md5
434 echo ' coverity.tar.gz' >> coverity.tar.gz.md5
435 md5sum -c coverity.tar.gz.md5
437 mkdir cov-analysis-linux64
438 tar xzf coverity.tar.gz --strip 1 -C cov-analysis-linux64
439 export PATH=$(pwd)/cov-analysis-linux64/bin:$PATH
441 for template in ${{ inputs.coverity_compiler_template_list }}; do
442 cov-configure --template --comptype gcc --compiler "$template"
445 - name: Clean and recompile packages with Coverity toolchain
446 if: inputs.coverity_check_packages != ''
447 shell: su buildbot -c "bash {0}"
448 working-directory: openwrt
450 set -o pipefail -o errexit
452 coverity_check_packages=(${{ inputs.coverity_check_packages }})
453 printf -v clean_packages "package/%s/clean " "${coverity_check_packages[@]}"
454 make -j$(nproc) BUILD_LOG=1 $clean_packages || ret=$? .github/workflows/scripts/show_build_failures.sh
456 coverity_force_compile_packages=(${{ inputs.coverity_force_compile_packages }})
457 printf -v force_compile_packages "package/%s/compile " "${coverity_force_compile_packages[@]}"
458 make -j$(nproc) BUILD_LOG=1 $force_compile_packages || ret=$? .github/workflows/scripts/show_build_failures.sh
460 printf -v compile_packages "package/%s/compile " "${coverity_check_packages[@]}"
461 export PATH=$(pwd)/cov-analysis-linux64/bin:$PATH
462 cov-build --dir cov-int make -j $(nproc) BUILD_LOG=1 $compile_packages || ret=$? .github/workflows/scripts/show_build_failures.sh
464 - name: Upload build to Coverity for analysis
465 if: inputs.coverity_check_packages != ''
466 shell: su buildbot -c "sh -e {0}"
467 working-directory: openwrt
469 tar czf cov-int.tar.gz ./cov-int
471 --form token="${{ secrets.coverity_api_token }}" \
472 --form email="contact@openwrt.org" \
473 --form file=@cov-int.tar.gz \
474 --form version="${{ github.ref_name }}-${{ github.sha }}" \
475 --form description="OpenWrt ${{ github.ref_name }}-${{ github.sha }}" \
476 "https://scan.coverity.com/builds?project=${{ inputs.coverity_project_name }}"
480 uses: actions/upload-artifact@v3
482 name: ${{ inputs.target }}-${{ inputs.subtarget }}-logs
485 - name: Find external toolchain name
486 id: get-toolchain-name
487 if: inputs.upload_external_toolchain == true
488 working-directory: openwrt
490 TOOLCHAIN_NAME=$(ls bin/targets/${{inputs.target }}/${{ inputs.subtarget }} | grep toolchain)
491 echo "toolchain-name=$TOOLCHAIN_NAME" >> $GITHUB_OUTPUT
493 - name: Upload prebuilt toolchain
494 if: inputs.upload_external_toolchain == true
495 uses: actions/upload-artifact@v3
497 name: ${{ inputs.target }}-${{ inputs.subtarget }}-external-toolchain
498 path: openwrt/bin/targets/${{ inputs.target }}/${{ inputs.subtarget }}/${{ steps.get-toolchain-name.outputs.toolchain-name }}