CI: build: add support for per branch tools container
[openwrt/staging/hauke.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 working-directory: openwrt
147 run: |
148 TOOLCHAIN_STRING="$(curl "https://downloads.cdn.openwrt.org/snapshots/targets/${{ env.TARGET }}/${{ env.SUBTARGET }}/sha256sums" \
149 | grep ".*openwrt-toolchain.*tar.xz")"
150 TOOLCHAIN_FILE=$(echo "$TOOLCHAIN_STRING" | sed -n -e 's/.*\(openwrt-toolchain.*\).tar.xz/\1/p')
151 TOOLCHAIN_SHA256=$(echo "$TOOLCHAIN_STRING" | cut -d ' ' -f 1)
152
153 echo "TOOLCHAIN_FILE=$TOOLCHAIN_FILE" >> "$GITHUB_ENV"
154 echo "TOOLCHAIN_SHA256=$TOOLCHAIN_SHA256" >> "$GITHUB_ENV"
155
156 - name: Cache external toolchain
157 if: inputs.build_toolchain == false
158 id: cache-external-toolchain
159 uses: actions/cache@v3
160 with:
161 path: openwrt/${{ env.TOOLCHAIN_FILE }}
162 key: ${{ env.TOOLCHAIN_FILE }}-${{ env.TOOLCHAIN_SHA256 }}
163
164 - name: Cache ccache
165 uses: actions/cache@v3
166 with:
167 path: openwrt/.ccache
168 key: ccache-kernel-${{ env.TARGET }}/${{ env.SUBTARGET }}-${{ needs.setup_build.outputs.ccache_hash }}
169 restore-keys: |
170 ccache-kernel-${{ env.TARGET }}/${{ env.SUBTARGET }}-
171
172 - name: Download external toolchain
173 if: inputs.build_toolchain == false && steps.cache-external-toolchain.outputs.cache-hit != 'true'
174 shell: su buildbot -c "sh -e {0}"
175 working-directory: openwrt
176 run: |
177 wget -O - https://downloads.cdn.openwrt.org/snapshots/targets/${{ env.TARGET }}/${{ env.SUBTARGET }}/${TOOLCHAIN_FILE}.tar.xz \
178 | tar --xz -xf -
179
180 - name: Extract prebuilt tools
181 shell: su buildbot -c "sh -e {0}"
182 working-directory: openwrt
183 run: ./scripts/ext-tools.sh --tools /tools.tar
184
185 - name: Configure testing kernel
186 if: inputs.testing == true
187 shell: su buildbot -c "sh -e {0}"
188 working-directory: openwrt
189 run: |
190 echo CONFIG_TESTING_KERNEL=y >> .config
191
192 - name: Configure all kernel modules
193 if: inputs.build_all_kmods == true
194 shell: su buildbot -c "sh -e {0}"
195 working-directory: openwrt
196 run: |
197 echo CONFIG_ALL_KMODS=y >> .config
198
199 - name: Configure all modules
200 if: inputs.build_all_modules == true
201 shell: su buildbot -c "sh -e {0}"
202 working-directory: openwrt
203 run: |
204 echo CONFIG_ALL=y >> .config
205
206 - name: Configure all boards
207 if: inputs.build_all_boards == true
208 shell: su buildbot -c "sh -e {0}"
209 working-directory: openwrt
210 run: |
211 echo CONFIG_TARGET_MULTI_PROFILE=y >> .config
212 echo CONFIG_TARGET_PER_DEVICE_ROOTFS=y >> .config
213 echo CONFIG_TARGET_ALL_PROFILES=y >> .config
214
215 - name: Configure external toolchain
216 if: inputs.build_toolchain == false
217 shell: su buildbot -c "sh -e {0}"
218 working-directory: openwrt
219 run: |
220 echo CONFIG_DEVEL=y >> .config
221 echo CONFIG_AUTOREMOVE=y >> .config
222 echo CONFIG_CCACHE=y >> .config
223
224 ./scripts/ext-toolchain.sh \
225 --toolchain ${{ env.TOOLCHAIN_FILE }}/toolchain-* \
226 --overwrite-config \
227 --config ${{ env.TARGET }}/${{ env.SUBTARGET }}
228
229 - name: Configure internal toolchain
230 if: inputs.build_toolchain == true
231 shell: su buildbot -c "sh -e {0}"
232 working-directory: openwrt
233 run: |
234 echo CONFIG_DEVEL=y >> .config
235 echo CONFIG_AUTOREMOVE=y >> .config
236 echo CONFIG_CCACHE=y >> .config
237
238 echo "CONFIG_TARGET_${{ env.TARGET }}=y" >> .config
239 echo "CONFIG_TARGET_${{ env.TARGET }}_${{ env.SUBTARGET }}=y" >> .config
240
241 make defconfig
242
243 - name: Show configuration
244 shell: su buildbot -c "sh -e {0}"
245 working-directory: openwrt
246 run: ./scripts/diffconfig.sh
247
248 - name: Build tools
249 shell: su buildbot -c "sh -e {0}"
250 working-directory: openwrt
251 run: make tools/install -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
252
253 - name: Build toolchain
254 shell: su buildbot -c "sh -e {0}"
255 working-directory: openwrt
256 run: make toolchain/install -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
257
258 - name: Build Kernel
259 shell: su buildbot -c "sh -e {0}"
260 working-directory: openwrt
261 run: make target/compile -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
262
263 - name: Build Kernel Kmods
264 shell: su buildbot -c "sh -e {0}"
265 working-directory: openwrt
266 run: make package/linux/compile -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
267
268 - name: Build everything
269 if: inputs.build_full == true
270 shell: su buildbot -c "sh -e {0}"
271 working-directory: openwrt
272 run: make -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
273
274 - name: Upload logs
275 if: failure()
276 uses: actions/upload-artifact@v3
277 with:
278 name: ${{ env.TARGET }}-${{ env.SUBTARGET }}-logs
279 path: "openwrt/logs"