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 container_tag: ${{ steps.determine_tools_container.outputs.container_tag }}
68 container_name: ${{ steps.determine_tools_container.outputs.container_name }}
72 uses: actions/checkout@v3
74 - name: Set lower case owner name
77 OWNER_LC=$(echo "${{ github.repository_owner }}" \
78 | tr '[:upper:]' '[:lower:]')
80 if [ ${{ inputs.use_openwrt_container }} == "true" ]; then
84 echo "owner_lc=$OWNER_LC" >> $GITHUB_OUTPUT
86 # Per branch tools container tag
87 # By default stick to latest
88 # For official test targetting openwrt stable branch
89 # Get the branch or parse the tag and push dedicated tools containers
90 # For local test to use the correct container for stable release testing
91 # you need to use for the branch name a prefix of openwrt-[0-9][0-9].[0-9][0-9]-
92 - name: Determine tools container tag
93 id: determine_tools_container
95 CONTAINER_NAME=${{ inputs.container_name }}
97 if [ -n "${{ github.base_ref }}" ]; then
98 if echo "${{ github.base_ref }}" | grep -q -E '^openwrt-[0-9][0-9]\.[0-9][0-9]$'; then
99 CONTAINER_TAG="${{ github.base_ref }}"
101 elif [ ${{ github.ref_type }} == "branch" ]; then
102 if echo "${{ github.ref_name }}" | grep -q -E '^openwrt-[0-9][0-9]\.[0-9][0-9]$'; then
103 CONTAINER_TAG=${{ github.ref_name }}
104 elif echo "${{ github.ref_name }}" | grep -q -E '^openwrt-[0-9][0-9]\.[0-9][0-9]-'; then
105 CONTAINER_TAG="$(echo ${{ github.ref_name }} | sed 's/^\(openwrt-[0-9][0-9]\.[0-9][0-9]\)-.*/\1/')"
107 elif [ ${{ github.ref_type }} == "tag" ]; then
108 if echo "${{ github.ref_name }}" | grep -q -E '^v[0-9][0-9]\.[0-9][0-9]\..+'; then
109 CONTAINER_TAG=openwrt-"$(echo ${{ github.ref_name }} | sed 's/^v\([0-9][0-9]\.[0-9][0-9]\)\..\+/\1/')"
113 if [ "$CONTAINER_NAME" = "toolchain" ]; then
114 GHCR_TOKEN=$(echo ${{ secrets.GITHUB_TOKEN }} | base64)
115 GHCR_HEADER="Authorization: Bearer ${GHCR_TOKEN}"
116 GHCR_MANIFEST_LINK=https://ghcr.io/v2/${{ steps.lower_owner.outputs.owner_lc }}/${{ inputs.container_name }}/manifests/${{ inputs.target }}-${{ inputs.subtarget }}-"$CONTAINER_TAG"
117 # Check if container exist
118 if [ $(curl -s -o /dev/null -w "%{http_code}" -H "$GHCR_HEADER" -I "$GHCR_MANIFEST_LINK") = 200 ]; then
119 CONTAINER_TAG=${{ inputs.target }}-${{ inputs.subtarget }}-"$CONTAINER_TAG"
125 echo "Tools container to use $CONTAINER_NAME:$CONTAINER_TAG"
126 echo "container_tag=$CONTAINER_TAG" >> $GITHUB_OUTPUT
127 echo "container_name=$CONTAINER_NAME" >> $GITHUB_OUTPUT
130 name: Build ${{ inputs.target }}/${{ inputs.subtarget }}
132 runs-on: ubuntu-latest
134 container: ghcr.io/${{ needs.setup_build.outputs.owner_lc }}/${{ needs.setup_build.outputs.container_name }}:${{ needs.setup_build.outputs.container_tag }}
141 - name: Checkout master directory
142 uses: actions/checkout@v3
146 - name: Checkout packages feed
147 if: inputs.include_feeds == true
148 uses: actions/checkout@v3
150 repository: openwrt/packages
151 path: openwrt/feeds/packages
153 - name: Checkout luci feed
154 if: inputs.include_feeds == true
155 uses: actions/checkout@v3
157 repository: openwrt/luci
158 path: openwrt/feeds/luci
160 - name: Checkout routing feed
161 if: inputs.include_feeds == true
162 uses: actions/checkout@v3
164 repository: openwrt/routing
165 path: openwrt/feeds/routing
167 - name: Checkout telephony feed
168 if: inputs.include_feeds == true
169 uses: actions/checkout@v3
171 repository: openwrt/telephony
172 path: openwrt/feeds/telephony
174 - name: Parse toolchain file
175 if: inputs.build_toolchain == false
177 working-directory: openwrt
179 if [ -d /external-toolchain/ ]; then
180 echo "toolchain-type=external_container" >> $GITHUB_OUTPUT
184 TOOLCHAIN_PATH=snapshots
186 if [ -n "${{ github.base_ref }}" ]; then
187 if echo "${{ github.base_ref }}" | grep -q -E '^openwrt-[0-9][0-9]\.[0-9][0-9]$'; then
188 major_ver="$(echo ${{ github.base_ref }} | sed 's/^openwrt-/v/')"
190 elif [ "${{ github.ref_type }}" = "branch" ]; then
191 if echo "${{ github.ref_name }}" | grep -q -E '^openwrt-[0-9][0-9]\.[0-9][0-9]$'; then
192 major_ver="$(echo ${{ github.ref_name }} | sed 's/^openwrt-/v/')"
193 elif echo "${{ github.ref_name }}" | grep -q -E '^openwrt-[0-9][0-9]\.[0-9][0-9]-'; then
194 major_ver="$(echo ${{ github.ref_name }} | sed 's/^openwrt-\([0-9][0-9]\.[0-9][0-9]\)-.*/v\1/')"
196 elif [ "${{ github.ref_type }}" = "tag" ]; then
197 if echo "${{ github.ref_name }}" | grep -q -E '^v[0-9][0-9]\.[0-9][0-9]\..+'; then
198 major_ver="$(echo ${{ github.ref_name }} | sed 's/^\(v[0-9][0-9]\.[0-9][0-9]\)\..\+/\1/')"
202 if [ -n "$major_ver" ]; then
204 latest_tag="$(git tag --sort=-creatordate -l $major_ver* | head -n1)"
205 if [ -n "$latest_tag" ]; then
206 TOOLCHAIN_PATH=releases/$(echo $latest_tag | sed 's/^v//')
210 SUMS_FILE="https://downloads.cdn.openwrt.org/$TOOLCHAIN_PATH/targets/${{ inputs.target }}/${{ inputs.subtarget }}/sha256sums"
211 if curl $SUMS_FILE | grep -q ".*openwrt-toolchain.*tar.xz"; then
212 TOOLCHAIN_STRING="$( curl $SUMS_FILE | grep ".*openwrt-toolchain.*tar.xz")"
213 TOOLCHAIN_FILE=$(echo "$TOOLCHAIN_STRING" | sed -n -e 's/.*\(openwrt-toolchain.*\).tar.xz/\1/p')
215 echo "toolchain-type=external_toolchain" >> $GITHUB_OUTPUT
216 elif curl $SUMS_FILE | grep -q ".*openwrt-sdk.*tar.xz"; then
217 TOOLCHAIN_STRING="$( curl $SUMS_FILE | grep ".*openwrt-sdk.*tar.xz")"
218 TOOLCHAIN_FILE=$(echo "$TOOLCHAIN_STRING" | sed -n -e 's/.*\(openwrt-sdk.*\).tar.xz/\1/p')
220 echo "toolchain-type=external_sdk" >> $GITHUB_OUTPUT
222 echo "toolchain-type=internal" >> $GITHUB_OUTPUT
225 echo "TOOLCHAIN_FILE=$TOOLCHAIN_FILE" >> "$GITHUB_ENV"
226 echo "TOOLCHAIN_PATH=$TOOLCHAIN_PATH" >> "$GITHUB_ENV"
228 - name: Fix permission
230 chown -R buildbot:buildbot openwrt
232 - name: Prepare prebuilt tools
233 shell: su buildbot -c "sh -e {0}"
234 working-directory: openwrt
236 mkdir -p staging_dir build_dir
237 ln -s /prebuilt_tools/staging_dir/host staging_dir/host
238 ln -s /prebuilt_tools/build_dir/host build_dir/host
240 ./scripts/ext-tools.sh --refresh
242 - name: Update & Install feeds
243 if: inputs.include_feeds == true
244 shell: su buildbot -c "sh -e {0}"
245 working-directory: openwrt
247 ./scripts/feeds update -a
248 ./scripts/feeds install -a
250 - name: Restore ccache cache
251 id: restore-ccache-cache
252 uses: actions/cache/restore@v3
254 path: openwrt/.ccache
255 key: ccache-kernel-${{ inputs.target }}/${{ inputs.subtarget }}-${{ hashFiles('openwrt/include/kernel-**') }}
257 ccache-kernel-${{ inputs.target }}/${{ inputs.subtarget }}-
259 - name: Download external toolchain/sdk
260 if: inputs.build_toolchain == false && steps.parse-toolchain.outputs.toolchain-type != 'internal' && steps.parse-toolchain.outputs.toolchain-type != 'external_container'
261 shell: su buildbot -c "sh -e {0}"
262 working-directory: openwrt
264 wget -O - https://downloads.cdn.openwrt.org/${{ env.TOOLCHAIN_PATH }}/targets/${{ inputs.target }}/${{ inputs.subtarget }}/${{ env.TOOLCHAIN_FILE }}.tar.xz \
267 - name: Configure testing kernel
268 if: inputs.testing == true
269 shell: su buildbot -c "sh -e {0}"
270 working-directory: openwrt
272 echo CONFIG_TESTING_KERNEL=y >> .config
274 - name: Configure all kernel modules
275 if: inputs.build_all_kmods == true
276 shell: su buildbot -c "sh -e {0}"
277 working-directory: openwrt
279 echo CONFIG_ALL_KMODS=y >> .config
281 - name: Configure all modules
282 if: inputs.build_all_modules == true
283 shell: su buildbot -c "sh -e {0}"
284 working-directory: openwrt
286 echo CONFIG_ALL=y >> .config
288 - name: Configure all boards
289 if: inputs.build_all_boards == true
290 shell: su buildbot -c "sh -e {0}"
291 working-directory: openwrt
293 echo CONFIG_TARGET_MULTI_PROFILE=y >> .config
294 echo CONFIG_TARGET_PER_DEVICE_ROOTFS=y >> .config
295 echo CONFIG_TARGET_ALL_PROFILES=y >> .config
297 - name: Configure external toolchain in container
298 if: inputs.build_toolchain == false && steps.parse-toolchain.outputs.toolchain-type == 'external_container'
299 shell: su buildbot -c "sh -e {0}"
300 working-directory: openwrt
302 echo CONFIG_DEVEL=y >> .config
303 echo CONFIG_AUTOREMOVE=y >> .config
304 echo CONFIG_CCACHE=y >> .config
306 ./scripts/ext-toolchain.sh \
307 --toolchain /external-toolchain/$(ls /external-toolchain/ | grep openwrt-toolchain)/toolchain-* \
309 --config ${{ inputs.target }}/${{ inputs.subtarget }}
311 - name: Configure external toolchain
312 if: inputs.build_toolchain == false && steps.parse-toolchain.outputs.toolchain-type == 'external_toolchain'
313 shell: su buildbot -c "sh -e {0}"
314 working-directory: openwrt
316 echo CONFIG_DEVEL=y >> .config
317 echo CONFIG_AUTOREMOVE=y >> .config
318 echo CONFIG_CCACHE=y >> .config
320 ./scripts/ext-toolchain.sh \
321 --toolchain ${{ env.TOOLCHAIN_FILE }}/toolchain-* \
323 --config ${{ inputs.target }}/${{ inputs.subtarget }}
325 - name: Adapt external sdk to external toolchain format
326 if: inputs.build_toolchain == false && steps.parse-toolchain.outputs.toolchain-type == 'external_sdk'
327 shell: su buildbot -c "sh -e {0}"
328 working-directory: openwrt
330 TOOLCHAIN_DIR=${{ env.TOOLCHAIN_FILE }}/staging_dir/$(ls ${{ env.TOOLCHAIN_FILE }}/staging_dir | grep toolchain)
331 TOOLCHAIN_BIN=$TOOLCHAIN_DIR/bin
334 # Find target name from toolchain info.mk
335 GNU_TARGET_NAME=$(cat $TOOLCHAIN_DIR/info.mk | grep TARGET_CROSS | sed 's/^TARGET_CROSS=\(.*\)-$/\1/')
339 # Revert sdk wrapper scripts applied to all the bins
340 for app in $(find . -name "*.bin"); do
341 TARGET_APP=$(echo $app | sed 's/\.\/\.\(.*\)\.bin/\1/')
343 mv .$TARGET_APP.bin $TARGET_APP
346 # Setup the wrapper script in the sdk toolchain dir simulating an external toolchain build
347 cp $OPENWRT_DIR/target/toolchain/files/wrapper.sh $GNU_TARGET_NAME-wrapper.sh
348 for app in cc gcc g++ c++ cpp ld as ; do
349 [ -f $GNU_TARGET_NAME-$app ] && mv $GNU_TARGET_NAME-$app $GNU_TARGET_NAME-$app.bin
350 ln -sf $GNU_TARGET_NAME-wrapper.sh $GNU_TARGET_NAME-$app
353 - name: Configure external toolchain with sdk
354 if: inputs.build_toolchain == false && steps.parse-toolchain.outputs.toolchain-type == 'external_sdk'
355 shell: su buildbot -c "sh -e {0}"
356 working-directory: openwrt
358 echo CONFIG_DEVEL=y >> .config
359 echo CONFIG_AUTOREMOVE=y >> .config
360 echo CONFIG_CCACHE=y >> .config
362 ./scripts/ext-toolchain.sh \
363 --toolchain ${{ env.TOOLCHAIN_FILE }}/staging_dir/toolchain-* \
365 --config ${{ inputs.target }}/${{ inputs.subtarget }}
367 - name: Configure internal toolchain
368 if: inputs.build_toolchain == true || steps.parse-toolchain.outputs.toolchain-type == 'internal'
369 shell: su buildbot -c "sh -e {0}"
370 working-directory: openwrt
372 echo CONFIG_DEVEL=y >> .config
373 echo CONFIG_AUTOREMOVE=y >> .config
374 echo CONFIG_CCACHE=y >> .config
376 echo "CONFIG_TARGET_${{ inputs.target }}=y" >> .config
377 echo "CONFIG_TARGET_${{ inputs.target }}_${{ inputs.subtarget }}=y" >> .config
381 - name: Show configuration
382 shell: su buildbot -c "sh -e {0}"
383 working-directory: openwrt
384 run: ./scripts/diffconfig.sh
387 shell: su buildbot -c "sh -e {0}"
388 working-directory: openwrt
389 run: make tools/install -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
391 - name: Build toolchain
392 shell: su buildbot -c "sh -e {0}"
393 working-directory: openwrt
394 run: make toolchain/install -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
397 if: inputs.build_kernel == true
398 shell: su buildbot -c "sh -e {0}"
399 working-directory: openwrt
400 run: make target/compile -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
402 - name: Build Kernel Kmods
403 if: inputs.build_kernel == true
404 shell: su buildbot -c "sh -e {0}"
405 working-directory: openwrt
406 run: make package/linux/compile -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
408 - name: Build everything
409 if: inputs.build_full == true
410 shell: su buildbot -c "sh -e {0}"
411 working-directory: openwrt
412 run: make -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
414 - name: Build external toolchain
415 if: inputs.build_external_toolchain == true
416 shell: su buildbot -c "sh -e {0}"
417 working-directory: openwrt
418 run: make target/toolchain/compile -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
420 - name: Coverity prepare toolchain
421 if: inputs.coverity_check_packages != ''
422 shell: su buildbot -c "sh -e {0}"
423 working-directory: openwrt
425 wget -q https://scan.coverity.com/download/linux64 --post-data "token=${{ secrets.coverity_api_token }}&project=${{ inputs.coverity_project_name }}" -O coverity.tar.gz
426 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
427 echo ' coverity.tar.gz' >> coverity.tar.gz.md5
428 md5sum -c coverity.tar.gz.md5
430 mkdir cov-analysis-linux64
431 tar xzf coverity.tar.gz --strip 1 -C cov-analysis-linux64
432 export PATH=$(pwd)/cov-analysis-linux64/bin:$PATH
434 for template in ${{ inputs.coverity_compiler_template_list }}; do
435 cov-configure --template --comptype gcc --compiler "$template"
438 - name: Clean and recompile packages with Coverity toolchain
439 if: inputs.coverity_check_packages != ''
440 shell: su buildbot -c "bash {0}"
441 working-directory: openwrt
443 set -o pipefail -o errexit
445 coverity_check_packages=(${{ inputs.coverity_check_packages }})
446 printf -v clean_packages "package/%s/clean " "${coverity_check_packages[@]}"
447 make -j$(nproc) BUILD_LOG=1 $clean_packages || ret=$? .github/workflows/scripts/show_build_failures.sh
449 coverity_force_compile_packages=(${{ inputs.coverity_force_compile_packages }})
450 printf -v force_compile_packages "package/%s/compile " "${coverity_force_compile_packages[@]}"
451 make -j$(nproc) BUILD_LOG=1 $force_compile_packages || ret=$? .github/workflows/scripts/show_build_failures.sh
453 printf -v compile_packages "package/%s/compile " "${coverity_check_packages[@]}"
454 export PATH=$(pwd)/cov-analysis-linux64/bin:$PATH
455 cov-build --dir cov-int make -j $(nproc) BUILD_LOG=1 $compile_packages || ret=$? .github/workflows/scripts/show_build_failures.sh
457 - name: Upload build to Coverity for analysis
458 if: inputs.coverity_check_packages != ''
459 shell: su buildbot -c "sh -e {0}"
460 working-directory: openwrt
462 tar czf cov-int.tar.gz ./cov-int
464 --form token="${{ secrets.coverity_api_token }}" \
465 --form email="contact@openwrt.org" \
466 --form file=@cov-int.tar.gz \
467 --form version="${{ github.ref_name }}-${{ github.sha }}" \
468 --form description="OpenWrt ${{ github.ref_name }}-${{ github.sha }}" \
469 "https://scan.coverity.com/builds?project=${{ inputs.coverity_project_name }}"
473 uses: actions/upload-artifact@v3
475 name: ${{ inputs.target }}-${{ inputs.subtarget }}-logs
478 - name: Save ccache cache
479 uses: actions/cache/save@v3
481 path: openwrt/.ccache
482 key: ${{ steps.restore-ccache-cache.outputs.cache-primary-key }}
484 - name: Find external toolchain name
485 id: get-toolchain-name
486 if: inputs.upload_external_toolchain == true
487 working-directory: openwrt
489 TOOLCHAIN_NAME=$(ls bin/targets/${{inputs.target }}/${{ inputs.subtarget }} | grep toolchain)
490 echo "toolchain-name=$TOOLCHAIN_NAME" >> $GITHUB_OUTPUT
492 - name: Upload prebuilt toolchain
493 if: inputs.upload_external_toolchain == true
494 uses: actions/upload-artifact@v3
496 name: ${{ inputs.target }}-${{ inputs.subtarget }}-external-toolchain
497 path: openwrt/bin/targets/${{ inputs.target }}/${{ inputs.subtarget }}/${{ steps.get-toolchain-name.outputs.toolchain-name }}