build.yml 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. name: 'Build'
  2. on:
  3. push:
  4. branches:
  5. - dev
  6. - "release*"
  7. tags:
  8. - '*'
  9. pull_request:
  10. env:
  11. TARGETS: f7
  12. DEFAULT_TARGET: f7
  13. jobs:
  14. main:
  15. runs-on: [self-hosted,Office]
  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: 'Build docker image'
  33. uses: ./.github/actions/docker
  34. - name: 'Make artifacts directory'
  35. run: |
  36. test -d artifacts && rm -rf artifacts || true
  37. mkdir artifacts
  38. - name: 'Generate suffix and folder name'
  39. id: names
  40. run: |
  41. REF=${{ github.ref }}
  42. if [[ ${{ github.event_name }} == 'pull_request' ]]; then
  43. REF=${{ github.head_ref }}
  44. fi
  45. BRANCH_OR_TAG=${REF#refs/*/}
  46. SHA=$(git rev-parse --short HEAD)
  47. if [[ "${{ github.ref }}" == "refs/tags/"* ]]; then
  48. SUFFIX=${BRANCH_OR_TAG//\//_}
  49. else
  50. SUFFIX=${BRANCH_OR_TAG//\//_}-$(date +'%d%m%Y')-${SHA}
  51. fi
  52. echo "WORKFLOW_BRANCH_OR_TAG=${BRANCH_OR_TAG}" >> $GITHUB_ENV
  53. echo "DIST_SUFFIX=${SUFFIX}" >> $GITHUB_ENV
  54. echo "::set-output name=artifacts-path::${BRANCH_OR_TAG}"
  55. echo "::set-output name=suffix::${SUFFIX}"
  56. echo "::set-output name=short-hash::${SHA}"
  57. echo "::set-output name=default-target::${DEFAULT_TARGET}"
  58. - name: 'Bundle scripts'
  59. if: ${{ !github.event.pull_request.head.repo.fork }}
  60. run: |
  61. tar czpf artifacts/flipper-z-any-scripts-${{steps.names.outputs.suffix}}.tgz scripts
  62. - name: 'Rebuild Assets'
  63. uses: ./.github/actions/docker
  64. with:
  65. run: |
  66. set -e
  67. make -C assets clean
  68. make -C assets
  69. git diff --quiet || ( echo "Assets recompilation required."; exit 255 )
  70. - name: 'Build the firmware in docker'
  71. uses: ./.github/actions/docker
  72. with:
  73. run: |
  74. set -e
  75. for TARGET in ${TARGETS}
  76. do
  77. make updater_package TARGET=${TARGET} ${{ startsWith(github.ref, 'refs/tags') && 'DEBUG=0 COMPACT=1' || '' }}
  78. done
  79. - name: 'Move upload files'
  80. if: ${{ !github.event.pull_request.head.repo.fork }}
  81. uses: ./.github/actions/docker
  82. with:
  83. run: |
  84. set -e
  85. for TARGET in ${TARGETS}
  86. do
  87. mv dist/${TARGET}/* artifacts/
  88. done
  89. - name: 'Bundle self-update package'
  90. if: ${{ !github.event.pull_request.head.repo.fork }}
  91. uses: ./.github/actions/docker
  92. with:
  93. run: |
  94. set -e
  95. for UPDATEBUNDLE in artifacts/*/
  96. do
  97. BUNDLE_NAME=`echo $UPDATEBUNDLE | cut -d'/' -f2`
  98. echo Packaging ${BUNDLE_NAME}
  99. tar czpf artifacts/flipper-z-${BUNDLE_NAME}.tgz -C artifacts ${BUNDLE_NAME}
  100. rm -rf artifacts/${BUNDLE_NAME}
  101. done
  102. - name: 'Bundle resources'
  103. if: ${{ !github.event.pull_request.head.repo.fork }}
  104. run: |
  105. ./scripts/assets.py manifest assets/resources
  106. tar czpf artifacts/flipper-z-any-resources-${{steps.names.outputs.suffix}}.tgz -C assets resources
  107. - name: 'Bundle core2 firmware'
  108. if: ${{ !github.event.pull_request.head.repo.fork }}
  109. run: |
  110. test -d core2_firmware && rm -rf core2_firmware || true
  111. mkdir core2_firmware
  112. ./scripts/assets.py copro lib/STM32CubeWB core2_firmware STM32WB5x
  113. tar czpf artifacts/flipper-z-any-core2_firmware-${{steps.names.outputs.suffix}}.tgz core2_firmware
  114. - name: 'Upload artifacts to update server'
  115. if: ${{ !github.event.pull_request.head.repo.fork }}
  116. uses: burnett01/rsync-deployments@5.1
  117. with:
  118. switches: -avzP --delete --mkpath
  119. path: artifacts/
  120. remote_path: "${{ secrets.RSYNC_DEPLOY_BASE_PATH }}${{steps.names.outputs.artifacts-path}}/"
  121. remote_host: ${{ secrets.RSYNC_DEPLOY_HOST }}
  122. remote_port: ${{ secrets.RSYNC_DEPLOY_PORT }}
  123. remote_user: ${{ secrets.RSYNC_DEPLOY_USER }}
  124. remote_key: ${{ secrets.RSYNC_DEPLOY_KEY }}
  125. - name: 'Trigger update server reindex'
  126. if: ${{ !github.event.pull_request.head.repo.fork }}
  127. uses: wei/curl@master
  128. with:
  129. args: -X POST -F 'key=${{ secrets.REINDEX_KEY }}' ${{ secrets.REINDEX_URL }}
  130. - name: 'Find Previous Comment'
  131. if: ${{ !github.event.pull_request.head.repo.fork && github.event.pull_request }}
  132. uses: peter-evans/find-comment@v1
  133. id: fc
  134. with:
  135. issue-number: ${{ github.event.pull_request.number }}
  136. comment-author: 'github-actions[bot]'
  137. body-includes: 'to flash the'
  138. - name: 'Create or update comment'
  139. if: ${{ !github.event.pull_request.head.repo.fork && github.event.pull_request}}
  140. uses: peter-evans/create-or-update-comment@v1
  141. with:
  142. comment-id: ${{ steps.fc.outputs.comment-id }}
  143. issue-number: ${{ github.event.pull_request.number }}
  144. body: |
  145. [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}}&target=${{steps.names.outputs.default-target}}) to flash the `${{steps.names.outputs.short-hash}}` version of this branch via WebUSB.
  146. edit-mode: replace
  147. compact:
  148. if: ${{ !startsWith(github.ref, 'refs/tags') }}
  149. runs-on: [self-hosted,koteeq]
  150. steps:
  151. - name: 'Cleanup workspace'
  152. uses: AutoModality/action-clean@v1
  153. - name: 'Decontaminate previous build leftovers'
  154. run: |
  155. if [ -d .git ]
  156. then
  157. git submodule status \
  158. || git checkout `git rev-list --max-parents=0 HEAD | tail -n 1`
  159. fi
  160. - name: 'Checkout code'
  161. uses: actions/checkout@v2
  162. with:
  163. fetch-depth: 0
  164. submodules: true
  165. ref: ${{ github.event.pull_request.head.sha }}
  166. - name: 'Build docker image'
  167. uses: ./.github/actions/docker
  168. - name: 'Generate suffix and folder name'
  169. id: names
  170. run: |
  171. REF=${{ github.ref }}
  172. if [[ ${{ github.event_name }} == 'pull_request' ]]; then
  173. REF=${{ github.head_ref }}
  174. fi
  175. BRANCH_OR_TAG=${REF#refs/*/}
  176. SHA=$(git rev-parse --short HEAD)
  177. if [[ "${{ github.ref }}" == "refs/tags/"* ]]; then
  178. SUFFIX=${BRANCH_OR_TAG//\//_}
  179. else
  180. SUFFIX=${BRANCH_OR_TAG//\//_}-$(date +'%d%m%Y')-${SHA}
  181. fi
  182. echo "WORKFLOW_BRANCH_OR_TAG=${BRANCH_OR_TAG}" >> $GITHUB_ENV
  183. echo "DIST_SUFFIX=${SUFFIX}" >> $GITHUB_ENV
  184. - name: 'Rebuild Assets'
  185. uses: ./.github/actions/docker
  186. with:
  187. run: |
  188. set -e
  189. make -C assets clean
  190. make -C assets
  191. - name: 'Build the firmware in docker'
  192. uses: ./.github/actions/docker
  193. with:
  194. run: |
  195. set -e
  196. for TARGET in ${TARGETS}
  197. do
  198. make TARGET=${TARGET} DEBUG=0 COMPACT=1
  199. done