build.yml 17 KB

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