CI: bump actions/checkout action to v3
[openwrt/openwrt.git] / .github / workflows / kernel.yml
1 name: Build Kernel
2
3 on:
4 pull_request:
5 paths:
6 - '.github/workflows/kernel.yml'
7 - 'include/kernel-*'
8 - 'package/kernel/**'
9 - 'target/linux/generic/**'
10 push:
11 paths:
12 - '.github/workflows/kernel.yml'
13 - 'include/kernel-*'
14 - 'package/kernel/**'
15 - 'target/linux/generic/**'
16
17 permissions:
18 contents: read
19
20 jobs:
21 determine_targets:
22 name: Set targets
23 runs-on: ubuntu-latest
24 outputs:
25 target: ${{ steps.find_targets.outputs.target }}
26 owner_lc: ${{ steps.lower_owner.outputs.owner_lc }}
27 ccache_hash: ${{ steps.ccache_hash.outputs.ccache_hash }}
28
29 steps:
30 - name: Checkout
31 uses: actions/checkout@v3
32
33 - name: Set lower case owner name
34 id: lower_owner
35 run: |
36 OWNER_LC=$(echo "${{ github.repository_owner }}" \
37 | tr '[:upper:]' '[:lower:]')
38 echo "::set-output name=owner_lc::$OWNER_LC"
39
40 - name: Generate ccache hash
41 id: ccache_hash
42 run: |
43 CCACHE_HASH=$(md5sum include/kernel-* | awk '{ print $1 }' \
44 | md5sum | awk '{ print $1 }')
45 echo "::set-output name=ccache_hash::$CCACHE_HASH"
46
47 - name: Set targets
48 id: find_targets
49 run: |
50 export TARGETS="$(perl ./scripts/dump-target-info.pl targets 2>/dev/null \
51 | sort -u -t '/' -k1,1 \
52 | awk '{ print $1 }')"
53
54 JSON='['
55 FIRST=1
56 for TARGET in $TARGETS; do
57 [[ $FIRST -ne 1 ]] && JSON="$JSON"','
58 JSON="$JSON"'"'"${TARGET}"'"'
59 FIRST=0
60 done
61 JSON="$JSON"']'
62
63 echo -e "\n---- targets ----\n"
64 echo "$JSON"
65 echo -e "\n---- targets ----\n"
66
67 echo "::set-output name=target::$JSON"
68
69 build:
70 name: Build Kernel with external toolchain
71 needs: determine_targets
72 runs-on: ubuntu-latest
73 strategy:
74 fail-fast: False
75 matrix:
76 target: ${{fromJson(needs.determine_targets.outputs.target)}}
77
78 container: ghcr.io/${{ needs.determine_targets.outputs.owner_lc }}/tools:latest
79
80 permissions:
81 contents: read
82 packages: read
83
84 steps:
85 - name: Checkout master directory
86 uses: actions/checkout@v3
87 with:
88 path: openwrt
89
90 - name: Checkout packages feed
91 uses: actions/checkout@v3
92 with:
93 repository: openwrt/packages
94 path: openwrt/feeds/packages
95
96 - name: Checkout luci feed
97 uses: actions/checkout@v3
98 with:
99 repository: openwrt/luci
100 path: openwrt/feeds/luci
101
102 - name: Checkout routing feed
103 uses: actions/checkout@v3
104 with:
105 repository: openwrt/routing
106 path: openwrt/feeds/routing
107
108 - name: Checkout telephony feed
109 uses: actions/checkout@v3
110 with:
111 repository: openwrt/telephony
112 path: openwrt/feeds/telephony
113
114 - name: Fix permission
115 run: |
116 chown -R buildbot:buildbot openwrt
117
118 - name: Initialization environment
119 run: |
120 TARGET=$(echo ${{ matrix.target }} | cut -d "/" -f 1)
121 SUBTARGET=$(echo ${{ matrix.target }} | cut -d "/" -f 2)
122 echo "TARGET=$TARGET" >> "$GITHUB_ENV"
123 echo "SUBTARGET=$SUBTARGET" >> "$GITHUB_ENV"
124
125 - name: Update & Install feeds
126 shell: su buildbot -c "sh -e {0}"
127 working-directory: openwrt
128 run: |
129 ./scripts/feeds update -a
130 ./scripts/feeds install -a
131
132 - name: Parse toolchain file
133 working-directory: openwrt
134 run: |
135 TOOLCHAIN_STRING="$(curl "https://downloads.cdn.openwrt.org/snapshots/targets/${{ env.TARGET }}/${{ env.SUBTARGET }}/sha256sums" \
136 | grep ".*openwrt-toolchain.*tar.xz")"
137 TOOLCHAIN_FILE=$(echo "$TOOLCHAIN_STRING" | sed -n -e 's/.*\(openwrt-toolchain.*\).tar.xz/\1/p')
138 TOOLCHAIN_SHA256=$(echo "$TOOLCHAIN_STRING" | cut -d ' ' -f 1)
139
140 echo "TOOLCHAIN_FILE=$TOOLCHAIN_FILE" >> "$GITHUB_ENV"
141 echo "TOOLCHAIN_SHA256=$TOOLCHAIN_SHA256" >> "$GITHUB_ENV"
142
143 - name: Cache external toolchain
144 id: cache-external-toolchain
145 uses: actions/cache@v3
146 with:
147 path: openwrt/${{ env.TOOLCHAIN_FILE }}
148 key: ${{ env.TOOLCHAIN_FILE }}-${{ env.TOOLCHAIN_SHA256 }}
149
150 - name: Cache ccache
151 uses: actions/cache@v3
152 with:
153 path: openwrt/.ccache
154 key: ccache-kernel-${{ env.TARGET }}/${{ env.SUBTARGET }}-${{ needs.determine_targets.outputs.ccache_hash }}
155 restore-keys: |
156 ccache-kernel-${{ env.TARGET }}/${{ env.SUBTARGET }}-
157
158 - name: Download external toolchain
159 if: ${{ steps.cache-external-toolchain.outputs.cache-hit != 'true' }}
160 shell: su buildbot -c "sh -e {0}"
161 working-directory: openwrt
162 run: |
163 wget -O - https://downloads.cdn.openwrt.org/snapshots/targets/${{ env.TARGET }}/${{ env.SUBTARGET }}/${TOOLCHAIN_FILE}.tar.xz \
164 | tar --xz -xf -
165
166 - name: Extract prebuilt tools
167 shell: su buildbot -c "sh -e {0}"
168 working-directory: openwrt
169 run: ./scripts/ext-tools.sh --tools /tools.tar
170
171 - name: Configure external toolchain
172 shell: su buildbot -c "sh -e {0}"
173 working-directory: openwrt
174 run: |
175 echo CONFIG_ALL_KMODS=y >> .config
176 echo CONFIG_DEVEL=y >> .config
177 echo CONFIG_AUTOREMOVE=y >> .config
178 echo CONFIG_CCACHE=y >> .config
179
180 ./scripts/ext-toolchain.sh \
181 --toolchain ${{ env.TOOLCHAIN_FILE }}/toolchain-* \
182 --overwrite-config \
183 --config ${{ env.TARGET }}/${{ env.SUBTARGET }}
184
185 - name: Show configuration
186 shell: su buildbot -c "sh -e {0}"
187 working-directory: openwrt
188 run: ./scripts/diffconfig.sh
189
190 - name: Build tools
191 shell: su buildbot -c "sh -e {0}"
192 working-directory: openwrt
193 run: make tools/install -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
194
195 - name: Build toolchain
196 shell: su buildbot -c "sh -e {0}"
197 working-directory: openwrt
198 run: make toolchain/install -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
199
200 - name: Build Kernel
201 shell: su buildbot -c "sh -e {0}"
202 working-directory: openwrt
203 run: make target/compile -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
204
205 - name: Build Kernel Kmods
206 shell: su buildbot -c "sh -e {0}"
207 working-directory: openwrt
208 run: make package/linux/compile -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
209
210 - name: Upload logs
211 if: failure()
212 uses: actions/upload-artifact@v2
213 with:
214 name: ${{ env.TARGET }}-${{ env.SUBTARGET }}-logs
215 path: "openwrt/logs"