CI: fix matching for openwrt release branch for container selection
[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=${{ github.ref_name }}
71 elif echo "${{ github.ref_name }}" | grep -q -E '^openwrt-[0-9][0-9]\.[0-9][0-9]-'; then
72 CONTAINER_TAG="$(echo ${{ github.ref_name }} | sed 's/^\(openwrt-[0-9][0-9]\.[0-9][0-9]\)-.*/\1/')"
73 fi
74 elif [ ${{ github.ref_type }} == "tag" ]; then
75 if echo "${{ github.ref_name }}" | grep -q -E '^v[0-9][0-9]\.[0-9][0-9]\..+'; then
76 CONTAINER_TAG=openwrt-"$(echo ${{ github.ref_name }} | sed 's/^v\([0-9][0-9]\.[0-9][0-9]\)\..\+/\1/')"
77 fi
78 fi
79 echo "Tools container to use tools:$CONTAINER_TAG"
80 echo "container_tag=$CONTAINER_TAG" >> $GITHUB_OUTPUT
81
82 build:
83 name: Build with external toolchain
84 needs: setup_build
85 runs-on: ubuntu-latest
86
87 container: ghcr.io/${{ needs.setup_build.outputs.owner_lc }}/tools:${{ needs.setup_build.outputs.container_tag }}
88
89 permissions:
90 contents: read
91 packages: read
92
93 steps:
94 - name: Checkout master directory
95 uses: actions/checkout@v3
96 with:
97 path: openwrt
98
99 - name: Checkout packages feed
100 if: inputs.include_feeds == true
101 uses: actions/checkout@v3
102 with:
103 repository: openwrt/packages
104 path: openwrt/feeds/packages
105
106 - name: Checkout luci feed
107 if: inputs.include_feeds == true
108 uses: actions/checkout@v3
109 with:
110 repository: openwrt/luci
111 path: openwrt/feeds/luci
112
113 - name: Checkout routing feed
114 if: inputs.include_feeds == true
115 uses: actions/checkout@v3
116 with:
117 repository: openwrt/routing
118 path: openwrt/feeds/routing
119
120 - name: Checkout telephony feed
121 if: inputs.include_feeds == true
122 uses: actions/checkout@v3
123 with:
124 repository: openwrt/telephony
125 path: openwrt/feeds/telephony
126
127 - name: Fix permission
128 run: |
129 chown -R buildbot:buildbot openwrt
130
131 - name: Initialization environment
132 run: |
133 TARGET=$(echo ${{ inputs.target }} | cut -d "/" -f 1)
134 SUBTARGET=$(echo ${{ inputs.target }} | cut -d "/" -f 2)
135 echo "TARGET=$TARGET" >> "$GITHUB_ENV"
136 echo "SUBTARGET=$SUBTARGET" >> "$GITHUB_ENV"
137
138 - name: Update & Install feeds
139 if: inputs.include_feeds == true
140 shell: su buildbot -c "sh -e {0}"
141 working-directory: openwrt
142 run: |
143 ./scripts/feeds update -a
144 ./scripts/feeds install -a
145
146 - name: Parse toolchain file
147 if: inputs.build_toolchain == false
148 id: parse-toolchain
149 working-directory: openwrt
150 run: |
151 TOOLCHAIN_PATH=snapshots
152
153 if [ -n "${{ github.base_ref }}" ]; then
154 if echo "${{ github.base_ref }}" | grep -q -E 'openwrt-[0-9][0-9]\.[0-9][0-9]'; then
155 major_ver="$(echo ${{ github.base_ref }} | sed 's/openwrt-/v/')"
156 fi
157 elif [ "${{ github.ref_type }}" = "branch" ]; then
158 if echo "${{ github.ref_name }}" | grep -q -E 'openwrt-[0-9][0-9]\.[0-9][0-9]-'; then
159 major_ver="$(echo ${{ github.ref_name }} | sed 's/openwrt-\([0-9][0-9]\.[0-9][0-9]\)-.*/v\1/')"
160 fi
161 elif [ "${{ github.ref_type }}" = "tag" ]; then
162 if echo "${{ github.ref_name }}" | grep -q -E 'v[0-9][0-9]\.[0-9][0-9]\..+'; then
163 major_ver="$(sed 's/\(v[0-9][0-9]\.[0-9][0-9]\)\..\+/\1/')"
164 fi
165 fi
166
167 if [ -n "$major_ver" ]; then
168 git fetch --tags
169 latest_tag="$(git tag --sort=-creatordate -l $major_ver* | head -n1)"
170 if [ -n "$latest_tag" ]; then
171 TOOLCHAIN_PATH=releases/$(echo $latest_tag | sed 's/^v//')
172 fi
173 fi
174
175 SUMS_FILE="https://downloads.cdn.openwrt.org/$TOOLCHAIN_PATH/targets/${{ env.TARGET }}/${{ env.SUBTARGET }}/sha256sums"
176 if curl $SUMS_FILE | grep -q ".*openwrt-toolchain.*tar.xz"; then
177 TOOLCHAIN_STRING="$( curl $SUMS_FILE | grep ".*openwrt-toolchain.*tar.xz")"
178 TOOLCHAIN_FILE=$(echo "$TOOLCHAIN_STRING" | sed -n -e 's/.*\(openwrt-toolchain.*\).tar.xz/\1/p')
179 TOOLCHAIN_SHA256=$(echo "$TOOLCHAIN_STRING" | cut -d ' ' -f 1)
180
181 echo "toolchain-type=external_toolchain" >> $GITHUB_OUTPUT
182 elif curl $SUMS_FILE | grep -q ".*openwrt-sdk.*tar.xz"; then
183 TOOLCHAIN_STRING="$( curl $SUMS_FILE | grep ".*openwrt-sdk.*tar.xz")"
184 TOOLCHAIN_FILE=$(echo "$TOOLCHAIN_STRING" | sed -n -e 's/.*\(openwrt-sdk.*\).tar.xz/\1/p')
185 TOOLCHAIN_SHA256=$(echo "$TOOLCHAIN_STRING" | cut -d ' ' -f 1)
186
187 echo "toolchain-type=external_sdk" >> $GITHUB_OUTPUT
188 fi
189
190 echo "TOOLCHAIN_FILE=$TOOLCHAIN_FILE" >> "$GITHUB_ENV"
191 echo "TOOLCHAIN_SHA256=$TOOLCHAIN_SHA256" >> "$GITHUB_ENV"
192 echo "TOOLCHAIN_PATH=$TOOLCHAIN_PATH" >> "$GITHUB_ENV"
193
194 - name: Cache external toolchain/sdk
195 if: inputs.build_toolchain == false
196 id: cache-external-toolchain
197 uses: actions/cache@v3
198 with:
199 path: openwrt/${{ env.TOOLCHAIN_FILE }}
200 key: ${{ env.TOOLCHAIN_FILE }}-${{ steps.parse-toolchain.outputs.toolchain-type }}-${{ env.TOOLCHAIN_SHA256 }}
201
202 - name: Cache ccache
203 uses: actions/cache@v3
204 with:
205 path: openwrt/.ccache
206 key: ccache-kernel-${{ env.TARGET }}/${{ env.SUBTARGET }}-${{ needs.setup_build.outputs.ccache_hash }}
207 restore-keys: |
208 ccache-kernel-${{ env.TARGET }}/${{ env.SUBTARGET }}-
209
210 - name: Download external toolchain/sdk
211 if: inputs.build_toolchain == false && steps.cache-external-toolchain.outputs.cache-hit != 'true'
212 shell: su buildbot -c "sh -e {0}"
213 working-directory: openwrt
214 run: |
215 wget -O - https://downloads.cdn.openwrt.org/${{ env.TOOLCHAIN_PATH }}/targets/${{ env.TARGET }}/${{ env.SUBTARGET }}/${{ env.TOOLCHAIN_FILE }}.tar.xz \
216 | tar --xz -xf -
217
218 - name: Extract prebuilt tools
219 shell: su buildbot -c "sh -e {0}"
220 working-directory: openwrt
221 run: ./scripts/ext-tools.sh --tools /tools.tar
222
223 - name: Configure testing kernel
224 if: inputs.testing == true
225 shell: su buildbot -c "sh -e {0}"
226 working-directory: openwrt
227 run: |
228 echo CONFIG_TESTING_KERNEL=y >> .config
229
230 - name: Configure all kernel modules
231 if: inputs.build_all_kmods == true
232 shell: su buildbot -c "sh -e {0}"
233 working-directory: openwrt
234 run: |
235 echo CONFIG_ALL_KMODS=y >> .config
236
237 - name: Configure all modules
238 if: inputs.build_all_modules == true
239 shell: su buildbot -c "sh -e {0}"
240 working-directory: openwrt
241 run: |
242 echo CONFIG_ALL=y >> .config
243
244 - name: Configure all boards
245 if: inputs.build_all_boards == true
246 shell: su buildbot -c "sh -e {0}"
247 working-directory: openwrt
248 run: |
249 echo CONFIG_TARGET_MULTI_PROFILE=y >> .config
250 echo CONFIG_TARGET_PER_DEVICE_ROOTFS=y >> .config
251 echo CONFIG_TARGET_ALL_PROFILES=y >> .config
252
253 - name: Configure external toolchain
254 if: inputs.build_toolchain == false && steps.parse-toolchain.outputs.toolchain-type == 'external_toolchain'
255 shell: su buildbot -c "sh -e {0}"
256 working-directory: openwrt
257 run: |
258 echo CONFIG_DEVEL=y >> .config
259 echo CONFIG_AUTOREMOVE=y >> .config
260 echo CONFIG_CCACHE=y >> .config
261
262 ./scripts/ext-toolchain.sh \
263 --toolchain ${{ env.TOOLCHAIN_FILE }}/toolchain-* \
264 --overwrite-config \
265 --config ${{ env.TARGET }}/${{ env.SUBTARGET }}
266
267 - name: Configure external toolchain with sdk
268 if: inputs.build_toolchain == false && steps.parse-toolchain.outputs.toolchain-type == 'external_sdk'
269 shell: su buildbot -c "sh -e {0}"
270 working-directory: openwrt
271 run: |
272 echo CONFIG_DEVEL=y >> .config
273 echo CONFIG_AUTOREMOVE=y >> .config
274 echo CONFIG_CCACHE=y >> .config
275
276 ./scripts/ext-toolchain.sh \
277 --toolchain ${{ env.TOOLCHAIN_FILE }}/staging_dir/toolchain-* \
278 --overwrite-config \
279 --config ${{ env.TARGET }}/${{ env.SUBTARGET }}
280
281 - name: Configure internal toolchain
282 if: inputs.build_toolchain == true
283 shell: su buildbot -c "sh -e {0}"
284 working-directory: openwrt
285 run: |
286 echo CONFIG_DEVEL=y >> .config
287 echo CONFIG_AUTOREMOVE=y >> .config
288 echo CONFIG_CCACHE=y >> .config
289
290 echo "CONFIG_TARGET_${{ env.TARGET }}=y" >> .config
291 echo "CONFIG_TARGET_${{ env.TARGET }}_${{ env.SUBTARGET }}=y" >> .config
292
293 make defconfig
294
295 - name: Show configuration
296 shell: su buildbot -c "sh -e {0}"
297 working-directory: openwrt
298 run: ./scripts/diffconfig.sh
299
300 - name: Build tools
301 shell: su buildbot -c "sh -e {0}"
302 working-directory: openwrt
303 run: make tools/install -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
304
305 - name: Build toolchain
306 shell: su buildbot -c "sh -e {0}"
307 working-directory: openwrt
308 run: make toolchain/install -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
309
310 - name: Build Kernel
311 shell: su buildbot -c "sh -e {0}"
312 working-directory: openwrt
313 run: make target/compile -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
314
315 - name: Build Kernel Kmods
316 shell: su buildbot -c "sh -e {0}"
317 working-directory: openwrt
318 run: make package/linux/compile -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
319
320 - name: Build everything
321 if: inputs.build_full == true
322 shell: su buildbot -c "sh -e {0}"
323 working-directory: openwrt
324 run: make -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
325
326 - name: Upload logs
327 if: failure()
328 uses: actions/upload-artifact@v3
329 with:
330 name: ${{ env.TARGET }}-${{ env.SUBTARGET }}-logs
331 path: "openwrt/logs"