build.yml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. name: Build sub target
  2. on:
  3. workflow_call:
  4. inputs:
  5. target:
  6. required: true
  7. type: string
  8. testing:
  9. type: boolean
  10. build_toolchain:
  11. type: boolean
  12. include_feeds:
  13. type: boolean
  14. build_full:
  15. type: boolean
  16. build_kernel:
  17. type: boolean
  18. build_all_modules:
  19. type: boolean
  20. build_all_kmods:
  21. type: boolean
  22. build_all_boards:
  23. type: boolean
  24. use_openwrt_container:
  25. type: boolean
  26. default: true
  27. permissions:
  28. contents: read
  29. jobs:
  30. setup_build:
  31. name: Setup build ${{ inputs.target }}
  32. runs-on: ubuntu-latest
  33. outputs:
  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 }}
  37. steps:
  38. - name: Checkout
  39. uses: actions/checkout@v3
  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. if [ ${{ inputs.use_openwrt_container }} == "true" ]; then
  46. OWNER_LC=openwrt
  47. fi
  48. echo "owner_lc=$OWNER_LC" >> $GITHUB_OUTPUT
  49. - name: Generate ccache hash
  50. id: ccache_hash
  51. run: |
  52. CCACHE_HASH=$(md5sum include/kernel-* | awk '{ print $1 }' \
  53. | md5sum | awk '{ print $1 }')
  54. echo "ccache_hash=$CCACHE_HASH" >> $GITHUB_OUTPUT
  55. # Per branch tools container tag
  56. # By default stick to latest
  57. # For official test targetting openwrt stable branch
  58. # Get the branch or parse the tag and push dedicated tools containers
  59. # For local test to use the correct container for stable release testing
  60. # you need to use for the branch name a prefix of openwrt-[0-9][0-9].[0-9][0-9]-
  61. - name: Determine tools container tag
  62. id: determine_tools_container
  63. run: |
  64. CONTAINER_TAG=latest
  65. if [ -n "${{ github.base_ref }}" ]; then
  66. if echo "${{ github.base_ref }}" | grep -q -E '^openwrt-[0-9][0-9]\.[0-9][0-9]$'; then
  67. CONTAINER_TAG="${{ github.base_ref }}"
  68. fi
  69. elif [ ${{ github.ref_type }} == "branch" ]; then
  70. if echo "${{ github.ref_name }}" | grep -q -E '^openwrt-[0-9][0-9]\.[0-9][0-9]$'; then
  71. CONTAINER_TAG=${{ github.ref_name }}
  72. elif echo "${{ github.ref_name }}" | grep -q -E '^openwrt-[0-9][0-9]\.[0-9][0-9]-'; then
  73. CONTAINER_TAG="$(echo ${{ github.ref_name }} | sed 's/^\(openwrt-[0-9][0-9]\.[0-9][0-9]\)-.*/\1/')"
  74. fi
  75. elif [ ${{ github.ref_type }} == "tag" ]; then
  76. if echo "${{ github.ref_name }}" | grep -q -E '^v[0-9][0-9]\.[0-9][0-9]\..+'; then
  77. CONTAINER_TAG=openwrt-"$(echo ${{ github.ref_name }} | sed 's/^v\([0-9][0-9]\.[0-9][0-9]\)\..\+/\1/')"
  78. fi
  79. fi
  80. echo "Tools container to use tools:$CONTAINER_TAG"
  81. echo "container_tag=$CONTAINER_TAG" >> $GITHUB_OUTPUT
  82. build:
  83. name: Build ${{ inputs.target }}
  84. needs: setup_build
  85. runs-on: ubuntu-latest
  86. container: ghcr.io/${{ needs.setup_build.outputs.owner_lc }}/tools:${{ needs.setup_build.outputs.container_tag }}
  87. permissions:
  88. contents: read
  89. packages: read
  90. steps:
  91. - name: Checkout master directory
  92. uses: actions/checkout@v3
  93. with:
  94. path: openwrt
  95. - name: Checkout packages feed
  96. if: inputs.include_feeds == true
  97. uses: actions/checkout@v3
  98. with:
  99. repository: openwrt/packages
  100. path: openwrt/feeds/packages
  101. - name: Checkout luci feed
  102. if: inputs.include_feeds == true
  103. uses: actions/checkout@v3
  104. with:
  105. repository: openwrt/luci
  106. path: openwrt/feeds/luci
  107. - name: Checkout routing feed
  108. if: inputs.include_feeds == true
  109. uses: actions/checkout@v3
  110. with:
  111. repository: openwrt/routing
  112. path: openwrt/feeds/routing
  113. - name: Checkout telephony feed
  114. if: inputs.include_feeds == true
  115. uses: actions/checkout@v3
  116. with:
  117. repository: openwrt/telephony
  118. path: openwrt/feeds/telephony
  119. - name: Fix permission
  120. run: |
  121. chown -R buildbot:buildbot openwrt
  122. - name: Initialization environment
  123. run: |
  124. TARGET=$(echo ${{ inputs.target }} | cut -d "/" -f 1)
  125. SUBTARGET=$(echo ${{ inputs.target }} | cut -d "/" -f 2)
  126. echo "TARGET=$TARGET" >> "$GITHUB_ENV"
  127. echo "SUBTARGET=$SUBTARGET" >> "$GITHUB_ENV"
  128. - name: Prepare prebuilt tools
  129. shell: su buildbot -c "sh -e {0}"
  130. working-directory: openwrt
  131. run: |
  132. mkdir -p staging_dir build_dir
  133. ln -s /prebuilt_tools/staging_dir/host staging_dir/host
  134. ln -s /prebuilt_tools/build_dir/host build_dir/host
  135. ./scripts/ext-tools.sh --refresh
  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. - name: Parse toolchain file
  144. if: inputs.build_toolchain == false
  145. id: parse-toolchain
  146. working-directory: openwrt
  147. run: |
  148. TOOLCHAIN_PATH=snapshots
  149. if [ -n "${{ github.base_ref }}" ]; then
  150. if echo "${{ github.base_ref }}" | grep -q -E '^openwrt-[0-9][0-9]\.[0-9][0-9]$'; then
  151. major_ver="$(echo ${{ github.base_ref }} | sed 's/^openwrt-/v/')"
  152. fi
  153. elif [ "${{ github.ref_type }}" = "branch" ]; then
  154. if echo "${{ github.ref_name }}" | grep -q -E '^openwrt-[0-9][0-9]\.[0-9][0-9]$'; then
  155. major_ver="$(echo ${{ github.ref_name }} | sed 's/^openwrt-/v/')"
  156. elif echo "${{ github.ref_name }}" | grep -q -E '^openwrt-[0-9][0-9]\.[0-9][0-9]-'; then
  157. major_ver="$(echo ${{ github.ref_name }} | sed 's/^openwrt-\([0-9][0-9]\.[0-9][0-9]\)-.*/v\1/')"
  158. fi
  159. elif [ "${{ github.ref_type }}" = "tag" ]; then
  160. if echo "${{ github.ref_name }}" | grep -q -E '^v[0-9][0-9]\.[0-9][0-9]\..+'; then
  161. major_ver="$(echo ${{ github.ref_name }} | sed 's/^\(v[0-9][0-9]\.[0-9][0-9]\)\..\+/\1/')"
  162. fi
  163. fi
  164. if [ -n "$major_ver" ]; then
  165. git fetch --tags -f
  166. latest_tag="$(git tag --sort=-creatordate -l $major_ver* | head -n1)"
  167. if [ -n "$latest_tag" ]; then
  168. TOOLCHAIN_PATH=releases/$(echo $latest_tag | sed 's/^v//')
  169. fi
  170. fi
  171. SUMS_FILE="https://downloads.cdn.openwrt.org/$TOOLCHAIN_PATH/targets/${{ env.TARGET }}/${{ env.SUBTARGET }}/sha256sums"
  172. if curl $SUMS_FILE | grep -q ".*openwrt-toolchain.*tar.xz"; then
  173. TOOLCHAIN_STRING="$( curl $SUMS_FILE | grep ".*openwrt-toolchain.*tar.xz")"
  174. TOOLCHAIN_FILE=$(echo "$TOOLCHAIN_STRING" | sed -n -e 's/.*\(openwrt-toolchain.*\).tar.xz/\1/p')
  175. TOOLCHAIN_SHA256=$(echo "$TOOLCHAIN_STRING" | cut -d ' ' -f 1)
  176. echo "toolchain-type=external_toolchain" >> $GITHUB_OUTPUT
  177. elif curl $SUMS_FILE | grep -q ".*openwrt-sdk.*tar.xz"; then
  178. TOOLCHAIN_STRING="$( curl $SUMS_FILE | grep ".*openwrt-sdk.*tar.xz")"
  179. TOOLCHAIN_FILE=$(echo "$TOOLCHAIN_STRING" | sed -n -e 's/.*\(openwrt-sdk.*\).tar.xz/\1/p')
  180. TOOLCHAIN_SHA256=$(echo "$TOOLCHAIN_STRING" | cut -d ' ' -f 1)
  181. echo "toolchain-type=external_sdk" >> $GITHUB_OUTPUT
  182. else
  183. echo "toolchain-type=internal" >> $GITHUB_OUTPUT
  184. fi
  185. echo "TOOLCHAIN_FILE=$TOOLCHAIN_FILE" >> "$GITHUB_ENV"
  186. echo "TOOLCHAIN_SHA256=$TOOLCHAIN_SHA256" >> "$GITHUB_ENV"
  187. echo "TOOLCHAIN_PATH=$TOOLCHAIN_PATH" >> "$GITHUB_ENV"
  188. - name: Cache external toolchain/sdk
  189. if: inputs.build_toolchain == false && steps.parse-toolchain.outputs.toolchain-type != 'internal'
  190. id: cache-external-toolchain
  191. uses: actions/cache@v3
  192. with:
  193. path: openwrt/${{ env.TOOLCHAIN_FILE }}
  194. key: ${{ env.TOOLCHAIN_FILE }}-${{ steps.parse-toolchain.outputs.toolchain-type }}-${{ env.TOOLCHAIN_SHA256 }}
  195. - name: Cache ccache
  196. uses: actions/cache@v3
  197. with:
  198. path: openwrt/.ccache
  199. key: ccache-kernel-${{ env.TARGET }}/${{ env.SUBTARGET }}-${{ needs.setup_build.outputs.ccache_hash }}
  200. restore-keys: |
  201. ccache-kernel-${{ env.TARGET }}/${{ env.SUBTARGET }}-
  202. - name: Download external toolchain/sdk
  203. if: inputs.build_toolchain == false && steps.cache-external-toolchain.outputs.cache-hit != 'true' && steps.parse-toolchain.outputs.toolchain-type != 'internal'
  204. shell: su buildbot -c "sh -e {0}"
  205. working-directory: openwrt
  206. run: |
  207. wget -O - https://downloads.cdn.openwrt.org/${{ env.TOOLCHAIN_PATH }}/targets/${{ env.TARGET }}/${{ env.SUBTARGET }}/${{ env.TOOLCHAIN_FILE }}.tar.xz \
  208. | tar --xz -xf -
  209. - name: Configure testing kernel
  210. if: inputs.testing == true
  211. shell: su buildbot -c "sh -e {0}"
  212. working-directory: openwrt
  213. run: |
  214. echo CONFIG_TESTING_KERNEL=y >> .config
  215. - name: Configure all kernel modules
  216. if: inputs.build_all_kmods == true
  217. shell: su buildbot -c "sh -e {0}"
  218. working-directory: openwrt
  219. run: |
  220. echo CONFIG_ALL_KMODS=y >> .config
  221. - name: Configure all modules
  222. if: inputs.build_all_modules == true
  223. shell: su buildbot -c "sh -e {0}"
  224. working-directory: openwrt
  225. run: |
  226. echo CONFIG_ALL=y >> .config
  227. - name: Configure all boards
  228. if: inputs.build_all_boards == true
  229. shell: su buildbot -c "sh -e {0}"
  230. working-directory: openwrt
  231. run: |
  232. echo CONFIG_TARGET_MULTI_PROFILE=y >> .config
  233. echo CONFIG_TARGET_PER_DEVICE_ROOTFS=y >> .config
  234. echo CONFIG_TARGET_ALL_PROFILES=y >> .config
  235. - name: Configure external toolchain
  236. if: inputs.build_toolchain == false && steps.parse-toolchain.outputs.toolchain-type == 'external_toolchain'
  237. shell: su buildbot -c "sh -e {0}"
  238. working-directory: openwrt
  239. run: |
  240. echo CONFIG_DEVEL=y >> .config
  241. echo CONFIG_AUTOREMOVE=y >> .config
  242. echo CONFIG_CCACHE=y >> .config
  243. ./scripts/ext-toolchain.sh \
  244. --toolchain ${{ env.TOOLCHAIN_FILE }}/toolchain-* \
  245. --overwrite-config \
  246. --config ${{ env.TARGET }}/${{ env.SUBTARGET }}
  247. - name: Adapt external sdk to external toolchain format
  248. if: inputs.build_toolchain == false && steps.parse-toolchain.outputs.toolchain-type == 'external_sdk' && steps.cache-external-toolchain.outputs.cache-hit != 'true'
  249. shell: su buildbot -c "sh -e {0}"
  250. working-directory: openwrt
  251. run: |
  252. TOOLCHAIN_DIR=${{ env.TOOLCHAIN_FILE }}/staging_dir/$(ls ${{ env.TOOLCHAIN_FILE }}/staging_dir | grep toolchain)
  253. TOOLCHAIN_BIN=$TOOLCHAIN_DIR/bin
  254. OPENWRT_DIR=$(pwd)
  255. # Find target name from toolchain info.mk
  256. GNU_TARGET_NAME=$(cat $TOOLCHAIN_DIR/info.mk | grep TARGET_CROSS | sed 's/^TARGET_CROSS=\(.*\)-$/\1/')
  257. cd $TOOLCHAIN_BIN
  258. # Revert sdk wrapper scripts applied to all the bins
  259. for app in $(find . -name "*.bin"); do
  260. TARGET_APP=$(echo $app | sed 's/\.\/\.\(.*\)\.bin/\1/')
  261. rm $TARGET_APP
  262. mv .$TARGET_APP.bin $TARGET_APP
  263. done
  264. # Setup the wrapper script in the sdk toolchain dir simulating an external toolchain build
  265. cp $OPENWRT_DIR/target/toolchain/files/wrapper.sh $GNU_TARGET_NAME-wrapper.sh
  266. for app in cc gcc g++ c++ cpp ld as ; do
  267. [ -f $GNU_TARGET_NAME-$app ] && mv $GNU_TARGET_NAME-$app $GNU_TARGET_NAME-$app.bin
  268. ln -sf $GNU_TARGET_NAME-wrapper.sh $GNU_TARGET_NAME-$app
  269. done
  270. - name: Configure external toolchain with sdk
  271. if: inputs.build_toolchain == false && steps.parse-toolchain.outputs.toolchain-type == 'external_sdk'
  272. shell: su buildbot -c "sh -e {0}"
  273. working-directory: openwrt
  274. run: |
  275. echo CONFIG_DEVEL=y >> .config
  276. echo CONFIG_AUTOREMOVE=y >> .config
  277. echo CONFIG_CCACHE=y >> .config
  278. ./scripts/ext-toolchain.sh \
  279. --toolchain ${{ env.TOOLCHAIN_FILE }}/staging_dir/toolchain-* \
  280. --overwrite-config \
  281. --config ${{ env.TARGET }}/${{ env.SUBTARGET }}
  282. - name: Configure internal toolchain
  283. if: inputs.build_toolchain == true || steps.parse-toolchain.outputs.toolchain-type == 'internal'
  284. shell: su buildbot -c "sh -e {0}"
  285. working-directory: openwrt
  286. run: |
  287. echo CONFIG_DEVEL=y >> .config
  288. echo CONFIG_AUTOREMOVE=y >> .config
  289. echo CONFIG_CCACHE=y >> .config
  290. echo "CONFIG_TARGET_${{ env.TARGET }}=y" >> .config
  291. echo "CONFIG_TARGET_${{ env.TARGET }}_${{ env.SUBTARGET }}=y" >> .config
  292. make defconfig
  293. - name: Show configuration
  294. shell: su buildbot -c "sh -e {0}"
  295. working-directory: openwrt
  296. run: ./scripts/diffconfig.sh
  297. - name: Build tools
  298. shell: su buildbot -c "sh -e {0}"
  299. working-directory: openwrt
  300. run: make tools/install -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
  301. - name: Build toolchain
  302. shell: su buildbot -c "sh -e {0}"
  303. working-directory: openwrt
  304. run: make toolchain/install -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
  305. - name: Build Kernel
  306. if: inputs.build_kernel == true
  307. shell: su buildbot -c "sh -e {0}"
  308. working-directory: openwrt
  309. run: make target/compile -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
  310. - name: Build Kernel Kmods
  311. if: inputs.build_kernel == true
  312. shell: su buildbot -c "sh -e {0}"
  313. working-directory: openwrt
  314. run: make package/linux/compile -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
  315. - name: Build everything
  316. if: inputs.build_full == true
  317. shell: su buildbot -c "sh -e {0}"
  318. working-directory: openwrt
  319. run: make -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh
  320. - name: Upload logs
  321. if: failure()
  322. uses: actions/upload-artifact@v3
  323. with:
  324. name: ${{ env.TARGET }}-${{ env.SUBTARGET }}-logs
  325. path: "openwrt/logs"