build.yml 14 KB

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