build.yml 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. name: 'Build'
  2. on:
  3. push:
  4. branches:
  5. - dev
  6. - "release*"
  7. tags:
  8. - '*'
  9. pull_request:
  10. env:
  11. TARGETS: f6
  12. jobs:
  13. build:
  14. runs-on: [self-hosted]
  15. steps:
  16. - name: 'Cleanup workspace'
  17. uses: AutoModality/action-clean@v1
  18. - name: 'Decontaminate previous build leftovers'
  19. run: |
  20. if [ -d .git ]
  21. then
  22. git submodule status \
  23. || git checkout `git rev-list --max-parents=0 HEAD | tail -n 1`
  24. fi
  25. - name: 'Checkout code'
  26. uses: actions/checkout@v2
  27. with:
  28. fetch-depth: 0
  29. submodules: true
  30. ref: ${{ github.event.pull_request.head.sha }}
  31. - name: 'Docker cache'
  32. uses: satackey/action-docker-layer-caching@v0.0.11
  33. continue-on-error: true
  34. with:
  35. key: docker-cache-${{ hashFiles('docker/**') }}-{hash}
  36. restore-keys: docker-cache-${{ hashFiles('docker/**') }}-
  37. - name: 'Build docker image'
  38. uses: ./.github/actions/docker
  39. - name: 'Make artifacts directory'
  40. run: |
  41. test -d artifacts && rm -rf artifacts || true
  42. mkdir artifacts
  43. - name: 'Generate suffix and folder name'
  44. id: names
  45. run: |
  46. REF=${{ github.ref }}
  47. if [[ ${{ github.event_name }} == 'pull_request' ]]; then
  48. REF=${{ github.head_ref }}
  49. fi
  50. BRANCH_OR_TAG=${REF##*/}
  51. SHA=$(git rev-parse --short HEAD)
  52. if [[ "${{ github.ref }}" == "refs/tags/"* ]]; then
  53. SUFFIX=${BRANCH_OR_TAG}
  54. else
  55. SUFFIX=${BRANCH_OR_TAG}-$(date +'%d%m%Y')-${SHA}
  56. fi
  57. echo "WORKFLOW_BRANCH_OR_TAG=${BRANCH_OR_TAG}" >> $GITHUB_ENV
  58. echo "::set-output name=artifacts-path::${BRANCH_OR_TAG}"
  59. echo "::set-output name=suffix::${SUFFIX}"
  60. echo "::set-output name=short-hash::${SHA}"
  61. echo "::set-output name=latest-target::${TARGETS[${#TARGETS[@]}-1]}"
  62. - name: 'Build bootloader in docker'
  63. uses: ./.github/actions/docker
  64. with:
  65. run: |
  66. for TARGET in ${TARGETS}
  67. do
  68. make -j$(nproc) -C bootloader TARGET=${TARGET}
  69. done
  70. - name: 'Build firmware in docker'
  71. uses: ./.github/actions/docker
  72. with:
  73. run: |
  74. for TARGET in ${TARGETS}
  75. do
  76. make -j$(nproc) -C firmware TARGET=${TARGET}
  77. done
  78. - name: 'Generate full hex file'
  79. if: ${{ !github.event.pull_request.head.repo.fork }}
  80. uses: ./.github/actions/docker
  81. with:
  82. run: |
  83. for TARGET in ${TARGETS}
  84. do
  85. srec_cat \
  86. bootloader/.obj/${TARGET}/bootloader.hex -Intel \
  87. firmware/.obj/${TARGET}/firmware.hex -Intel \
  88. -o firmware/.obj/${TARGET}/full.hex -Intel
  89. done
  90. - name: 'Move upload files'
  91. if: ${{ !github.event.pull_request.head.repo.fork }}
  92. uses: ./.github/actions/docker
  93. with:
  94. run: |
  95. for TARGET in ${TARGETS}
  96. do
  97. mv bootloader/.obj/${TARGET}/bootloader.dfu \
  98. artifacts/flipper-z-${TARGET}-bootloader-${{steps.names.outputs.suffix}}.dfu
  99. mv bootloader/.obj/${TARGET}/bootloader.bin \
  100. artifacts/flipper-z-${TARGET}-bootloader-${{steps.names.outputs.suffix}}.bin
  101. mv bootloader/.obj/${TARGET}/bootloader.elf \
  102. artifacts/flipper-z-${TARGET}-bootloader-${{steps.names.outputs.suffix}}.elf
  103. mv firmware/.obj/${TARGET}/firmware.dfu \
  104. artifacts/flipper-z-${TARGET}-firmware-${{steps.names.outputs.suffix}}.dfu
  105. mv firmware/.obj/${TARGET}/firmware.bin \
  106. artifacts/flipper-z-${TARGET}-firmware-${{steps.names.outputs.suffix}}.bin
  107. mv firmware/.obj/${TARGET}/firmware.elf \
  108. artifacts/flipper-z-${TARGET}-firmware-${{steps.names.outputs.suffix}}.elf
  109. done
  110. - name: 'Generate full dfu file'
  111. if: ${{ !github.event.pull_request.head.repo.fork }}
  112. uses: ./.github/actions/docker
  113. with:
  114. run: |
  115. for TARGET in ${TARGETS}
  116. do
  117. hex2dfu \
  118. -i firmware/.obj/${TARGET}/full.hex \
  119. -o artifacts/flipper-z-${TARGET}-full-${{steps.names.outputs.suffix}}.dfu \
  120. -l "Flipper Zero $(echo $TARGET | tr a-z A-Z)"
  121. done
  122. - name: 'Full flash asssembly: bootloader as base'
  123. if: ${{ !github.event.pull_request.head.repo.fork }}
  124. run: |
  125. for TARGET in ${TARGETS}
  126. do
  127. cp \
  128. artifacts/flipper-z-${TARGET}-bootloader-${{steps.names.outputs.suffix}}.bin \
  129. artifacts/flipper-z-${TARGET}-full-${{steps.names.outputs.suffix}}.bin
  130. done
  131. - name: 'Full flash asssembly: bootloader padding'
  132. if: ${{ !github.event.pull_request.head.repo.fork }}
  133. run: |
  134. for TARGET in ${TARGETS}
  135. do
  136. truncate -s 32768 artifacts/flipper-z-${TARGET}-full-${{steps.names.outputs.suffix}}.bin
  137. done
  138. - name: 'Full flash asssembly: append firmware'
  139. if: ${{ !github.event.pull_request.head.repo.fork }}
  140. run: |
  141. for TARGET in ${TARGETS}
  142. do
  143. cat \
  144. artifacts/flipper-z-${TARGET}-firmware-${{steps.names.outputs.suffix}}.bin \
  145. >> artifacts/flipper-z-${TARGET}-full-${{steps.names.outputs.suffix}}.bin
  146. done
  147. - name: 'Bundle core2 firmware'
  148. if: ${{ !github.event.pull_request.head.repo.fork }}
  149. run: |
  150. test -d core2_firmware && rm -rf core2_firmware || true
  151. mkdir core2_firmware
  152. cp \
  153. lib/STM32CubeWB/package.xml \
  154. lib/STM32CubeWB/Projects/STM32WB_Copro_Wireless_Binaries/STM32WB5x/stm32wb5x_FUS_fw.bin \
  155. lib/STM32CubeWB/Projects/STM32WB_Copro_Wireless_Binaries/STM32WB5x/stm32wb5x_FUS_fw_for_fus_0_5_3.bin \
  156. lib/STM32CubeWB/Projects/STM32WB_Copro_Wireless_Binaries/STM32WB5x/stm32wb5x_BLE_Stack_full_fw.bin \
  157. core2_firmware
  158. tar czpf artifacts/flipper-z-any-core2_firmware-${{steps.names.outputs.suffix}}.tgz core2_firmware
  159. - name: 'Bundle scripts'
  160. if: ${{ !github.event.pull_request.head.repo.fork }}
  161. run: |
  162. tar czpf artifacts/flipper-z-any-scripts-${{steps.names.outputs.suffix}}.tgz scripts
  163. - name: 'Bundle resources'
  164. if: ${{ !github.event.pull_request.head.repo.fork }}
  165. run: |
  166. tar czpf artifacts/flipper-z-any-resources-${{steps.names.outputs.suffix}}.tgz -C assets resources
  167. - name: 'Upload artifacts to update server'
  168. if: ${{ !github.event.pull_request.head.repo.fork }}
  169. uses: burnett01/rsync-deployments@4.1
  170. with:
  171. switches: -avzP --delete
  172. path: artifacts/
  173. remote_path: "${{ secrets.RSYNC_DEPLOY_BASE_PATH }}${{steps.names.outputs.artifacts-path}}/"
  174. remote_host: ${{ secrets.RSYNC_DEPLOY_HOST }}
  175. remote_port: ${{ secrets.RSYNC_DEPLOY_PORT }}
  176. remote_user: ${{ secrets.RSYNC_DEPLOY_USER }}
  177. remote_key: ${{ secrets.RSYNC_DEPLOY_KEY }}
  178. - name: 'Trigger update server reindex'
  179. if: ${{ !github.event.pull_request.head.repo.fork }}
  180. uses: wei/curl@master
  181. with:
  182. args: -X POST -F 'key=${{ secrets.REINDEX_KEY }}' ${{ secrets.REINDEX_URL }}
  183. - name: Find Previous Comment
  184. if: ${{ !github.event.pull_request.head.repo.fork && github.event.pull_request }}
  185. uses: peter-evans/find-comment@v1
  186. id: fc
  187. with:
  188. issue-number: ${{ github.event.pull_request.number }}
  189. comment-author: 'github-actions[bot]'
  190. body-includes: 'to flash the'
  191. - name: Create or update comment
  192. if: ${{ !github.event.pull_request.head.repo.fork && github.event.pull_request}}
  193. uses: peter-evans/create-or-update-comment@v1
  194. with:
  195. comment-id: ${{ steps.fc.outputs.comment-id }}
  196. issue-number: ${{ github.event.pull_request.number }}
  197. body: |
  198. [Click here](https://update.flipperzero.one/?url=https://update.flipperzero.one/builds/firmware/${{steps.names.outputs.artifacts-path}}/flipper-z-${{steps.names.outputs.latest-target}}-full-${{steps.names.outputs.suffix}}.dfu&channel=${{steps.names.outputs.artifacts-path}}&version=${{steps.names.outputs.short-hash}}) to flash the `${{steps.names.outputs.short-hash}}` version of this branch via WebUSB.
  199. edit-mode: replace