build.yml 8.3 KB

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