build.yml 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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,FlipperZeroShell]
  16. steps:
  17. - name: 'Decontaminate previous build leftovers'
  18. run: |
  19. if [ -d .git ]
  20. then
  21. git submodule status \
  22. || git checkout `git rev-list --max-parents=0 HEAD | tail -n 1`
  23. fi
  24. - name: 'Checkout code'
  25. uses: actions/checkout@v2
  26. with:
  27. fetch-depth: 0
  28. ref: ${{ github.event.pull_request.head.sha }}
  29. - name: 'Make artifacts directory'
  30. run: |
  31. test -d artifacts && rm -rf artifacts || true
  32. mkdir artifacts
  33. - name: 'Generate suffix and folder name'
  34. id: names
  35. run: |
  36. REF=${{ github.ref }}
  37. if [[ ${{ github.event_name }} == 'pull_request' ]]; then
  38. REF=${{ github.head_ref }}
  39. fi
  40. BRANCH_OR_TAG=${REF#refs/*/}
  41. SHA=$(git rev-parse --short HEAD)
  42. if [[ "${{ github.ref }}" == "refs/tags/"* ]]; then
  43. SUFFIX=${BRANCH_OR_TAG//\//_}
  44. else
  45. SUFFIX=${BRANCH_OR_TAG//\//_}-$(date +'%d%m%Y')-${SHA}
  46. fi
  47. echo "WORKFLOW_BRANCH_OR_TAG=${BRANCH_OR_TAG}" >> $GITHUB_ENV
  48. echo "DIST_SUFFIX=${SUFFIX}" >> $GITHUB_ENV
  49. echo "::set-output name=artifacts-path::${BRANCH_OR_TAG}"
  50. echo "::set-output name=suffix::${SUFFIX}"
  51. echo "::set-output name=short-hash::${SHA}"
  52. echo "::set-output name=default-target::${DEFAULT_TARGET}"
  53. - name: 'Bundle scripts'
  54. if: ${{ !github.event.pull_request.head.repo.fork }}
  55. run: |
  56. tar czpf artifacts/flipper-z-any-scripts-${{steps.names.outputs.suffix}}.tgz scripts
  57. - name: 'Build the firmware'
  58. run: |
  59. set -e
  60. for TARGET in ${TARGETS}
  61. do
  62. FBT_TOOLCHAIN_PATH=/opt ./fbt TARGET_HW=`echo ${TARGET} | sed 's/f//'` updater_package ${{ startsWith(github.ref, 'refs/tags') && 'DEBUG=0 COMPACT=1' || '' }}
  63. done
  64. - name: 'Move upload files'
  65. if: ${{ !github.event.pull_request.head.repo.fork }}
  66. run: |
  67. set -e
  68. for TARGET in ${TARGETS}
  69. do
  70. mv dist/${TARGET}-*/* artifacts/
  71. done
  72. - name: 'Bundle self-update package'
  73. if: ${{ !github.event.pull_request.head.repo.fork }}
  74. run: |
  75. set -e
  76. for UPDATEBUNDLE in artifacts/*/
  77. do
  78. BUNDLE_NAME=`echo $UPDATEBUNDLE | cut -d'/' -f2`
  79. echo Packaging ${BUNDLE_NAME}
  80. tar czpf artifacts/flipper-z-${BUNDLE_NAME}.tgz -C artifacts ${BUNDLE_NAME}
  81. rm -rf artifacts/${BUNDLE_NAME}
  82. done
  83. - name: "Check for uncommitted changes"
  84. run: |
  85. git diff --exit-code
  86. - name: 'Bundle resources'
  87. if: ${{ !github.event.pull_request.head.repo.fork }}
  88. run: |
  89. tar czpf artifacts/flipper-z-any-resources-${{steps.names.outputs.suffix}}.tgz -C assets resources
  90. - name: 'Bundle core2 firmware'
  91. if: ${{ !github.event.pull_request.head.repo.fork }}
  92. run: |
  93. FBT_TOOLCHAIN_PATH=/opt ./fbt copro_dist
  94. tar czpf artifacts/flipper-z-any-core2_firmware-${{steps.names.outputs.suffix}}.tgz -C assets core2_firmware
  95. - name: 'Copy .map file'
  96. run: |
  97. cp build/f7-firmware-*/firmware.elf.map artifacts/flipper-z-f7-firmware-${{steps.names.outputs.suffix}}.elf.map
  98. - name: 'Upload artifacts to update server'
  99. if: ${{ !github.event.pull_request.head.repo.fork }}
  100. run: |
  101. echo "${{ secrets.RSYNC_DEPLOY_KEY }}" > deploy_key;
  102. chmod 600 ./deploy_key;
  103. rsync -avzP --delete --mkpath \
  104. -e 'ssh -p ${{ secrets.RSYNC_DEPLOY_PORT }} -i ./deploy_key' \
  105. artifacts/ ${{ secrets.RSYNC_DEPLOY_USER }}@${{ secrets.RSYNC_DEPLOY_HOST }}:"${{ secrets.RSYNC_DEPLOY_BASE_PATH }}${{steps.names.outputs.artifacts-path}}/";
  106. rm ./deploy_key;
  107. - name: 'Trigger update server reindex'
  108. if: ${{ !github.event.pull_request.head.repo.fork }}
  109. run: curl -X POST -F 'key=${{ secrets.REINDEX_KEY }}' ${{ secrets.REINDEX_URL }}
  110. - name: 'Find Previous Comment'
  111. if: ${{ !github.event.pull_request.head.repo.fork && github.event.pull_request }}
  112. uses: peter-evans/find-comment@v1
  113. id: fc
  114. with:
  115. issue-number: ${{ github.event.pull_request.number }}
  116. comment-author: 'github-actions[bot]'
  117. body-includes: 'Compiled firmware for commit'
  118. - name: 'Create or update comment'
  119. if: ${{ !github.event.pull_request.head.repo.fork && github.event.pull_request}}
  120. uses: peter-evans/create-or-update-comment@v1
  121. with:
  122. comment-id: ${{ steps.fc.outputs.comment-id }}
  123. issue-number: ${{ github.event.pull_request.number }}
  124. body: |
  125. **Compiled firmware for commit `${{steps.names.outputs.short-hash}}`:**
  126. - [📦 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)
  127. - [📥 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)
  128. - [☁️ 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}})
  129. edit-mode: replace
  130. compact:
  131. if: ${{ !startsWith(github.ref, 'refs/tags') }}
  132. runs-on: [self-hosted,FlipperZeroShell]
  133. steps:
  134. - name: 'Decontaminate previous build leftovers'
  135. run: |
  136. if [ -d .git ]
  137. then
  138. git submodule status \
  139. || git checkout `git rev-list --max-parents=0 HEAD | tail -n 1`
  140. fi
  141. - name: 'Checkout code'
  142. uses: actions/checkout@v2
  143. with:
  144. fetch-depth: 0
  145. submodules: true
  146. ref: ${{ github.event.pull_request.head.sha }}
  147. - name: 'Generate suffix and folder name'
  148. id: names
  149. run: |
  150. REF=${{ github.ref }}
  151. if [[ ${{ github.event_name }} == 'pull_request' ]]; then
  152. REF=${{ github.head_ref }}
  153. fi
  154. BRANCH_OR_TAG=${REF#refs/*/}
  155. SHA=$(git rev-parse --short HEAD)
  156. if [[ "${{ github.ref }}" == "refs/tags/"* ]]; then
  157. SUFFIX=${BRANCH_OR_TAG//\//_}
  158. else
  159. SUFFIX=${BRANCH_OR_TAG//\//_}-$(date +'%d%m%Y')-${SHA}
  160. fi
  161. echo "WORKFLOW_BRANCH_OR_TAG=${BRANCH_OR_TAG}" >> $GITHUB_ENV
  162. echo "DIST_SUFFIX=${SUFFIX}" >> $GITHUB_ENV
  163. - name: 'Build the firmware'
  164. run: |
  165. set -e
  166. for TARGET in ${TARGETS}
  167. do
  168. FBT_TOOLCHAIN_PATH=/opt ./fbt TARGET_HW=`echo ${TARGET} | sed 's/f//'` updater_package DEBUG=0 COMPACT=1
  169. done