511d9596fa21db3850057d5d1c304e00f4d8a3b4
[openwrt/openwrt.git] / .github / workflows / build.yml
1 name: Build sub target
2
3 on:
4 workflow_call:
5 inputs:
6 target:
7 required: true
8 type: string
9 testing:
10 type: boolean
11 build_toolchain:
12 type: boolean
13 include_feeds:
14 type: boolean
15 build_full:
16 type: boolean
17 build_all_modules:
18 type: boolean
19 build_all_kmods:
20 type: boolean
21 build_all_boards:
22 type: boolean
23
24 permissions:
25 contents: read
26
27 jobs:
28 setup_build:
29 name: Setup build
30 runs-on: ubuntu-latest
31 outputs:
32 owner_lc: ${{ steps.lower_owner.outputs.owner_lc }}
33 ccache_hash: ${{ steps.ccache_hash.outputs.ccache_hash }}
34 container_tag: ${{ steps.determine_tools_container.outputs.container_tag }}
35
36 steps:
37 - name: Checkout
38 uses: actions/checkout@v3
39
40 - name: Set lower case owner name
41 id: lower_owner
42 run: |
43 OWNER_LC=$(echo "${{ github.repository_owner }}" \
44 | tr '[:upper:]' '[:lower:]')
45 echo "owner_lc=$OWNER_LC" >> $GITHUB_OUTPUT
46
47 - name: Generate ccache hash
48 id: ccache_hash
49 run: |
50 CCACHE_HASH=$(md5sum include/kernel-* | awk '{ print $1 }' \
51 | md5sum | awk '{ print $1 }')
52 echo "ccache_hash=$CCACHE_HASH" >> $GITHUB_OUTPUT
53
54 # Per branch tools container tag
55 # By default stick to latest
56 # For official test targetting openwrt stable branch
57 # Get the branch or parse the tag and push dedicated tools containers
58 # For local test to use the correct container for stable release testing
59 # you need to use for the branch name a prefix of openwrt-[0-9][0-9].[0-9][0-9]-
60 - name: Determine tools container tag
61 id: determine_tools_container
62 run: |
63 CONTAINER_TAG=latest
64 if [ -n "${{ github.base_ref }}" ]; then
65 if echo "${{ github.base_ref }}" | grep -q -E 'openwrt-[0-9][0-9]\.[0-9][0-9]'; then
66 CONTAINER_TAG="${{ github.base_ref }}"
67 fi
68 elif [ ${{ github.ref_type }} == "branch" ]; then
69 if echo "${{ github.ref_name }}" | grep -q -E 'openwrt-[0-9][0-9]\.[0-9][0-9]-'; then
70 CONTAINER_TAG="$(echo ${{ github.ref_name }} | sed 's/^\(openwrt-[0-9][0-9]\.[0-9][0-9]\)-.*/\1/')"
71 fi
72 elif [ ${{ github.ref_type }} == "tag" ]; then
73 if echo "${{ github.ref_name }}" | grep -q -E 'v[0-9][0-9]\.[0-9][0-9]\..+'; then
74 CONTAINER_TAG=openwrt-"$(echo ${{ github.ref_name }} | sed 's/v\([0-9][0-9]\.[0-9][0-9]\)\..\+/\1/')"
75 fi
76 fi
77 echo "Tools container to use tools:$CONTAINER_TAG"
78 echo "container_tag=$CONTAINER_TAG" >> $GITHUB_OUTPUT
79
80 build:
81 name: Build with external toolchain
82 needs: setup_build
83 runs-on: ubuntu-latest
84
85 container: ghcr.io/${{ needs.setup_build.outputs.owner_lc }}/tools:${{ needs.setup_build.outputs.container_tag }}
86
87 permissions:
88 contents: read
89 packages: read
90
91 steps:
92 - name: Checkout master directory
93 uses: actions/checkout@v3
94 with:
95 path: openwrt
96
97 - name: Checkout packages feed
98 if: inputs.include_feeds == true
99 uses: actions/checkout@v3
100 with:
101 repository: openwrt/packages
102 path: openwrt/feeds/packages
103
104 - name: Checkout luci feed
105 if: inputs.include_feeds == true
106 uses: actions/checkout@v3
107 with:
108 repository: openwrt/luci
109 path: openwrt/feeds/luci
110
111 - name: Checkout routing feed
112 if: inputs.include_feeds == true
113 uses: actions/checkout@v3
114 with:
115 repository: openwrt/routing
116 path: openwrt/feeds/routing
117
118 - name: Checkout telephony feed
119 if: inputs.include_feeds == true
120 uses: actions/checkout@v3
121 with:
122 repository: openwrt/telephony
123 path: openwrt/feeds/telephony
124
125 - name: Fix permission
126 run: |
127 chown -R buildbot:buildbot openwrt
128
129 - name: Initialization environment
130 run: |
131 TARGET=$(echo ${{ inputs.target }} | cut -d "/" -f 1)
132 SUBTARGET=$(echo ${{ inputs.target }} | cut -d "/" -f 2)
133 echo "TARGET=$TARGET" >> "$GITHUB_ENV"
134 echo "SUBTARGET=$SUBTARGET" >> "$GITHUB_ENV"
135
136 - name: Update & Install feeds
137 if: inputs.include_feeds == true
138 shell: su buildbot -c "sh -e {0}"
139 working-directory: openwrt
140 run: |
141 ./scripts/feeds update -a
142 ./scripts/feeds install -a
143
144 - name: Parse toolchain file
145 if: inputs.build_toolchain == false
146 id: parse-toolchain
147 working-directory: openwrt
148 run: |
149 TOOLCHAIN_PATH=snapshots
150
151 if [ -n "${{ github.base_ref }}" ]; then
152 if echo "${{ github.base_ref }}" | grep -q -E 'openwrt-[0-9][0-9]\.[0-9][0-9]'; then
153 major_ver="$(echo ${{ github.base_ref }} | sed 's/openwrt-/v/')"
154 fi
155 elif [ "${{ github.ref_type }}" = "branch" ]; then
156 if echo "${{ github.ref_name }}" | grep -q -E 'openwrt-[0-9][0-9]\.[0-9][0-9]-'; then
157 major_ver="$(echo ${{ github.ref_name }} | sed 's/openwrt-\([0-9][0-9]\.[0-9][0-9]\)-.*/v\1/')"
158 fi
159 elif [ "${{ github.ref_type }}" = "tag" ]; then
160 if echo "${{ github.ref_name }}" | grep -q -E 'v[0-9][0-9]\.[0-9][0-9]\..+'; then
161 major_ver="$(sed 's/\(v[0-9][0-9]\.[0-9][0-9]\)\..\+/\1/')"
162 fi
163 fi
164
165 if [ -n "$major_ver" ]; then
166 git fetch --tags
167 latest_tag="$(git tag --sort=-creatordate -l $major_ver* | head -n1)"
168 if [ -n "$latest_tag" ]; then
169 TOOLCHAIN_PATH=releases/$(echo $latest_tag | sed 's/^v//')
170 fi
171 fi
172
173 SUMS_FILE="https://downloads.cdn.openwrt.org/$TOOLCHAIN_PATH/targets/${{ env.TARGET }}/${{ env.SUBTARGET }}/sha256sums"
174 if curl $SUMS_FILE | grep -q ".*openwrt-toolchain.*tar.xz"; then
175 TOOLCHAIN_STRING="$( curl $SUMS_FILE | grep ".*openwrt-toolchain.*tar.xz")"
176 TOOLCHAIN_FILE=$(echo "$TOOLCHAIN_STRING" | sed -n -e 's/.*\(openwrt-toolchain.*\).tar.xz/\1/p')
177 TOOLCHAIN_SHA256=$(echo "$TOOLCHAIN_STRING" | cut -d ' ' -f 1)
178
179 echo "toolchain-type=external_toolchain" >> $GITHUB_OUTPUT
180 elif curl $SUMS_FILE | grep -q ".*openwrt-sdk.*tar.xz"; then
181 TOOLCHAIN_STRING="$( curl $SUMS_FILE | grep ".*openwrt-sdk.*tar.xz")"
182 TOOLCHAIN_FILE=$(echo "$TOOLCHAIN_STRING" | sed -n -e 's/.*\(openwrt-sdk.*\).tar.xz/\1/p')
183 TOOLCHAIN_SHA256=$(echo "$TOOLCHAIN_STRING" | cut -d ' ' -f 1)
184
185 echo "toolchain-type=external_sdk" >> $GITHUB_OUTPUT
186 fi
187
188 echo "TOOLCHAIN_FILE=$TOOLCHAIN_FILE" >> "$GITHUB_ENV"
189 echo "TOOLCHAIN_SHA256=$TOOLCHAIN_SHA256" >> "$GITHUB_ENV"
190 echo "TOOLCHAIN_PATH=$TOOLCHAIN_PATH" >> "$GITHUB_ENV"
191
192 - name: Cache external toolchain/sdk
193 if: inputs.build_toolchain == false
194 id: cache-external-toolchain
195 uses: actions/cache@v3
196 with:
197 path: openwrt/${{ env.TOOLCHAIN_FILE }}
198 key: ${{ env.TOOLCHAIN_FILE }}-${{ steps.parse-toolchain.outputs.toolchain-type }}-${{ env.TOOLCHAIN_SHA256 }}
199
200 - name: Cache ccache
201 uses: actions/cache@v3
202 with:
203 path: openwrt/.ccache
204 key: ccache-kernel-${{ env.TARGET }}/${{ env.SUBTARGET }}-${{ needs.setup_build.outputs.ccache_hash }}
205 restore-keys: |
206 ccache-kernel-${{ env.TARGET }}/${{ env.SUBTARGET }}-
207
208 - name: Download external toolchain/sdk
209 if: inputs.build_toolchain == false && steps.cache-external-toolchain.outputs.cache-hit != 'true'
210 shell: su buildbot -c "sh -e {0}"
211 working-directory: openwrt
212 run: |
213 wget -O - https://downloads.cdn.openwrt.org/${{ env.TOOLCHAIN_PATH }}/targets/${{ env.TARGET }}/${{ env.SUBTARGET }}/${{ env.TOOLCHAIN_FILE }}.tar.xz \
214 | tar --xz -xf -
215
216 - name: Extract prebuilt tools
217 shell: su buildbot -c "sh -e {0}"
218 working-directory: openwrt
219 run: ./scripts/ext-tools.sh --tools /tools.tar
220
221 - name: Configure testing kernel
222 if: inputs.testing == true
223 shell: su buildbot -c "sh -e {0}"
224 working-directory: openwrt
225 run: |
226 echo CONFIG_TESTING_KERNEL=y >> .config
227
228 - name: Configure all kernel modules
229 if: inputs.build_all_kmods == true
230 shell: su buildbot -c "sh -e {0}"
231 working-directory: openwrt
232 run: |
233 echo CONFIG_ALL_KMODS=y >> .config
234
235 - name: Configure all modules
236 if: inputs.build_all_modules == true
237 shell: su buildbot -c "sh -e {0}"
238 working-directory: openwrt
239 run: |
240 echo CONFIG_ALL=y >> .config
241
242 - name: Configure all boards
243 if: inputs.build_all_boards == true
244 shell: su buildbot -c "sh -e {0}"
245 working-directory: openwrt
246 run: |
247 echo CONFIG_TARGET_MULTI_PROFILE=y >> .config
248 echo CONFIG_TARGET_PER_DEVICE_ROOTFS=y >> .config
249 echo CONFIG_TARGET_ALL_PROFILES=y >> .config
250
251 - name: Configure external toolchain
252 if: inputs.build_toolchain == false && steps.parse-toolchain.outputs.toolchain-type == 'external_toolchain'
253 shell: su buildbot -c "sh -e {0}"
254 working-directory: openwrt
255 run: |
256 echo CONFIG_DEVEL=y >> .config
257 echo CONFIG_AUTOREMOVE=y >> .config
258 echo CONFIG_CCACHE=y >> .config
259
260 ./scripts/ext-toolchain.sh \
261 --toolchain ${{ env.TOOLCHAIN_FILE }}/toolchain-* \
262 --overwrite-config \
263 --config ${{ env.TARGET }}/${{ env.SUBTARGET }}
264
265 - name: Configure external toolchain with sdk
266 if: inputs.build_toolchain == false && steps.parse-toolchain.outputs.toolchain-type == 'external_sdk'
267 shell: su buildbot -c "sh -e {0}"
268 working-directory: openwrt
269 run: |
270 echo CONFIG_DEVEL=y >> .config
271 echo CONFIG_AUTOREMOVE=y >> .config
272 echo CONFIG_CCACHE=y >> .config
273
274 ./scripts/ext-toolchain.sh \
275 --toolchain ${{ env.TOOLCHAIN_FILE }}/staging_dir/toolchain-* \
276 --overwrite-config \
277 --config ${{ env.TARGET }}/${{ env.SUBTARGET }}
278
279 - name: Configure internal toolchain
280 if: inputs.build_toolchain == true
281 shell: su buildbot -c "sh -e {0}"
282 working-directory: openwrt
283 run: |
284 echo CONFIG_DEVEL=y >> .config
285 echo CONFIG_AUTOREMOVE=y >> .config
286 echo CONFIG_CCACHE=y >> .config
287
288 echo "CONFIG_TARGET_${{ env.TARGET }}=y" >> .config
289 echo "CONFIG_TARGET_${{ env.TARGET }}_${{ env.SUBTARGET }}=y" >> .config
290
291 make defconfig
292
293 - name: Show configuration
294 shell: su buildbot -c "sh -e {0}"
295 working-directory: openwrt
296 run: ./scripts/diffconfig.sh
297
298 - name: Build tools
299 shell: su buildbot -c "sh -e {0}"
300 working-directory: openwrt
301 run: make tools/install -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
302
303 - name: Build toolchain
304 shell: su buildbot -c "sh -e {0}"
305 working-directory: openwrt
306 run: make toolchain/install -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
307
308 - name: Build Kernel
309 shell: su buildbot -c "sh -e {0}"
310 working-directory: openwrt
311 run: make target/compile -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
312
313 - name: Build Kernel Kmods
314 shell: su buildbot -c "sh -e {0}"
315 working-directory: openwrt
316 run: make package/linux/compile -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
317
318 - name: Build everything
319 if: inputs.build_full == true
320 shell: su buildbot -c "sh -e {0}"
321 working-directory: openwrt
322 run: make -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
323
324 - name: Upload logs
325 if: failure()
326 uses: actions/upload-artifact@v3
327 with:
328 name: ${{ env.TARGET }}-${{ env.SUBTARGET }}-logs
329 path: "openwrt/logs"