build.yml 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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,FlipperZero]
  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: 'Build the firmware in docker'
  63. uses: ./.github/actions/docker
  64. with:
  65. run: |
  66. set -e
  67. for TARGET in ${TARGETS}
  68. do
  69. ./fbt TARGET_HW=`echo ${TARGET} | sed 's/f//'` --with-updater updater_package ${{ startsWith(github.ref, 'refs/tags') && 'DEBUG=0 COMPACT=1' || '' }}
  70. done
  71. - name: 'Move upload files'
  72. if: ${{ !github.event.pull_request.head.repo.fork }}
  73. uses: ./.github/actions/docker
  74. with:
  75. run: |
  76. set -e
  77. for TARGET in ${TARGETS}
  78. do
  79. mv dist/${TARGET}-*/* artifacts/
  80. done
  81. - name: 'Bundle self-update package'
  82. if: ${{ !github.event.pull_request.head.repo.fork }}
  83. uses: ./.github/actions/docker
  84. with:
  85. run: |
  86. set -e
  87. for UPDATEBUNDLE in artifacts/*/
  88. do
  89. BUNDLE_NAME=`echo $UPDATEBUNDLE | cut -d'/' -f2`
  90. echo Packaging ${BUNDLE_NAME}
  91. tar czpf artifacts/flipper-z-${BUNDLE_NAME}.tgz -C artifacts ${BUNDLE_NAME}
  92. rm -rf artifacts/${BUNDLE_NAME}
  93. done
  94. - name: 'Bundle resources'
  95. if: ${{ !github.event.pull_request.head.repo.fork }}
  96. run: |
  97. tar czpf artifacts/flipper-z-any-resources-${{steps.names.outputs.suffix}}.tgz -C assets resources
  98. - name: 'Bundle core2 firmware'
  99. if: ${{ !github.event.pull_request.head.repo.fork }}
  100. uses: ./.github/actions/docker
  101. with:
  102. run: |
  103. ./fbt copro_dist
  104. tar czpf artifacts/flipper-z-any-core2_firmware-${{steps.names.outputs.suffix}}.tgz -C assets core2_firmware
  105. - name: 'Upload artifacts to update server'
  106. if: ${{ !github.event.pull_request.head.repo.fork }}
  107. uses: burnett01/rsync-deployments@5.1
  108. with:
  109. switches: -avzP --delete --mkpath
  110. path: artifacts/
  111. remote_path: "${{ secrets.RSYNC_DEPLOY_BASE_PATH }}${{steps.names.outputs.artifacts-path}}/"
  112. remote_host: ${{ secrets.RSYNC_DEPLOY_HOST }}
  113. remote_port: ${{ secrets.RSYNC_DEPLOY_PORT }}
  114. remote_user: ${{ secrets.RSYNC_DEPLOY_USER }}
  115. remote_key: ${{ secrets.RSYNC_DEPLOY_KEY }}
  116. - name: 'Trigger update server reindex'
  117. if: ${{ !github.event.pull_request.head.repo.fork }}
  118. uses: wei/curl@master
  119. with:
  120. args: -X POST -F 'key=${{ secrets.REINDEX_KEY }}' ${{ secrets.REINDEX_URL }}
  121. - name: 'Find Previous Comment'
  122. if: ${{ !github.event.pull_request.head.repo.fork && github.event.pull_request }}
  123. uses: peter-evans/find-comment@v1
  124. id: fc
  125. with:
  126. issue-number: ${{ github.event.pull_request.number }}
  127. comment-author: 'github-actions[bot]'
  128. body-includes: 'Compiled firmware for commit'
  129. - name: 'Create or update comment'
  130. if: ${{ !github.event.pull_request.head.repo.fork && github.event.pull_request}}
  131. uses: peter-evans/create-or-update-comment@v1
  132. with:
  133. comment-id: ${{ steps.fc.outputs.comment-id }}
  134. issue-number: ${{ github.event.pull_request.number }}
  135. body: |
  136. **Compiled firmware for commit `${{steps.names.outputs.short-hash}}`:**
  137. - [📦 Update package](https://update.flipperzero.one/builds/firmware/${{steps.names.outputs.artifacts-path}}/flipper-z-${{steps.names.outputs.default-target}}-update-${{steps.names.outputs.suffix}}.tgz)
  138. - [📥 DFU file](https://update.flipperzero.one/builds/firmware/${{steps.names.outputs.artifacts-path}}/flipper-z-${{steps.names.outputs.default-target}}-full-${{steps.names.outputs.suffix}}.dfu)
  139. - [☁️ Web updater](https://my.flipp.dev/?url=https://update.flipperzero.one/builds/firmware/${{steps.names.outputs.artifacts-path}}/flipper-z-${{steps.names.outputs.default-target}}-update-${{steps.names.outputs.suffix}}.tgz&channel=${{steps.names.outputs.artifacts-path}}&version=${{steps.names.outputs.short-hash}})
  140. edit-mode: replace
  141. compact:
  142. if: ${{ !startsWith(github.ref, 'refs/tags') }}
  143. runs-on: [self-hosted,FlipperZero]
  144. steps:
  145. - name: 'Cleanup workspace'
  146. uses: AutoModality/action-clean@v1
  147. - name: 'Decontaminate previous build leftovers'
  148. run: |
  149. if [ -d .git ]
  150. then
  151. git submodule status \
  152. || git checkout `git rev-list --max-parents=0 HEAD | tail -n 1`
  153. fi
  154. - name: 'Checkout code'
  155. uses: actions/checkout@v2
  156. with:
  157. fetch-depth: 0
  158. submodules: true
  159. ref: ${{ github.event.pull_request.head.sha }}
  160. - name: 'Build docker image'
  161. uses: ./.github/actions/docker
  162. - name: 'Generate suffix and folder name'
  163. id: names
  164. run: |
  165. REF=${{ github.ref }}
  166. if [[ ${{ github.event_name }} == 'pull_request' ]]; then
  167. REF=${{ github.head_ref }}
  168. fi
  169. BRANCH_OR_TAG=${REF#refs/*/}
  170. SHA=$(git rev-parse --short HEAD)
  171. if [[ "${{ github.ref }}" == "refs/tags/"* ]]; then
  172. SUFFIX=${BRANCH_OR_TAG//\//_}
  173. else
  174. SUFFIX=${BRANCH_OR_TAG//\//_}-$(date +'%d%m%Y')-${SHA}
  175. fi
  176. echo "WORKFLOW_BRANCH_OR_TAG=${BRANCH_OR_TAG}" >> $GITHUB_ENV
  177. echo "DIST_SUFFIX=${SUFFIX}" >> $GITHUB_ENV
  178. - name: 'Build the firmware in docker'
  179. uses: ./.github/actions/docker
  180. with:
  181. run: |
  182. set -e
  183. for TARGET in ${TARGETS}
  184. do
  185. ./fbt TARGET_HW=`echo ${TARGET} | sed 's/f//'` --with-updater updater_package DEBUG=0 COMPACT=1
  186. done