bsp_buildings.yml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. #
  2. # Copyright (c) 2025, RT-Thread Development Team
  3. #
  4. # SPDX-License-Identifier: Apache-2.0
  5. #
  6. # Change Logs:
  7. # Date Author Notes
  8. # 2025-03-22 Supperthomas 添加upload 上传编译固件
  9. # 2025-03-31 Hydevcode 将需要编译的bsp列表分离,根据修改的文件对相应的bsp编译
  10. name: RT-Thread BSP Static Build Check
  11. # Controls when the action will run. Triggers the workflow on push or pull request
  12. # events but only for the RT-Thread organization master branch
  13. on:
  14. # Runs at 16:00 UTC (BeiJing 00:00) every day
  15. schedule:
  16. - cron: '0 16 * * *'
  17. push:
  18. branches:
  19. - master
  20. paths-ignore:
  21. - documentation/**
  22. - '**/README.md'
  23. - '**/README_zh.md'
  24. pull_request:
  25. branches:
  26. - master
  27. paths-ignore:
  28. - documentation/**
  29. - '**/README.md'
  30. - '**/README_zh.md'
  31. repository_dispatch:
  32. types:
  33. - online-pkgs-static-building-trigger-event
  34. workflow_dispatch:
  35. permissions:
  36. contents: read # to fetch code (actions/checkout)
  37. jobs:
  38. generate-matrix:
  39. runs-on: ubuntu-22.04
  40. outputs:
  41. filtered_matrix: ${{ steps.filter.outputs.filtered_matrix }}
  42. steps:
  43. - name: Checkout repo
  44. uses: actions/checkout@v4
  45. with:
  46. sparse-checkout: .github/ALL_BSP_COMPILE.json
  47. persist-credentials: false
  48. - name: Read matrix config
  49. id: read-config
  50. run: |
  51. #读取ALL_BSP_COMPILE.json文件
  52. raw_matrix_base64=$(cat .github/ALL_BSP_COMPILE.json |egrep -v '^//'|base64 -w 0)
  53. echo "raw_matrix=$raw_matrix_base64" >> $GITHUB_OUTPUT
  54. - name: Get changed files
  55. id: changed_files
  56. if: github.event_name == 'pull_request'
  57. run: |
  58. changed_files=$(curl -s \
  59. "https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files" | \
  60. jq -r '.[].filename')
  61. prefix=$(echo "$changed_files" | cut -d'/' -f1 | sort -u )
  62. has_bsp=true
  63. for r in "$prefix"; do
  64. if [[ ! "$r" == "bsp" ]]; then
  65. has_bsp=false
  66. break
  67. fi
  68. done
  69. if [[ $has_bsp == true ]]; then
  70. changed_files=$(echo "${changed_files}"| cut -d'/' -f2 | sort -u)
  71. echo "CHANGED_FILES=${changed_files}" >> $GITHUB_OUTPUT
  72. fi
  73. #获取修改文件的路径,如果有bsp以外的文件夹则编译全部bsp,否则获取对应文件夹名
  74. echo "${changed_files}"
  75. - name: Filter matrix
  76. id: filter
  77. run: |
  78. raw_matrix=$(echo "${{ steps.read-config.outputs.raw_matrix }}" | base64 --decode)
  79. CHANGED_FILES="${{ steps.changed_files.outputs.CHANGED_FILES }}"
  80. # 将修改的文件路径与ALL_BSP_COMPILE.json文件的SUB_RTT_BSP进行判断,判断是否包含
  81. filtered_matrix="${filtered_matrix}"
  82. if [[ "$CHANGED_FILES" == "" ]]; then
  83. FILTER_CONDITION='.legs[]'
  84. filtered_matrix=$(jq -c "{legs: [$FILTER_CONDITION]}" <<< "$raw_matrix")
  85. else
  86. CONDITIONS=$(echo "$CHANGED_FILES" | awk '{for (i=1; i<=NF; i++) printf "contains(\"%s\") or ", $i}')
  87. CONDITIONS=${CONDITIONS% or }
  88. FILTER_CONDITION=".legs[] | select(any(.SUB_RTT_BSP[]; $CONDITIONS))"
  89. filtered_matrix=$(jq -c "{legs: [$FILTER_CONDITION]}" <<< "$raw_matrix")
  90. fi
  91. echo "filtered_matrix=${filtered_matrix}" >> $GITHUB_OUTPUT
  92. echo "${filtered_matrix}"
  93. build:
  94. runs-on: ubuntu-22.04
  95. needs: generate-matrix
  96. name: ${{ matrix.legs.RTT_BSP }}
  97. if: github.repository_owner == 'RT-Thread'
  98. strategy:
  99. fail-fast: false
  100. matrix: ${{ fromJson(needs.generate-matrix.outputs.filtered_matrix) }}
  101. steps:
  102. - uses: actions/checkout@v4
  103. - name: Set up Python
  104. uses: actions/setup-python@main
  105. with:
  106. python-version: 3.8
  107. - name: Install Tools
  108. shell: bash
  109. run: |
  110. wget https://raw.githubusercontent.com/RT-Thread/env/master/install_ubuntu.sh
  111. chmod 777 install_ubuntu.sh
  112. ./install_ubuntu.sh
  113. pip install -r tools/requirements.txt
  114. git config --global http.postBuffer 524288000
  115. echo "RTT_ROOT=${{ github.workspace }}" >> $GITHUB_ENV
  116. echo "RTT_CC=gcc" >> $GITHUB_ENV
  117. echo "export PATH=~/.env/tools/scripts:$PATH" > ~/.env/env.sh
  118. - name: Cache GCC Arm Toolchain
  119. if: ${{ matrix.legs.RTT_TOOL_CHAIN == 'sourcery-arm'}}
  120. id: cache-gcc-arm
  121. uses: actions/cache@main
  122. with:
  123. path: /opt/arm-gnu-toolchain-13.2.Rel1-x86_64-arm-none-eabi
  124. key: ${{ runner.os }}-arm-gnu-toolchain-13.2.Rel1-x86_64-arm-none-eabi
  125. - name: Download Arm ToolChains
  126. if: ${{ matrix.legs.RTT_TOOL_CHAIN == 'sourcery-arm' && (steps.cache-gcc-arm.outputs.cache-hit != 'true') }}
  127. shell: bash
  128. run: |
  129. wget -q https://github.com/RT-Thread/toolchains-ci/releases/download/v1.8/arm-gnu-toolchain-13.2.rel1-x86_64-arm-none-eabi.tar.xz
  130. sudo tar -xf arm-gnu-toolchain-13.2.rel1-x86_64-arm-none-eabi.tar.xz -C /opt
  131. - name: Install Arm ToolChains2
  132. if: ${{ matrix.legs.RTT_TOOL_CHAIN == 'sourcery-arm'}}
  133. shell: bash
  134. run: |
  135. /opt/arm-gnu-toolchain-13.2.Rel1-x86_64-arm-none-eabi/bin/arm-none-eabi-gcc --version
  136. echo "RTT_EXEC_PATH=/opt/arm-gnu-toolchain-13.2.Rel1-x86_64-arm-none-eabi/bin" >> $GITHUB_ENV
  137. - name: Install LLVM-Arm ToolChains
  138. if: ${{ matrix.legs.RTT_TOOL_CHAIN == 'llvm-arm' && success() }}
  139. shell: bash
  140. run: |
  141. wget -q https://github.com/ARM-software/LLVM-embedded-toolchain-for-Arm/releases/download/release-16.0.0/LLVMEmbeddedToolchainForArm-16.0.0-Linux-x86_64.tar.gz
  142. sudo tar zxf LLVMEmbeddedToolchainForArm-16.0.0-Linux-x86_64.tar.gz -C /opt
  143. sudo apt-get -qq install libncurses5 libncurses5-dev libncursesw5-dev
  144. /opt/LLVMEmbeddedToolchainForArm-16.0.0-Linux-x86_64/bin/clang --version
  145. echo "RTT_CC=llvm-arm" >> $GITHUB_ENV
  146. echo "RTT_EXEC_PATH=/opt/LLVMEmbeddedToolchainForArm-16.0.0-Linux-x86_64/bin" >> $GITHUB_ENV
  147. - name: Install AArch64 ToolChains
  148. if: ${{ matrix.legs.RTT_TOOL_CHAIN == 'sourcery-aarch64' && success() }}
  149. shell: bash
  150. run: |
  151. wget -q https://github.com/RT-Thread/toolchains-ci/releases/download/v1.6/gcc-arm-10.2-2020.11-x86_64-aarch64-none-elf.tar.xz
  152. sudo tar -xf gcc-arm-10.2-2020.11-x86_64-aarch64-none-elf.tar.xz -C /opt
  153. /opt/gcc-arm-10.2-2020.11-x86_64-aarch64-none-elf/bin/aarch64-none-elf-gcc --version
  154. echo "RTT_EXEC_PATH=/opt/gcc-arm-10.2-2020.11-x86_64-aarch64-none-elf/bin" >> $GITHUB_ENV
  155. - name: Install Mips ToolChains
  156. if: ${{ matrix.legs.RTT_TOOL_CHAIN == 'sourcery-mips' && success() }}
  157. shell: bash
  158. run: |
  159. wget -q https://github.com/RT-Thread/toolchains-ci/releases/download/v1.1/mips-2016.05-7-mips-sde-elf-i686-pc-linux-gnu.tar.bz2
  160. sudo tar xjf mips-2016.05-7-mips-sde-elf-i686-pc-linux-gnu.tar.bz2 -C /opt
  161. /opt/mips-2016.05/bin/mips-sde-elf-gcc --version
  162. echo "RTT_EXEC_PATH=/opt/mips-2016.05/bin" >> $GITHUB_ENV
  163. - name: Install Riscv64-unknown-elf ToolChains
  164. if: ${{ matrix.legs.RTT_TOOL_CHAIN == 'sourcery-riscv64-unknown-elf' && success() }}
  165. run: |
  166. wget -q https://github.com/RT-Thread/toolchains-ci/releases/download/v1.4/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14.tar.gz
  167. sudo tar zxf riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14.tar.gz -C /opt
  168. /opt/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14/bin/riscv64-unknown-elf-gcc --version
  169. echo "RTT_EXEC_PATH=/opt/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14/bin" >> $GITHUB_ENV
  170. - name: Install riscv32-unknown-elf Toolchains
  171. if: ${{ matrix.legs.RTT_TOOL_CHAIN == 'RISC-V-GCC-RV32' && success() }}
  172. run: |
  173. wget -q https://github.com/hpmicro/riscv-gnu-toolchain/releases/download/2022.05.15/riscv32-unknown-elf-newlib-multilib_2022.05.15_linux.tar.gz
  174. sudo tar zxf riscv32-unknown-elf-newlib-multilib_2022.05.15_linux.tar.gz -C /opt
  175. /opt/riscv32-unknown-elf-newlib-multilib/bin/riscv32-unknown-elf-gcc --version
  176. echo "RTT_EXEC_PATH=/opt/riscv32-unknown-elf-newlib-multilib/bin/" >> $GITHUB_ENV
  177. - name: Install Riscv-none-embed ToolChains
  178. if: ${{ matrix.legs.RTT_TOOL_CHAIN == 'sourcery-riscv-none-embed' && success() }}
  179. run: |
  180. wget -q https://github.com/RT-Thread/toolchains-ci/releases/download/v1.5/xpack-riscv-none-embed-gcc-8.3.0-2.3-linux-x64.tar.gz
  181. sudo tar zxf xpack-riscv-none-embed-gcc-8.3.0-2.3-linux-x64.tar.gz -C /opt
  182. /opt/xpack-riscv-none-embed-gcc-8.3.0-2.3/bin/riscv-none-embed-gcc --version
  183. echo "RTT_EXEC_PATH=/opt/xpack-riscv-none-embed-gcc-8.3.0-2.3/bin" >> $GITHUB_ENV
  184. - name: Install riscv32-esp-elf ToolChains
  185. if: ${{ matrix.legs.RTT_TOOL_CHAIN == 'sourcery-riscv32-esp32' && success() }}
  186. run: |
  187. wget -q https://github.com/espressif/crosstool-NG/releases/download/esp-2022r1-RC1/riscv32-esp-elf-gcc11_2_0-esp-2022r1-RC1-linux-amd64.tar.xz
  188. sudo tar xf riscv32-esp-elf-gcc11_2_0-esp-2022r1-RC1-linux-amd64.tar.xz -C /opt
  189. /opt/riscv32-esp-elf/bin/riscv32-esp-elf-gcc --version
  190. pip3 install esptool
  191. echo "RTT_EXEC_PATH=/opt/riscv32-esp-elf/bin" >> $GITHUB_ENV
  192. - name: Install Simulator Tools
  193. if: ${{ matrix.legs.RTT_TOOL_CHAIN == 'gcc' && success() }}
  194. run: |
  195. sudo apt-get -qq install libsdl2-dev
  196. - name: Install i386-unknown-elf Tools
  197. if: ${{ matrix.legs.RTT_TOOL_CHAIN == 'sourcery-i386-unknown-elf' && success() }}
  198. run: |
  199. wget -q https://github.com/zhkag/toolchains/releases/download/i386-unknown/i386-unknown-elf_for_x86_64-pc-linux-gnu_latest.tar.bz2
  200. sudo tar -jxvf i386-unknown-elf_for_x86_64-pc-linux-gnu_latest.tar.bz2 -C /opt
  201. /opt/i386-unknown-elf_for_x86_64-pc-linux-gnu/bin/i386-unknown-elf-gcc --version
  202. echo "RTT_EXEC_PATH=/opt/i386-unknown-elf_for_x86_64-pc-linux-gnu/bin" >> $GITHUB_ENV
  203. - name: Bsp Scons Compile
  204. if: ${{ success() }}
  205. shell: bash
  206. env:
  207. RTT_BSP: ${{ matrix.legs.RTT_BSP }}
  208. RTT_TOOL_CHAIN: ${{ matrix.legs.RTT_TOOL_CHAIN }}
  209. SRTT_BSP: ${{ join(matrix.legs.SUB_RTT_BSP, ',') }}
  210. run: |
  211. source ~/.env/env.sh
  212. python tools/ci/bsp_buildings.py
  213. - name: Upload output as artifact
  214. if: ${{ success() }}
  215. uses: actions/upload-artifact@main
  216. with:
  217. name: ${{ matrix.legs.RTT_BSP }}
  218. if-no-files-found: ignore
  219. path: output/
  220. - name: Post failure comment
  221. if: failure()
  222. run: |
  223. curl -X POST -H "Authorization: token ${{ secrets.RTTHREAD_GITHUB_TOKEN }}" \
  224. -d '{"body":"@${{ github.actor }}, Thank you for your contribution, but there was an error with the action. Could you please help check the BSP compilation issue? Thank you."}' \
  225. "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments"
  226. # 整合所有的output为一个文件夹
  227. collect-artifacts:
  228. needs: build
  229. runs-on: ubuntu-latest
  230. if: github.event_name != 'pull_request' #排除Pull request
  231. steps:
  232. #这里会下载所有产物
  233. - name: Download all artifacts
  234. uses: actions/download-artifact@main
  235. with:
  236. path: output/
  237. merge-multiple: true
  238. - run: ls -R output/
  239. - name: Upload combined output as artifact
  240. uses: actions/upload-artifact@main
  241. with:
  242. name: 00_all_bsp_output_${{ github.sha }}
  243. path: output/