ci: show build failures directly in job log output
authorPetr Štetiar <ynezz@true.cz>
Mon, 22 Aug 2022 13:05:01 +0000 (15:05 +0200)
committerPetr Štetiar <ynezz@true.cz>
Tue, 20 Sep 2022 10:14:54 +0000 (12:14 +0200)
Instead of waiting for complete workflow finish, then downloading the
artifacts, unpacking them and inspecting them, lets try to make the
build failure immediately visible in the log output:

  ====== Make errors from logs/target/linux/compile.txt ======
  * Legacy (non-UHI/non-FIT) Boards
  *
  Support MIPS SEAD-3 boards (LEGACY_BOARD_SEAD3) [N/y/?] (NEW)
  Error in reading or end of file.

  make[6]: *** [scripts/kconfig/Makefile:77: syncconfig] Error 1
  make[5]: *** [Makefile:616: syncconfig] Error 2
  make[4]: *** [Makefile:736: include/config/auto.conf.cmd] Error 2
  make[3]: *** [Makefile:24: build_dir/target-mipsel-openwrt-linux-musl_musl/linux-ramips_mt7620/linux-5.15.62/.modules] Error 2
  make[2]: *** [Makefile:11: compile] Error 2
  time: target/linux/compile#30.09#11.30#37.92

Signed-off-by: Petr Štetiar <ynezz@true.cz>
.github/workflows/kernel.yml
.github/workflows/scripts/show_build_failures.sh [new file with mode: 0755]
.github/workflows/tools.yml

index 62e0952f195c06834f94c2eca3b32fda1f0c8f75..5afd546394dce2cbde24b78f0c581a43471c3074 100644 (file)
@@ -150,22 +150,22 @@ jobs:
       - name: Build tools
         shell: su buildbot -c "sh -e {0}"
         working-directory: openwrt
-        run: make tools/install -j$(nproc) BUILD_LOG=1
+        run: make tools/install -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
 
       - name: Build toolchain
         shell: su buildbot -c "sh -e {0}"
         working-directory: openwrt
-        run: make toolchain/install -j$(nproc) BUILD_LOG=1
+        run: make toolchain/install -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
 
       - name: Build Kernel
         shell: su buildbot -c "sh -e {0}"
         working-directory: openwrt
-        run: make target/compile -j$(nproc) BUILD_LOG=1
+        run: make target/compile -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
 
       - name: Build Kernel Kmods
         shell: su buildbot -c "sh -e {0}"
         working-directory: openwrt
-        run: make package/linux/compile -j$(nproc) BUILD_LOG=1
+        run: make package/linux/compile -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
 
       - name: Upload logs
         if: failure()
diff --git a/.github/workflows/scripts/show_build_failures.sh b/.github/workflows/scripts/show_build_failures.sh
new file mode 100755 (executable)
index 0000000..14f699c
--- /dev/null
@@ -0,0 +1,15 @@
+#!/bin/bash
+
+original_exit_code="${ret:-1}"
+log_dir_path="${1:-logs}"
+context="${2:-10}"
+
+show_make_build_errors() {
+       grep -slr 'make\[[[:digit:]]\].*Error [[:digit:]]$' "$log_dir_path" | while IFS= read -r log_file; do
+               printf "====== Make errors from %s ======\n" "$log_file";
+               grep -r -C"$context" 'make\[[[:digit:]]\].*Error [[:digit:]]$' "$log_file" ;
+       done
+}
+
+show_make_build_errors
+exit "$original_exit_code"
index 4e423fdd6292c3346cca44804040f65699224d44..b97f0599e2250a92b1f6e14ccaf755b288b4f20e 100644 (file)
@@ -123,7 +123,7 @@ jobs:
       - name: Build tools
         run: |
           cd "$WORKPATH"
-          make tools/install -j$(nproc) BUILD_LOG=1
+          make tools/install -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
 
       - name: Move logs to GITHUB_WORKSPACE
         if: always()