b29698a77477a2db6d3c66f7dbed635ea704aca0
[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 build_toolchain:
10 type: boolean
11 include_feeds:
12 type: boolean
13 build_full:
14 type: boolean
15 build_all_modules:
16 type: boolean
17 build_all_kmods:
18 type: boolean
19
20 permissions:
21 contents: read
22
23 jobs:
24 setup_build:
25 name: Setup build
26 runs-on: ubuntu-latest
27 outputs:
28 owner_lc: ${{ steps.lower_owner.outputs.owner_lc }}
29 ccache_hash: ${{ steps.ccache_hash.outputs.ccache_hash }}
30
31 steps:
32 - name: Checkout
33 uses: actions/checkout@v3
34
35 - name: Set lower case owner name
36 id: lower_owner
37 run: |
38 OWNER_LC=$(echo "${{ github.repository_owner }}" \
39 | tr '[:upper:]' '[:lower:]')
40 echo "owner_lc=$OWNER_LC" >> $GITHUB_OUTPUT
41
42 - name: Generate ccache hash
43 id: ccache_hash
44 run: |
45 CCACHE_HASH=$(md5sum include/kernel-* | awk '{ print $1 }' \
46 | md5sum | awk '{ print $1 }')
47 echo "ccache_hash=$CCACHE_HASH" >> $GITHUB_OUTPUT
48
49 build:
50 name: Build with external toolchain
51 needs: setup_build
52 runs-on: ubuntu-latest
53
54 container: ghcr.io/${{ needs.setup_build.outputs.owner_lc }}/tools:latest
55
56 permissions:
57 contents: read
58 packages: read
59
60 steps:
61 - name: Checkout master directory
62 uses: actions/checkout@v3
63 with:
64 path: openwrt
65
66 - name: Checkout packages feed
67 if: inputs.include_feeds == true
68 uses: actions/checkout@v3
69 with:
70 repository: openwrt/packages
71 path: openwrt/feeds/packages
72
73 - name: Checkout luci feed
74 if: inputs.include_feeds == true
75 uses: actions/checkout@v3
76 with:
77 repository: openwrt/luci
78 path: openwrt/feeds/luci
79
80 - name: Checkout routing feed
81 if: inputs.include_feeds == true
82 uses: actions/checkout@v3
83 with:
84 repository: openwrt/routing
85 path: openwrt/feeds/routing
86
87 - name: Checkout telephony feed
88 if: inputs.include_feeds == true
89 uses: actions/checkout@v3
90 with:
91 repository: openwrt/telephony
92 path: openwrt/feeds/telephony
93
94 - name: Fix permission
95 run: |
96 chown -R buildbot:buildbot openwrt
97
98 - name: Initialization environment
99 run: |
100 TARGET=$(echo ${{ inputs.target }} | cut -d "/" -f 1)
101 SUBTARGET=$(echo ${{ inputs.target }} | cut -d "/" -f 2)
102 echo "TARGET=$TARGET" >> "$GITHUB_ENV"
103 echo "SUBTARGET=$SUBTARGET" >> "$GITHUB_ENV"
104
105 - name: Update & Install feeds
106 if: inputs.include_feeds == true
107 shell: su buildbot -c "sh -e {0}"
108 working-directory: openwrt
109 run: |
110 ./scripts/feeds update -a
111 ./scripts/feeds install -a
112
113 - name: Parse toolchain file
114 if: inputs.build_toolchain == false
115 working-directory: openwrt
116 run: |
117 TOOLCHAIN_STRING="$(curl "https://downloads.cdn.openwrt.org/snapshots/targets/${{ env.TARGET }}/${{ env.SUBTARGET }}/sha256sums" \
118 | grep ".*openwrt-toolchain.*tar.xz")"
119 TOOLCHAIN_FILE=$(echo "$TOOLCHAIN_STRING" | sed -n -e 's/.*\(openwrt-toolchain.*\).tar.xz/\1/p')
120 TOOLCHAIN_SHA256=$(echo "$TOOLCHAIN_STRING" | cut -d ' ' -f 1)
121
122 echo "TOOLCHAIN_FILE=$TOOLCHAIN_FILE" >> "$GITHUB_ENV"
123 echo "TOOLCHAIN_SHA256=$TOOLCHAIN_SHA256" >> "$GITHUB_ENV"
124
125 - name: Cache external toolchain
126 if: inputs.build_toolchain == false
127 id: cache-external-toolchain
128 uses: actions/cache@v3
129 with:
130 path: openwrt/${{ env.TOOLCHAIN_FILE }}
131 key: ${{ env.TOOLCHAIN_FILE }}-${{ env.TOOLCHAIN_SHA256 }}
132
133 - name: Cache ccache
134 uses: actions/cache@v3
135 with:
136 path: openwrt/.ccache
137 key: ccache-kernel-${{ env.TARGET }}/${{ env.SUBTARGET }}-${{ needs.setup_build.outputs.ccache_hash }}
138 restore-keys: |
139 ccache-kernel-${{ env.TARGET }}/${{ env.SUBTARGET }}-
140
141 - name: Download external toolchain
142 if: inputs.build_toolchain == false && steps.cache-external-toolchain.outputs.cache-hit != 'true'
143 shell: su buildbot -c "sh -e {0}"
144 working-directory: openwrt
145 run: |
146 wget -O - https://downloads.cdn.openwrt.org/snapshots/targets/${{ env.TARGET }}/${{ env.SUBTARGET }}/${TOOLCHAIN_FILE}.tar.xz \
147 | tar --xz -xf -
148
149 - name: Extract prebuilt tools
150 shell: su buildbot -c "sh -e {0}"
151 working-directory: openwrt
152 run: ./scripts/ext-tools.sh --tools /tools.tar
153
154 - name: Configure all kernel modules
155 if: inputs.build_all_kmods == true
156 shell: su buildbot -c "sh -e {0}"
157 working-directory: openwrt
158 run: |
159 echo CONFIG_ALL_KMODS=y >> .config
160
161 - name: Configure all modules
162 if: inputs.build_all_modules == true
163 shell: su buildbot -c "sh -e {0}"
164 working-directory: openwrt
165 run: |
166 echo CONFIG_ALL=y >> .config
167
168 - name: Configure external toolchain
169 if: inputs.build_toolchain == false
170 shell: su buildbot -c "sh -e {0}"
171 working-directory: openwrt
172 run: |
173 echo CONFIG_DEVEL=y >> .config
174 echo CONFIG_AUTOREMOVE=y >> .config
175 echo CONFIG_CCACHE=y >> .config
176
177 ./scripts/ext-toolchain.sh \
178 --toolchain ${{ env.TOOLCHAIN_FILE }}/toolchain-* \
179 --overwrite-config \
180 --config ${{ env.TARGET }}/${{ env.SUBTARGET }}
181
182 - name: Configure internal toolchain
183 if: inputs.build_toolchain == true
184 shell: su buildbot -c "sh -e {0}"
185 working-directory: openwrt
186 run: |
187 echo CONFIG_DEVEL=y >> .config
188 echo CONFIG_AUTOREMOVE=y >> .config
189 echo CONFIG_CCACHE=y >> .config
190
191 echo "CONFIG_TARGET_${{ env.TARGET }}=y" >> .config
192 echo "CONFIG_TARGET_${{ env.TARGET }}_${{ env.SUBTARGET }}=y" >> .config
193
194 make defconfig
195
196 - name: Show configuration
197 shell: su buildbot -c "sh -e {0}"
198 working-directory: openwrt
199 run: ./scripts/diffconfig.sh
200
201 - name: Build tools
202 shell: su buildbot -c "sh -e {0}"
203 working-directory: openwrt
204 run: make tools/install -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
205
206 - name: Build toolchain
207 shell: su buildbot -c "sh -e {0}"
208 working-directory: openwrt
209 run: make toolchain/install -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
210
211 - name: Build Kernel
212 shell: su buildbot -c "sh -e {0}"
213 working-directory: openwrt
214 run: make target/compile -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
215
216 - name: Build Kernel Kmods
217 shell: su buildbot -c "sh -e {0}"
218 working-directory: openwrt
219 run: make package/linux/compile -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
220
221 - name: Build everything
222 if: inputs.build_full == true
223 shell: su buildbot -c "sh -e {0}"
224 working-directory: openwrt
225 run: make -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
226
227 - name: Upload logs
228 if: failure()
229 uses: actions/upload-artifact@v3
230 with:
231 name: ${{ env.TARGET }}-${{ env.SUBTARGET }}-logs
232 path: "openwrt/logs"