30 runs-on: ubuntu-latest
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 }}
38 uses: actions/checkout@v3
40 - name: Set lower case owner name
43 OWNER_LC=$(echo "${{ github.repository_owner }}" \
44 | tr '[:upper:]' '[:lower:]')
45 echo "owner_lc=$OWNER_LC" >> $GITHUB_OUTPUT
47 - name: Generate ccache hash
50 CCACHE_HASH=$(md5sum include/kernel-* | awk '{ print $1 }' \
51 | md5sum | awk '{ print $1 }')
52 echo "ccache_hash=$CCACHE_HASH" >> $GITHUB_OUTPUT
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
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 }}"
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/')"
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/')"
79 echo "Tools container to use tools:$CONTAINER_TAG"
80 echo "container_tag=$CONTAINER_TAG" >> $GITHUB_OUTPUT
83 name: Build with external toolchain
85 runs-on: ubuntu-latest
87 container: ghcr.io/${{ needs.setup_build.outputs.owner_lc }}/tools:${{ needs.setup_build.outputs.container_tag }}
94 - name: Checkout master directory
95 uses: actions/checkout@v3
99 - name: Checkout packages feed
100 if: inputs.include_feeds == true
101 uses: actions/checkout@v3
103 repository: openwrt/packages
104 path: openwrt/feeds/packages
106 - name: Checkout luci feed
107 if: inputs.include_feeds == true
108 uses: actions/checkout@v3
110 repository: openwrt/luci
111 path: openwrt/feeds/luci
113 - name: Checkout routing feed
114 if: inputs.include_feeds == true
115 uses: actions/checkout@v3
117 repository: openwrt/routing
118 path: openwrt/feeds/routing
120 - name: Checkout telephony feed
121 if: inputs.include_feeds == true
122 uses: actions/checkout@v3
124 repository: openwrt/telephony
125 path: openwrt/feeds/telephony
127 - name: Fix permission
129 chown -R buildbot:buildbot openwrt
131 - name: Initialization environment
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"
138 - name: Update & Install feeds
139 if: inputs.include_feeds == true
140 shell: su buildbot -c "sh -e {0}"
141 working-directory: openwrt
143 ./scripts/feeds update -a
144 ./scripts/feeds install -a
146 - name: Parse toolchain file
147 if: inputs.build_toolchain == false
149 working-directory: openwrt
151 TOOLCHAIN_PATH=snapshots
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/')"
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-/v/')"
160 elif echo "${{ github.ref_name }}" | grep -q -E '^openwrt-[0-9][0-9]\.[0-9][0-9]-'; then
161 major_ver="$(echo ${{ github.ref_name }} | sed 's/^openwrt-\([0-9][0-9]\.[0-9][0-9]\)-.*/v\1/')"
163 elif [ "${{ github.ref_type }}" = "tag" ]; then
164 if echo "${{ github.ref_name }}" | grep -q -E '^v[0-9][0-9]\.[0-9][0-9]\..+'; then
165 major_ver="$(echo ${{ github.ref_name }} | sed 's/^\(v[0-9][0-9]\.[0-9][0-9]\)\..\+/\1/')"
169 if [ -n "$major_ver" ]; then
171 latest_tag="$(git tag --sort=-creatordate -l $major_ver* | head -n1)"
172 if [ -n "$latest_tag" ]; then
173 TOOLCHAIN_PATH=releases/$(echo $latest_tag | sed 's/^v//')
177 SUMS_FILE="https://downloads.cdn.openwrt.org/$TOOLCHAIN_PATH/targets/${{ env.TARGET }}/${{ env.SUBTARGET }}/sha256sums"
178 if curl $SUMS_FILE | grep -q ".*openwrt-toolchain.*tar.xz"; then
179 TOOLCHAIN_STRING="$( curl $SUMS_FILE | grep ".*openwrt-toolchain.*tar.xz")"
180 TOOLCHAIN_FILE=$(echo "$TOOLCHAIN_STRING" | sed -n -e 's/.*\(openwrt-toolchain.*\).tar.xz/\1/p')
181 TOOLCHAIN_SHA256=$(echo "$TOOLCHAIN_STRING" | cut -d ' ' -f 1)
183 echo "toolchain-type=external_toolchain" >> $GITHUB_OUTPUT
184 elif curl $SUMS_FILE | grep -q ".*openwrt-sdk.*tar.xz"; then
185 TOOLCHAIN_STRING="$( curl $SUMS_FILE | grep ".*openwrt-sdk.*tar.xz")"
186 TOOLCHAIN_FILE=$(echo "$TOOLCHAIN_STRING" | sed -n -e 's/.*\(openwrt-sdk.*\).tar.xz/\1/p')
187 TOOLCHAIN_SHA256=$(echo "$TOOLCHAIN_STRING" | cut -d ' ' -f 1)
189 echo "toolchain-type=external_sdk" >> $GITHUB_OUTPUT
192 echo "TOOLCHAIN_FILE=$TOOLCHAIN_FILE" >> "$GITHUB_ENV"
193 echo "TOOLCHAIN_SHA256=$TOOLCHAIN_SHA256" >> "$GITHUB_ENV"
194 echo "TOOLCHAIN_PATH=$TOOLCHAIN_PATH" >> "$GITHUB_ENV"
196 - name: Cache external toolchain/sdk
197 if: inputs.build_toolchain == false
198 id: cache-external-toolchain
199 uses: actions/cache@v3
201 path: openwrt/${{ env.TOOLCHAIN_FILE }}
202 key: ${{ env.TOOLCHAIN_FILE }}-${{ steps.parse-toolchain.outputs.toolchain-type }}-${{ env.TOOLCHAIN_SHA256 }}
205 uses: actions/cache@v3
207 path: openwrt/.ccache
208 key: ccache-kernel-${{ env.TARGET }}/${{ env.SUBTARGET }}-${{ needs.setup_build.outputs.ccache_hash }}
210 ccache-kernel-${{ env.TARGET }}/${{ env.SUBTARGET }}-
212 - name: Download external toolchain/sdk
213 if: inputs.build_toolchain == false && steps.cache-external-toolchain.outputs.cache-hit != 'true'
214 shell: su buildbot -c "sh -e {0}"
215 working-directory: openwrt
217 wget -O - https://downloads.cdn.openwrt.org/${{ env.TOOLCHAIN_PATH }}/targets/${{ env.TARGET }}/${{ env.SUBTARGET }}/${{ env.TOOLCHAIN_FILE }}.tar.xz \
220 - name: Extract prebuilt tools
221 shell: su buildbot -c "sh -e {0}"
222 working-directory: openwrt
223 run: ./scripts/ext-tools.sh --tools /tools.tar
225 - name: Configure testing kernel
226 if: inputs.testing == true
227 shell: su buildbot -c "sh -e {0}"
228 working-directory: openwrt
230 echo CONFIG_TESTING_KERNEL=y >> .config
232 - name: Configure all kernel modules
233 if: inputs.build_all_kmods == true
234 shell: su buildbot -c "sh -e {0}"
235 working-directory: openwrt
237 echo CONFIG_ALL_KMODS=y >> .config
239 - name: Configure all modules
240 if: inputs.build_all_modules == true
241 shell: su buildbot -c "sh -e {0}"
242 working-directory: openwrt
244 echo CONFIG_ALL=y >> .config
246 - name: Configure all boards
247 if: inputs.build_all_boards == true
248 shell: su buildbot -c "sh -e {0}"
249 working-directory: openwrt
251 echo CONFIG_TARGET_MULTI_PROFILE=y >> .config
252 echo CONFIG_TARGET_PER_DEVICE_ROOTFS=y >> .config
253 echo CONFIG_TARGET_ALL_PROFILES=y >> .config
255 - name: Configure external toolchain
256 if: inputs.build_toolchain == false && steps.parse-toolchain.outputs.toolchain-type == 'external_toolchain'
257 shell: su buildbot -c "sh -e {0}"
258 working-directory: openwrt
260 echo CONFIG_DEVEL=y >> .config
261 echo CONFIG_AUTOREMOVE=y >> .config
262 echo CONFIG_CCACHE=y >> .config
264 ./scripts/ext-toolchain.sh \
265 --toolchain ${{ env.TOOLCHAIN_FILE }}/toolchain-* \
267 --config ${{ env.TARGET }}/${{ env.SUBTARGET }}
269 - name: Adapt external sdk to external toolchain format
270 if: inputs.build_toolchain == false && steps.parse-toolchain.outputs.toolchain-type == 'external_sdk' && steps.cache-external-toolchain.outputs.cache-hit != 'true'
271 shell: su buildbot -c "sh -e {0}"
272 working-directory: openwrt
274 TOOLCHAIN_DIR=${{ env.TOOLCHAIN_FILE }}/staging_dir/$(ls ${{ env.TOOLCHAIN_FILE }}/staging_dir | grep toolchain)
275 TOOLCHAIN_BIN=$TOOLCHAIN_DIR/bin
278 # Find target name from toolchain info.mk
279 GNU_TARGET_NAME=$(cat $TOOLCHAIN_DIR/info.mk | grep TARGET_CROSS | sed 's/^TARGET_CROSS=\(.*\)-$/\1/')
283 # Revert sdk wrapper scripts applied to all the bins
284 for app in $(find . -name "*.bin"); do
285 TARGET_APP=$(echo $app | sed 's/\.\/\.\(.*\)\.bin/\1/')
287 mv .$TARGET_APP.bin $TARGET_APP
290 # Setup the wrapper script in the sdk toolchain dir simulating an external toolchain build
291 cp $OPENWRT_DIR/target/toolchain/files/wrapper.sh $GNU_TARGET_NAME-wrapper.sh
292 for app in cc gcc g++ c++ cpp ld as ; do
293 [ -f $GNU_TARGET_NAME-$app ] && mv $GNU_TARGET_NAME-$app $GNU_TARGET_NAME-$app.bin
294 ln -sf $GNU_TARGET_NAME-wrapper.sh $GNU_TARGET_NAME-$app
297 - name: Configure external toolchain with sdk
298 if: inputs.build_toolchain == false && steps.parse-toolchain.outputs.toolchain-type == 'external_sdk'
299 shell: su buildbot -c "sh -e {0}"
300 working-directory: openwrt
302 echo CONFIG_DEVEL=y >> .config
303 echo CONFIG_AUTOREMOVE=y >> .config
304 echo CONFIG_CCACHE=y >> .config
306 ./scripts/ext-toolchain.sh \
307 --toolchain ${{ env.TOOLCHAIN_FILE }}/staging_dir/toolchain-* \
309 --config ${{ env.TARGET }}/${{ env.SUBTARGET }}
311 - name: Configure internal toolchain
312 if: inputs.build_toolchain == true
313 shell: su buildbot -c "sh -e {0}"
314 working-directory: openwrt
316 echo CONFIG_DEVEL=y >> .config
317 echo CONFIG_AUTOREMOVE=y >> .config
318 echo CONFIG_CCACHE=y >> .config
320 echo "CONFIG_TARGET_${{ env.TARGET }}=y" >> .config
321 echo "CONFIG_TARGET_${{ env.TARGET }}_${{ env.SUBTARGET }}=y" >> .config
325 - name: Show configuration
326 shell: su buildbot -c "sh -e {0}"
327 working-directory: openwrt
328 run: ./scripts/diffconfig.sh
331 shell: su buildbot -c "sh -e {0}"
332 working-directory: openwrt
333 run: make tools/install -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
335 - name: Build toolchain
336 shell: su buildbot -c "sh -e {0}"
337 working-directory: openwrt
338 run: make toolchain/install -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
341 shell: su buildbot -c "sh -e {0}"
342 working-directory: openwrt
343 run: make target/compile -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
345 - name: Build Kernel Kmods
346 shell: su buildbot -c "sh -e {0}"
347 working-directory: openwrt
348 run: make package/linux/compile -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
350 - name: Build everything
351 if: inputs.build_full == true
352 shell: su buildbot -c "sh -e {0}"
353 working-directory: openwrt
354 run: make -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
358 uses: actions/upload-artifact@v3
360 name: ${{ env.TARGET }}-${{ env.SUBTARGET }}-logs