31 name: Setup build ${{ inputs.target }}
32 runs-on: ubuntu-latest
34 owner_lc: ${{ steps.lower_owner.outputs.owner_lc }}
35 ccache_hash: ${{ steps.ccache_hash.outputs.ccache_hash }}
36 container_tag: ${{ steps.determine_tools_container.outputs.container_tag }}
40 uses: actions/checkout@v3
42 - name: Set lower case owner name
45 OWNER_LC=$(echo "${{ github.repository_owner }}" \
46 | tr '[:upper:]' '[:lower:]')
47 echo "owner_lc=$OWNER_LC" >> $GITHUB_OUTPUT
49 - name: Generate ccache hash
52 CCACHE_HASH=$(md5sum include/kernel-* | awk '{ print $1 }' \
53 | md5sum | awk '{ print $1 }')
54 echo "ccache_hash=$CCACHE_HASH" >> $GITHUB_OUTPUT
56 # Per branch tools container tag
57 # By default stick to latest
58 # For official test targetting openwrt stable branch
59 # Get the branch or parse the tag and push dedicated tools containers
60 # For local test to use the correct container for stable release testing
61 # you need to use for the branch name a prefix of openwrt-[0-9][0-9].[0-9][0-9]-
62 - name: Determine tools container tag
63 id: determine_tools_container
66 if [ -n "${{ github.base_ref }}" ]; then
67 if echo "${{ github.base_ref }}" | grep -q -E '^openwrt-[0-9][0-9]\.[0-9][0-9]$'; then
68 CONTAINER_TAG="${{ github.base_ref }}"
70 elif [ ${{ github.ref_type }} == "branch" ]; then
71 if echo "${{ github.ref_name }}" | grep -q -E '^openwrt-[0-9][0-9]\.[0-9][0-9]$'; then
72 CONTAINER_TAG=${{ github.ref_name }}
73 elif echo "${{ github.ref_name }}" | grep -q -E '^openwrt-[0-9][0-9]\.[0-9][0-9]-'; then
74 CONTAINER_TAG="$(echo ${{ github.ref_name }} | sed 's/^\(openwrt-[0-9][0-9]\.[0-9][0-9]\)-.*/\1/')"
76 elif [ ${{ github.ref_type }} == "tag" ]; then
77 if echo "${{ github.ref_name }}" | grep -q -E '^v[0-9][0-9]\.[0-9][0-9]\..+'; then
78 CONTAINER_TAG=openwrt-"$(echo ${{ github.ref_name }} | sed 's/^v\([0-9][0-9]\.[0-9][0-9]\)\..\+/\1/')"
81 echo "Tools container to use tools:$CONTAINER_TAG"
82 echo "container_tag=$CONTAINER_TAG" >> $GITHUB_OUTPUT
85 name: Build ${{ inputs.target }}
87 runs-on: ubuntu-latest
89 container: ghcr.io/${{ needs.setup_build.outputs.owner_lc }}/tools:${{ needs.setup_build.outputs.container_tag }}
96 - name: Checkout master directory
97 uses: actions/checkout@v3
101 - name: Checkout packages feed
102 if: inputs.include_feeds == true
103 uses: actions/checkout@v3
105 repository: openwrt/packages
106 path: openwrt/feeds/packages
108 - name: Checkout luci feed
109 if: inputs.include_feeds == true
110 uses: actions/checkout@v3
112 repository: openwrt/luci
113 path: openwrt/feeds/luci
115 - name: Checkout routing feed
116 if: inputs.include_feeds == true
117 uses: actions/checkout@v3
119 repository: openwrt/routing
120 path: openwrt/feeds/routing
122 - name: Checkout telephony feed
123 if: inputs.include_feeds == true
124 uses: actions/checkout@v3
126 repository: openwrt/telephony
127 path: openwrt/feeds/telephony
129 - name: Fix permission
131 chown -R buildbot:buildbot openwrt
133 - name: Initialization environment
135 TARGET=$(echo ${{ inputs.target }} | cut -d "/" -f 1)
136 SUBTARGET=$(echo ${{ inputs.target }} | cut -d "/" -f 2)
137 echo "TARGET=$TARGET" >> "$GITHUB_ENV"
138 echo "SUBTARGET=$SUBTARGET" >> "$GITHUB_ENV"
140 - name: Update & Install feeds
141 if: inputs.include_feeds == true
142 shell: su buildbot -c "sh -e {0}"
143 working-directory: openwrt
145 ./scripts/feeds update -a
146 ./scripts/feeds install -a
148 - name: Parse toolchain file
149 if: inputs.build_toolchain == false
151 working-directory: openwrt
153 TOOLCHAIN_PATH=snapshots
155 if [ -n "${{ github.base_ref }}" ]; then
156 if echo "${{ github.base_ref }}" | grep -q -E '^openwrt-[0-9][0-9]\.[0-9][0-9]$'; then
157 major_ver="$(echo ${{ github.base_ref }} | sed 's/^openwrt-/v/')"
159 elif [ "${{ github.ref_type }}" = "branch" ]; then
160 if 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-/v/')"
162 elif echo "${{ github.ref_name }}" | grep -q -E '^openwrt-[0-9][0-9]\.[0-9][0-9]-'; then
163 major_ver="$(echo ${{ github.ref_name }} | sed 's/^openwrt-\([0-9][0-9]\.[0-9][0-9]\)-.*/v\1/')"
165 elif [ "${{ github.ref_type }}" = "tag" ]; then
166 if echo "${{ github.ref_name }}" | grep -q -E '^v[0-9][0-9]\.[0-9][0-9]\..+'; then
167 major_ver="$(echo ${{ github.ref_name }} | sed 's/^\(v[0-9][0-9]\.[0-9][0-9]\)\..\+/\1/')"
171 if [ -n "$major_ver" ]; then
173 latest_tag="$(git tag --sort=-creatordate -l $major_ver* | head -n1)"
174 if [ -n "$latest_tag" ]; then
175 TOOLCHAIN_PATH=releases/$(echo $latest_tag | sed 's/^v//')
179 SUMS_FILE="https://downloads.cdn.openwrt.org/$TOOLCHAIN_PATH/targets/${{ env.TARGET }}/${{ env.SUBTARGET }}/sha256sums"
180 if curl $SUMS_FILE | grep -q ".*openwrt-toolchain.*tar.xz"; then
181 TOOLCHAIN_STRING="$( curl $SUMS_FILE | grep ".*openwrt-toolchain.*tar.xz")"
182 TOOLCHAIN_FILE=$(echo "$TOOLCHAIN_STRING" | sed -n -e 's/.*\(openwrt-toolchain.*\).tar.xz/\1/p')
183 TOOLCHAIN_SHA256=$(echo "$TOOLCHAIN_STRING" | cut -d ' ' -f 1)
185 echo "toolchain-type=external_toolchain" >> $GITHUB_OUTPUT
186 elif curl $SUMS_FILE | grep -q ".*openwrt-sdk.*tar.xz"; then
187 TOOLCHAIN_STRING="$( curl $SUMS_FILE | grep ".*openwrt-sdk.*tar.xz")"
188 TOOLCHAIN_FILE=$(echo "$TOOLCHAIN_STRING" | sed -n -e 's/.*\(openwrt-sdk.*\).tar.xz/\1/p')
189 TOOLCHAIN_SHA256=$(echo "$TOOLCHAIN_STRING" | cut -d ' ' -f 1)
191 echo "toolchain-type=external_sdk" >> $GITHUB_OUTPUT
193 echo "toolchain-type=internal" >> $GITHUB_OUTPUT
196 echo "TOOLCHAIN_FILE=$TOOLCHAIN_FILE" >> "$GITHUB_ENV"
197 echo "TOOLCHAIN_SHA256=$TOOLCHAIN_SHA256" >> "$GITHUB_ENV"
198 echo "TOOLCHAIN_PATH=$TOOLCHAIN_PATH" >> "$GITHUB_ENV"
200 - name: Cache external toolchain/sdk
201 if: inputs.build_toolchain == false && steps.parse-toolchain.outputs.toolchain-type != 'internal'
202 id: cache-external-toolchain
203 uses: actions/cache@v3
205 path: openwrt/${{ env.TOOLCHAIN_FILE }}
206 key: ${{ env.TOOLCHAIN_FILE }}-${{ steps.parse-toolchain.outputs.toolchain-type }}-${{ env.TOOLCHAIN_SHA256 }}
209 uses: actions/cache@v3
211 path: openwrt/.ccache
212 key: ccache-kernel-${{ env.TARGET }}/${{ env.SUBTARGET }}-${{ needs.setup_build.outputs.ccache_hash }}
214 ccache-kernel-${{ env.TARGET }}/${{ env.SUBTARGET }}-
216 - name: Download external toolchain/sdk
217 if: inputs.build_toolchain == false && steps.cache-external-toolchain.outputs.cache-hit != 'true' && steps.parse-toolchain.outputs.toolchain-type != 'internal'
218 shell: su buildbot -c "sh -e {0}"
219 working-directory: openwrt
221 wget -O - https://downloads.cdn.openwrt.org/${{ env.TOOLCHAIN_PATH }}/targets/${{ env.TARGET }}/${{ env.SUBTARGET }}/${{ env.TOOLCHAIN_FILE }}.tar.xz \
224 - name: Extract prebuilt tools
225 shell: su buildbot -c "sh -e {0}"
226 working-directory: openwrt
227 run: ./scripts/ext-tools.sh --tools /tools.tar
229 - name: Configure testing kernel
230 if: inputs.testing == true
231 shell: su buildbot -c "sh -e {0}"
232 working-directory: openwrt
234 echo CONFIG_TESTING_KERNEL=y >> .config
236 - name: Configure all kernel modules
237 if: inputs.build_all_kmods == true
238 shell: su buildbot -c "sh -e {0}"
239 working-directory: openwrt
241 echo CONFIG_ALL_KMODS=y >> .config
243 - name: Configure all modules
244 if: inputs.build_all_modules == true
245 shell: su buildbot -c "sh -e {0}"
246 working-directory: openwrt
248 echo CONFIG_ALL=y >> .config
250 - name: Configure all boards
251 if: inputs.build_all_boards == true
252 shell: su buildbot -c "sh -e {0}"
253 working-directory: openwrt
255 echo CONFIG_TARGET_MULTI_PROFILE=y >> .config
256 echo CONFIG_TARGET_PER_DEVICE_ROOTFS=y >> .config
257 echo CONFIG_TARGET_ALL_PROFILES=y >> .config
259 - name: Configure external toolchain
260 if: inputs.build_toolchain == false && steps.parse-toolchain.outputs.toolchain-type == 'external_toolchain'
261 shell: su buildbot -c "sh -e {0}"
262 working-directory: openwrt
264 echo CONFIG_DEVEL=y >> .config
265 echo CONFIG_AUTOREMOVE=y >> .config
266 echo CONFIG_CCACHE=y >> .config
268 ./scripts/ext-toolchain.sh \
269 --toolchain ${{ env.TOOLCHAIN_FILE }}/toolchain-* \
271 --config ${{ env.TARGET }}/${{ env.SUBTARGET }}
273 - name: Adapt external sdk to external toolchain format
274 if: inputs.build_toolchain == false && steps.parse-toolchain.outputs.toolchain-type == 'external_sdk' && steps.cache-external-toolchain.outputs.cache-hit != 'true'
275 shell: su buildbot -c "sh -e {0}"
276 working-directory: openwrt
278 TOOLCHAIN_DIR=${{ env.TOOLCHAIN_FILE }}/staging_dir/$(ls ${{ env.TOOLCHAIN_FILE }}/staging_dir | grep toolchain)
279 TOOLCHAIN_BIN=$TOOLCHAIN_DIR/bin
282 # Find target name from toolchain info.mk
283 GNU_TARGET_NAME=$(cat $TOOLCHAIN_DIR/info.mk | grep TARGET_CROSS | sed 's/^TARGET_CROSS=\(.*\)-$/\1/')
287 # Revert sdk wrapper scripts applied to all the bins
288 for app in $(find . -name "*.bin"); do
289 TARGET_APP=$(echo $app | sed 's/\.\/\.\(.*\)\.bin/\1/')
291 mv .$TARGET_APP.bin $TARGET_APP
294 # Setup the wrapper script in the sdk toolchain dir simulating an external toolchain build
295 cp $OPENWRT_DIR/target/toolchain/files/wrapper.sh $GNU_TARGET_NAME-wrapper.sh
296 for app in cc gcc g++ c++ cpp ld as ; do
297 [ -f $GNU_TARGET_NAME-$app ] && mv $GNU_TARGET_NAME-$app $GNU_TARGET_NAME-$app.bin
298 ln -sf $GNU_TARGET_NAME-wrapper.sh $GNU_TARGET_NAME-$app
301 - name: Configure external toolchain with sdk
302 if: inputs.build_toolchain == false && steps.parse-toolchain.outputs.toolchain-type == 'external_sdk'
303 shell: su buildbot -c "sh -e {0}"
304 working-directory: openwrt
306 echo CONFIG_DEVEL=y >> .config
307 echo CONFIG_AUTOREMOVE=y >> .config
308 echo CONFIG_CCACHE=y >> .config
310 ./scripts/ext-toolchain.sh \
311 --toolchain ${{ env.TOOLCHAIN_FILE }}/staging_dir/toolchain-* \
313 --config ${{ env.TARGET }}/${{ env.SUBTARGET }}
315 - name: Configure internal toolchain
316 if: inputs.build_toolchain == true || steps.parse-toolchain.outputs.toolchain-type == 'internal'
317 shell: su buildbot -c "sh -e {0}"
318 working-directory: openwrt
320 echo CONFIG_DEVEL=y >> .config
321 echo CONFIG_AUTOREMOVE=y >> .config
322 echo CONFIG_CCACHE=y >> .config
324 echo "CONFIG_TARGET_${{ env.TARGET }}=y" >> .config
325 echo "CONFIG_TARGET_${{ env.TARGET }}_${{ env.SUBTARGET }}=y" >> .config
329 - name: Show configuration
330 shell: su buildbot -c "sh -e {0}"
331 working-directory: openwrt
332 run: ./scripts/diffconfig.sh
335 shell: su buildbot -c "sh -e {0}"
336 working-directory: openwrt
337 run: make tools/install -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
339 - name: Build toolchain
340 shell: su buildbot -c "sh -e {0}"
341 working-directory: openwrt
342 run: make toolchain/install -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
345 if: inputs.build_kernel == true
346 shell: su buildbot -c "sh -e {0}"
347 working-directory: openwrt
348 run: make target/compile -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
350 - name: Build Kernel Kmods
351 if: inputs.build_kernel == true
352 shell: su buildbot -c "sh -e {0}"
353 working-directory: openwrt
354 run: make package/linux/compile -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
356 - name: Build everything
357 if: inputs.build_full == true
358 shell: su buildbot -c "sh -e {0}"
359 working-directory: openwrt
360 run: make -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
364 uses: actions/upload-artifact@v3
366 name: ${{ env.TARGET }}-${{ env.SUBTARGET }}-logs