CI: add Kernel compile tests
[openwrt/openwrt.git] / .github / workflows / kernel.yml
1 name: Build Kernel
2
3 on:
4 pull_request:
5 paths:
6 - 'include/kernel-*'
7 - 'package/kernel/**'
8 jobs:
9 determine_targets:
10 name: Set targets
11 runs-on: ubuntu-latest
12 outputs:
13 target: ${{ steps.find_targets.outputs.target }}
14
15 steps:
16 - name: Checkout
17 uses: actions/checkout@v2
18
19 - name: Set targets
20 id: find_targets
21 run: |
22 export TARGETS="$(perl ./scripts/dump-target-info.pl targets 2>/dev/null \
23 | sort -u -t '/' -k1,1 \
24 | awk '{ print $1 }')"
25
26 JSON='['
27 FIRST=1
28 for TARGET in $TARGETS; do
29 [[ $FIRST -ne 1 ]] && JSON="$JSON"','
30 JSON="$JSON"'"'"${TARGET}"'"'
31 FIRST=0
32 done
33 JSON="$JSON"']'
34
35 echo -e "\n---- targets ----\n"
36 echo "$JSON"
37 echo -e "\n---- targets ----\n"
38
39 echo "::set-output name=target::$JSON"
40
41 build:
42 name: Build Kernel with external toolchain
43 needs: determine_targets
44 runs-on: ubuntu-latest
45 strategy:
46 fail-fast: False
47 matrix:
48 target: ${{fromJson(needs.determine_targets.outputs.target)}}
49
50 steps:
51 - name: Checkout master directory
52 uses: actions/checkout@v2
53 with:
54 path: openwrt
55
56 - name: Setup Ubuntu
57 env:
58 DEBIAN_FRONTEND: noninteractive
59 run: |
60 sudo apt-get update
61 sudo apt-get -y install \
62 build-essential \
63 ccache \
64 clang-12 \
65 ecj \
66 fastjar \
67 file \
68 g++ \
69 gawk \
70 gettext \
71 git \
72 java-propose-classpath \
73 libelf-dev \
74 libncurses-dev \
75 libssl-dev \
76 mkisofs \
77 python3 \
78 python3-dev \
79 python3-distutils \
80 python3-setuptools \
81 qemu-utils \
82 rsync \
83 subversion \
84 swig \
85 unzip \
86 wget \
87 xsltproc \
88 zlib1g-dev
89
90 - name: Initialization environment
91 run: |
92 TARGET=$(echo ${{ matrix.target }} | cut -d "/" -f 1)
93 SUBTARGET=$(echo ${{ matrix.target }} | cut -d "/" -f 2)
94 echo "TARGET=$TARGET" >> "$GITHUB_ENV"
95 echo "SUBTARGET=$SUBTARGET" >> "$GITHUB_ENV"
96
97 - name: Update & Install feeds
98 run: |
99 cd openwrt
100 ./scripts/feeds update -a
101 ./scripts/feeds install -a
102
103 - name: Setup external toolchain
104 run: |
105 cd openwrt
106 TOOLCHAIN_FILE=$(curl "https://downloads.openwrt.org/snapshots/targets/${{ env.TARGET }}/${{ env.SUBTARGET }}/sha256sums" \
107 | sed -n -e 's/.*\(openwrt-toolchain.*\).tar.xz/\1/p')
108
109 echo "TOOLCHAIN_FILE=$TOOLCHAIN_FILE" >> "$GITHUB_ENV"
110
111 wget -O - https://downloads.openwrt.org/snapshots/targets/${{ env.TARGET }}/${{ env.SUBTARGET }}/${TOOLCHAIN_FILE}.tar.xz \
112 | tar --xz -xf -
113
114 - name: Configure external toolchain
115 run: |
116 cd openwrt
117 ./scripts/ext-toolchain.sh \
118 --toolchain ${{ env.TOOLCHAIN_FILE }}/toolchain-* \
119 --config ${{ env.TARGET }}/${{ env.SUBTARGET }}
120
121 make defconfig
122
123 - name: Build tools
124 run: |
125 cd openwrt
126 make tools/install -j$(nproc) BUILD_LOG=1
127
128 - name: Build toolchain
129 run: |
130 cd openwrt
131 make toolchain/install -j$(nproc) BUILD_LOG=1
132
133 - name: Build Kernel
134 run: |
135 cd openwrt
136 make target/compile -j$(nproc) BUILD_LOG=1
137
138 - name: Upload logs
139 if: failure()
140 uses: actions/upload-artifact@v2
141 with:
142 name: ${{ env.TARGET }}-${{ env.SUBTARGET }}-logs
143 path: "openwrt/logs"