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:
71 name: Setup build ${{ inputs.target }}/${{ inputs.subtarget }}
72 runs-on: ubuntu-latest
74 owner_lc: ${{ steps.lower_owner.outputs.owner_lc }}
75 container_tag: ${{ steps.determine_tools_container.outputs.container_tag }}
76 container_name: ${{ steps.determine_tools_container.outputs.container_name }}
80 uses: actions/checkout@v3
82 - name: Set lower case owner name
85 OWNER_LC=$(echo "${{ github.repository_owner }}" \
86 | tr '[:upper:]' '[:lower:]')
88 if [ ${{ inputs.use_openwrt_container }} == "true" ]; then
92 echo "owner_lc=$OWNER_LC" >> $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 }}
150 - name: Checkout master directory
151 uses: actions/checkout@v3
155 - name: Checkout packages feed
156 if: inputs.include_feeds == true
157 uses: actions/checkout@v3
159 repository: openwrt/packages
160 path: openwrt/feeds/packages
162 - name: Checkout luci feed
163 if: inputs.include_feeds == true
164 uses: actions/checkout@v3
166 repository: openwrt/luci
167 path: openwrt/feeds/luci
169 - name: Checkout routing feed
170 if: inputs.include_feeds == true
171 uses: actions/checkout@v3
173 repository: openwrt/routing
174 path: openwrt/feeds/routing
176 - name: Checkout telephony feed
177 if: inputs.include_feeds == true
178 uses: actions/checkout@v3
180 repository: openwrt/telephony
181 path: openwrt/feeds/telephony
183 - name: Parse toolchain file
184 if: inputs.build_toolchain == false
186 working-directory: openwrt
188 if [ -d /external-toolchain/ ]; then
189 echo "toolchain-type=external_container" >> $GITHUB_OUTPUT
193 TOOLCHAIN_PATH=snapshots
195 if [ -n "${{ github.base_ref }}" ]; then
196 if echo "${{ github.base_ref }}" | grep -q -E '^openwrt-[0-9][0-9]\.[0-9][0-9]$'; then
197 major_ver="$(echo ${{ github.base_ref }} | sed 's/^openwrt-/v/')"
199 elif [ "${{ github.ref_type }}" = "branch" ]; then
200 if echo "${{ github.ref_name }}" | grep -q -E '^openwrt-[0-9][0-9]\.[0-9][0-9]$'; then
201 major_ver="$(echo ${{ github.ref_name }} | sed 's/^openwrt-/v/')"
202 elif echo "${{ github.ref_name }}" | grep -q -E '^openwrt-[0-9][0-9]\.[0-9][0-9]-'; then
203 major_ver="$(echo ${{ github.ref_name }} | sed 's/^openwrt-\([0-9][0-9]\.[0-9][0-9]\)-.*/v\1/')"
205 elif [ "${{ github.ref_type }}" = "tag" ]; then
206 if echo "${{ github.ref_name }}" | grep -q -E '^v[0-9][0-9]\.[0-9][0-9]\..+'; then
207 major_ver="$(echo ${{ github.ref_name }} | sed 's/^\(v[0-9][0-9]\.[0-9][0-9]\)\..\+/\1/')"
211 if [ -n "$major_ver" ]; then
213 latest_tag="$(git tag --sort=-creatordate -l $major_ver* | head -n1)"
214 if [ -n "$latest_tag" ]; then
215 TOOLCHAIN_PATH=releases/$(echo $latest_tag | sed 's/^v//')
219 SUMS_FILE="https://downloads.cdn.openwrt.org/$TOOLCHAIN_PATH/targets/${{ inputs.target }}/${{ inputs.subtarget }}/sha256sums"
220 if curl $SUMS_FILE | grep -q ".*openwrt-toolchain.*tar.xz"; then
221 TOOLCHAIN_STRING="$( curl $SUMS_FILE | grep ".*openwrt-toolchain.*tar.xz")"
222 TOOLCHAIN_FILE=$(echo "$TOOLCHAIN_STRING" | sed -n -e 's/.*\(openwrt-toolchain.*\).tar.xz/\1/p')
224 echo "toolchain-type=external_toolchain" >> $GITHUB_OUTPUT
225 elif curl $SUMS_FILE | grep -q ".*openwrt-sdk.*tar.xz"; then
226 TOOLCHAIN_STRING="$( curl $SUMS_FILE | grep ".*openwrt-sdk.*tar.xz")"
227 TOOLCHAIN_FILE=$(echo "$TOOLCHAIN_STRING" | sed -n -e 's/.*\(openwrt-sdk.*\).tar.xz/\1/p')
229 echo "toolchain-type=external_sdk" >> $GITHUB_OUTPUT
231 echo "toolchain-type=internal" >> $GITHUB_OUTPUT
234 echo "TOOLCHAIN_FILE=$TOOLCHAIN_FILE" >> "$GITHUB_ENV"
235 echo "TOOLCHAIN_PATH=$TOOLCHAIN_PATH" >> "$GITHUB_ENV"
237 - name: Download and extract ccache cache from s3
238 id: restore-ccache-cache-s3
239 if: inputs.use_ccache_cache == true
240 working-directory: openwrt
242 ENDPOINT=https://storage.googleapis.com
243 BUCKET=openwrt-ci-cache
244 CCACHE_TAR=ccache-${{ inputs.ccache_type }}-${{ inputs.target }}-${{ inputs.subtarget }}.tar
246 if curl -o /dev/null -s --head --fail $ENDPOINT/$BUCKET/$CCACHE_TAR; then
247 wget -O - $ENDPOINT/$BUCKET/$CCACHE_TAR | tar -xf -
248 echo "cache-hit=true" >> $GITHUB_OUTPUT
251 - name: Fix permission
253 chown -R buildbot:buildbot openwrt
255 - name: Prepare prebuilt tools
256 shell: su buildbot -c "sh -e {0}"
257 working-directory: openwrt
259 mkdir -p staging_dir build_dir
260 ln -s /prebuilt_tools/staging_dir/host staging_dir/host
261 ln -s /prebuilt_tools/build_dir/host build_dir/host
263 ./scripts/ext-tools.sh --refresh
265 - name: Update & Install feeds
266 if: inputs.include_feeds == true
267 shell: su buildbot -c "sh -e {0}"
268 working-directory: openwrt
270 ./scripts/feeds update -a
271 ./scripts/feeds install -a
273 - name: Restore ccache cache
274 id: restore-ccache-cache
275 if: inputs.use_ccache_cache == true && steps.restore-ccache-cache-s3.outputs.cache-hit != 'true'
276 uses: actions/cache/restore@v3
278 path: openwrt/.ccache
279 key: ccache-${{ inputs.ccache_type }}-${{ inputs.target }}/${{ inputs.subtarget }}-${{ hashFiles('openwrt/include/kernel-**') }}
281 ccache-${{ inputs.ccache_type }}-${{ inputs.target }}/${{ inputs.subtarget }}-
283 - name: Download external toolchain/sdk
284 if: inputs.build_toolchain == false && steps.parse-toolchain.outputs.toolchain-type != 'internal' && steps.parse-toolchain.outputs.toolchain-type != 'external_container'
285 shell: su buildbot -c "sh -e {0}"
286 working-directory: openwrt
288 wget -O - https://downloads.cdn.openwrt.org/${{ env.TOOLCHAIN_PATH }}/targets/${{ inputs.target }}/${{ inputs.subtarget }}/${{ env.TOOLCHAIN_FILE }}.tar.xz \
291 - name: Configure testing kernel
292 if: inputs.testing == true
293 shell: su buildbot -c "sh -e {0}"
294 working-directory: openwrt
296 echo CONFIG_TESTING_KERNEL=y >> .config
298 - name: Configure all kernel modules
299 if: inputs.build_all_kmods == true
300 shell: su buildbot -c "sh -e {0}"
301 working-directory: openwrt
303 echo CONFIG_ALL_KMODS=y >> .config
305 - name: Configure all modules
306 if: inputs.build_all_modules == true
307 shell: su buildbot -c "sh -e {0}"
308 working-directory: openwrt
310 echo CONFIG_ALL=y >> .config
312 - name: Configure all boards
313 if: inputs.build_all_boards == true
314 shell: su buildbot -c "sh -e {0}"
315 working-directory: openwrt
317 echo CONFIG_TARGET_MULTI_PROFILE=y >> .config
318 echo CONFIG_TARGET_PER_DEVICE_ROOTFS=y >> .config
319 echo CONFIG_TARGET_ALL_PROFILES=y >> .config
321 # ccache for some reason have problem detecting compiler type
322 # with external toolchain. This cause the complete malfunction
323 # of ccache with the result of tons of unsupported compiler
325 # To fix this force compiler type to gcc.
326 - name: Configure ccache and apply fixes
327 if: inputs.use_ccache_cache == true
328 shell: su buildbot -c "sh -e {0}"
329 working-directory: openwrt
331 SYSTEM_CCACHE_CONF: staging_dir/host/etc/ccache.conf
333 touch $SYSTEM_CCACHE_CONF
335 echo compiler_type=gcc >> $SYSTEM_CCACHE_CONF
337 echo CONFIG_CCACHE=y >> .config
339 - name: Configure external toolchain in container
340 if: inputs.build_toolchain == false && steps.parse-toolchain.outputs.toolchain-type == 'external_container'
341 shell: su buildbot -c "sh -e {0}"
342 working-directory: openwrt
344 echo CONFIG_DEVEL=y >> .config
345 echo CONFIG_AUTOREMOVE=y >> .config
347 ./scripts/ext-toolchain.sh \
348 --toolchain /external-toolchain/$(ls /external-toolchain/ | grep openwrt-toolchain)/toolchain-* \
350 --config ${{ inputs.target }}/${{ inputs.subtarget }}
352 - name: Configure external toolchain
353 if: inputs.build_toolchain == false && steps.parse-toolchain.outputs.toolchain-type == 'external_toolchain'
354 shell: su buildbot -c "sh -e {0}"
355 working-directory: openwrt
357 echo CONFIG_DEVEL=y >> .config
358 echo CONFIG_AUTOREMOVE=y >> .config
360 ./scripts/ext-toolchain.sh \
361 --toolchain ${{ env.TOOLCHAIN_FILE }}/toolchain-* \
363 --config ${{ inputs.target }}/${{ inputs.subtarget }}
365 - name: Adapt external sdk to external toolchain format
366 if: inputs.build_toolchain == false && steps.parse-toolchain.outputs.toolchain-type == 'external_sdk'
367 shell: su buildbot -c "sh -e {0}"
368 working-directory: openwrt
370 TOOLCHAIN_DIR=${{ env.TOOLCHAIN_FILE }}/staging_dir/$(ls ${{ env.TOOLCHAIN_FILE }}/staging_dir | grep toolchain)
371 TOOLCHAIN_BIN=$TOOLCHAIN_DIR/bin
374 # Find target name from toolchain info.mk
375 GNU_TARGET_NAME=$(cat $TOOLCHAIN_DIR/info.mk | grep TARGET_CROSS | sed 's/^TARGET_CROSS=\(.*\)-$/\1/')
379 # Revert sdk wrapper scripts applied to all the bins
380 for app in $(find . -name "*.bin"); do
381 TARGET_APP=$(echo $app | sed 's/\.\/\.\(.*\)\.bin/\1/')
383 mv .$TARGET_APP.bin $TARGET_APP
386 # Setup the wrapper script in the sdk toolchain dir simulating an external toolchain build
387 cp $OPENWRT_DIR/target/toolchain/files/wrapper.sh $GNU_TARGET_NAME-wrapper.sh
388 for app in cc gcc g++ c++ cpp ld as ; do
389 [ -f $GNU_TARGET_NAME-$app ] && mv $GNU_TARGET_NAME-$app $GNU_TARGET_NAME-$app.bin
390 ln -sf $GNU_TARGET_NAME-wrapper.sh $GNU_TARGET_NAME-$app
393 - name: Configure external toolchain with sdk
394 if: inputs.build_toolchain == false && steps.parse-toolchain.outputs.toolchain-type == 'external_sdk'
395 shell: su buildbot -c "sh -e {0}"
396 working-directory: openwrt
398 echo CONFIG_DEVEL=y >> .config
399 echo CONFIG_AUTOREMOVE=y >> .config
401 ./scripts/ext-toolchain.sh \
402 --toolchain ${{ env.TOOLCHAIN_FILE }}/staging_dir/toolchain-* \
404 --config ${{ inputs.target }}/${{ inputs.subtarget }}
406 - name: Configure internal toolchain
407 if: inputs.build_toolchain == true || steps.parse-toolchain.outputs.toolchain-type == 'internal'
408 shell: su buildbot -c "sh -e {0}"
409 working-directory: openwrt
411 echo CONFIG_DEVEL=y >> .config
412 echo CONFIG_AUTOREMOVE=y >> .config
414 echo "CONFIG_TARGET_${{ inputs.target }}=y" >> .config
415 echo "CONFIG_TARGET_${{ inputs.target }}_${{ inputs.subtarget }}=y" >> .config
419 - name: Show configuration
420 shell: su buildbot -c "sh -e {0}"
421 working-directory: openwrt
422 run: ./scripts/diffconfig.sh
425 shell: su buildbot -c "sh -e {0}"
426 working-directory: openwrt
427 run: make tools/install -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
429 - name: Build toolchain
430 shell: su buildbot -c "sh -e {0}"
431 working-directory: openwrt
432 run: make toolchain/install -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
435 if: inputs.build_kernel == true
436 shell: su buildbot -c "sh -e {0}"
437 working-directory: openwrt
438 run: make target/compile -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
440 - name: Build Kernel Kmods
441 if: inputs.build_kernel == true
442 shell: su buildbot -c "sh -e {0}"
443 working-directory: openwrt
444 run: make package/linux/compile -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
446 - name: Build everything
447 if: inputs.build_full == true
448 shell: su buildbot -c "sh -e {0}"
449 working-directory: openwrt
450 run: make -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
452 - name: Build external toolchain
453 if: inputs.build_external_toolchain == true
454 shell: su buildbot -c "sh -e {0}"
455 working-directory: openwrt
456 run: make target/toolchain/compile -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
458 - name: Coverity prepare toolchain
459 if: inputs.coverity_check_packages != ''
460 shell: su buildbot -c "sh -e {0}"
461 working-directory: openwrt
463 wget -q https://scan.coverity.com/download/linux64 --post-data "token=${{ secrets.coverity_api_token }}&project=${{ inputs.coverity_project_name }}" -O coverity.tar.gz
464 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
465 echo ' coverity.tar.gz' >> coverity.tar.gz.md5
466 md5sum -c coverity.tar.gz.md5
468 mkdir cov-analysis-linux64
469 tar xzf coverity.tar.gz --strip 1 -C cov-analysis-linux64
470 export PATH=$(pwd)/cov-analysis-linux64/bin:$PATH
472 for template in ${{ inputs.coverity_compiler_template_list }}; do
473 cov-configure --template --comptype gcc --compiler "$template"
476 - name: Clean and recompile packages with Coverity toolchain
477 if: inputs.coverity_check_packages != ''
478 shell: su buildbot -c "bash {0}"
479 working-directory: openwrt
481 set -o pipefail -o errexit
483 coverity_check_packages=(${{ inputs.coverity_check_packages }})
484 printf -v clean_packages "package/%s/clean " "${coverity_check_packages[@]}"
485 make -j$(nproc) BUILD_LOG=1 $clean_packages || ret=$? .github/workflows/scripts/show_build_failures.sh
487 coverity_force_compile_packages=(${{ inputs.coverity_force_compile_packages }})
488 printf -v force_compile_packages "package/%s/compile " "${coverity_force_compile_packages[@]}"
489 make -j$(nproc) BUILD_LOG=1 $force_compile_packages || ret=$? .github/workflows/scripts/show_build_failures.sh
491 printf -v compile_packages "package/%s/compile " "${coverity_check_packages[@]}"
492 export PATH=$(pwd)/cov-analysis-linux64/bin:$PATH
493 cov-build --dir cov-int make -j $(nproc) BUILD_LOG=1 $compile_packages || ret=$? .github/workflows/scripts/show_build_failures.sh
495 - name: Upload build to Coverity for analysis
496 if: inputs.coverity_check_packages != ''
497 shell: su buildbot -c "sh -e {0}"
498 working-directory: openwrt
500 tar czf cov-int.tar.gz ./cov-int
502 --form token="${{ secrets.coverity_api_token }}" \
503 --form email="contact@openwrt.org" \
504 --form file=@cov-int.tar.gz \
505 --form version="${{ github.ref_name }}-${{ github.sha }}" \
506 --form description="OpenWrt ${{ github.ref_name }}-${{ github.sha }}" \
507 "https://scan.coverity.com/builds?project=${{ inputs.coverity_project_name }}"
511 uses: actions/upload-artifact@v3
513 name: ${{ inputs.target }}-${{ inputs.subtarget }}-logs
516 - name: Delete already present ccache cache
517 if: steps.restore-ccache-cache.outputs.cache-hit == 'true' && inputs.use_ccache_cache == true &&
518 github.event_name == 'push' && steps.restore-ccache-cache-s3.outputs.cache-hit != 'true'
519 uses: octokit/request-action@v2.x
521 route: DELETE /repos/{repository}/actions/caches?key={key}
523 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
524 INPUT_REPOSITORY: ${{ github.repository }}
525 INPUT_KEY: ${{ steps.restore-ccache-cache.outputs.cache-primary-key }}
527 - name: Save ccache cache
528 if: inputs.use_ccache_cache == true && github.event_name == 'push' &&
529 steps.restore-ccache-cache-s3.outputs.cache-hit != 'true'
530 uses: actions/cache/save@v3
532 path: openwrt/.ccache
533 key: ${{ steps.restore-ccache-cache.outputs.cache-primary-key }}
535 - name: Archive ccache
536 if: inputs.use_ccache_cache == true && github.event_name == 'push' &&
537 inputs.upload_ccache_cache == true
538 shell: su buildbot -c "sh -e {0}"
539 working-directory: openwrt
540 run: tar -cf ccache-${{ inputs.ccache_type }}-${{ inputs.target }}-${{ inputs.subtarget }}.tar .ccache
542 - name: Upload ccache cache
543 if: inputs.use_ccache_cache == true && github.event_name == 'push' &&
544 inputs.upload_ccache_cache == true
545 uses: actions/upload-artifact@v3
547 name: ${{ inputs.target }}-${{ inputs.subtarget }}-ccache-cache
548 path: openwrt/ccache-${{ inputs.ccache_type }}-${{ inputs.target }}-${{ inputs.subtarget }}.tar
551 - name: Find external toolchain name
552 id: get-toolchain-name
553 if: inputs.upload_external_toolchain == true
554 working-directory: openwrt
556 TOOLCHAIN_NAME=$(ls bin/targets/${{inputs.target }}/${{ inputs.subtarget }} | grep toolchain)
557 echo "toolchain-name=$TOOLCHAIN_NAME" >> $GITHUB_OUTPUT
559 - name: Upload prebuilt toolchain
560 if: inputs.upload_external_toolchain == true
561 uses: actions/upload-artifact@v3
563 name: ${{ inputs.target }}-${{ inputs.subtarget }}-external-toolchain
564 path: openwrt/bin/targets/${{ inputs.target }}/${{ inputs.subtarget }}/${{ steps.get-toolchain-name.outputs.toolchain-name }}