build.yml 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. name: 'Build'
  2. on:
  3. push:
  4. branches:
  5. - dev
  6. tags:
  7. - '*'
  8. pull_request:
  9. env:
  10. TARGETS: f7
  11. DEFAULT_TARGET: f7
  12. FBT_TOOLCHAIN_PATH: /runner/_work
  13. jobs:
  14. main:
  15. runs-on: [self-hosted,FlipperZeroShell]
  16. steps:
  17. - name: 'Wipe workspace'
  18. run: find ./ -mount -maxdepth 1 -exec rm -rf {} \;
  19. - name: 'Checkout code'
  20. uses: actions/checkout@v3
  21. with:
  22. fetch-depth: 1
  23. ref: ${{ github.event.pull_request.head.sha }}
  24. - name: 'Get commit details'
  25. id: names
  26. run: |
  27. if [[ ${{ github.event_name }} == 'pull_request' ]]; then
  28. TYPE="pull"
  29. elif [[ "${{ github.ref }}" == "refs/tags/"* ]]; then
  30. TYPE="tag"
  31. else
  32. TYPE="other"
  33. fi
  34. python3 scripts/get_env.py "--event_file=${{ github.event_path }}" "--type=$TYPE" || cat "${{ github.event_path }}"
  35. echo random_hash=$(openssl rand -base64 40 | shasum -a 256 | awk '{print $1}') >> $GITHUB_OUTPUT
  36. echo "event_type=$TYPE" >> $GITHUB_OUTPUT
  37. - name: 'Check API versions'
  38. run: |
  39. set -e
  40. N_API_HEADER_SIGNATURES=`ls -1 firmware/targets/f*/api_symbols.csv | xargs -I {} sh -c "head -n2 {} | md5sum" | sort -u | wc -l`
  41. if [ $N_API_HEADER_SIGNATURES != 1 ] ; then
  42. echo API versions aren\'t matching for available targets. Please update!
  43. head -n2 firmware/targets/f*/api_symbols.csv
  44. exit 1
  45. fi
  46. - name: 'Make artifacts directory'
  47. run: |
  48. rm -rf artifacts
  49. rm -rf map_analyser_files
  50. mkdir artifacts
  51. mkdir map_analyser_files
  52. - name: 'Bundle scripts'
  53. if: ${{ !github.event.pull_request.head.repo.fork }}
  54. run: |
  55. tar czpf artifacts/flipper-z-any-scripts-${SUFFIX}.tgz scripts
  56. - name: 'Build the firmware'
  57. run: |
  58. set -e
  59. for TARGET in ${TARGETS}; do
  60. TARGET="$(echo "${TARGET}" | sed 's/f//')"; \
  61. ./fbt TARGET_HW=$TARGET copro_dist updater_package \
  62. ${{ 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}; do
  69. mv dist/${TARGET}-*/* artifacts/
  70. done
  71. - name: "Check for uncommitted changes"
  72. run: |
  73. git diff --exit-code
  74. - name: 'Bundle resources'
  75. if: ${{ !github.event.pull_request.head.repo.fork }}
  76. run: |
  77. tar czpf "artifacts/flipper-z-any-resources-${SUFFIX}.tgz" -C assets resources
  78. - name: 'Bundle core2 firmware'
  79. if: ${{ !github.event.pull_request.head.repo.fork }}
  80. run: |
  81. cp build/core2_firmware.tgz "artifacts/flipper-z-any-core2_firmware-${SUFFIX}.tgz"
  82. - name: 'Copy map analyser files'
  83. if: ${{ !github.event.pull_request.head.repo.fork }}
  84. run: |
  85. cp build/f7-firmware-*/firmware.elf.map map_analyser_files/firmware.elf.map
  86. cp build/f7-firmware-*/firmware.elf map_analyser_files/firmware.elf
  87. cp ${{ github.event_path }} map_analyser_files/event.json
  88. - name: 'Upload map analyser files to storage'
  89. if: ${{ !github.event.pull_request.head.repo.fork }}
  90. uses: prewk/s3-cp-action@v2
  91. with:
  92. aws_s3_endpoint: "${{ secrets.MAP_REPORT_AWS_ENDPOINT }}"
  93. aws_access_key_id: "${{ secrets.MAP_REPORT_AWS_ACCESS_KEY }}"
  94. aws_secret_access_key: "${{ secrets.MAP_REPORT_AWS_SECRET_KEY }}"
  95. source: "./map_analyser_files/"
  96. dest: "s3://${{ secrets.MAP_REPORT_AWS_BUCKET }}/${{steps.names.outputs.random_hash}}"
  97. flags: "--recursive --acl public-read"
  98. - name: 'Trigger map file reporter'
  99. if: ${{ !github.event.pull_request.head.repo.fork }}
  100. uses: peter-evans/repository-dispatch@v2
  101. with:
  102. repository: flipperdevices/flipper-map-reporter
  103. token: ${{ secrets.REPOSITORY_DISPATCH_TOKEN }}
  104. event-type: map-file-analyse
  105. client-payload: '{"random_hash": "${{steps.names.outputs.random_hash}}", "event_type": "${{steps.names.outputs.event_type}}"}'
  106. - name: 'Upload artifacts to update server'
  107. if: ${{ !github.event.pull_request.head.repo.fork }}
  108. run: |
  109. mkdir -p ~/.ssh
  110. ssh-keyscan -p ${{ secrets.RSYNC_DEPLOY_PORT }} -H ${{ secrets.RSYNC_DEPLOY_HOST }} > ~/.ssh/known_hosts
  111. echo "${{ secrets.RSYNC_DEPLOY_KEY }}" > deploy_key;
  112. chmod 600 ./deploy_key;
  113. rsync -avzP --delete --mkpath \
  114. -e 'ssh -p ${{ secrets.RSYNC_DEPLOY_PORT }} -i ./deploy_key' \
  115. artifacts/ ${{ secrets.RSYNC_DEPLOY_USER }}@${{ secrets.RSYNC_DEPLOY_HOST }}:"${{ secrets.RSYNC_DEPLOY_BASE_PATH }}${BRANCH_NAME}/";
  116. rm ./deploy_key;
  117. - name: 'Trigger update server reindex'
  118. if: ${{ !github.event.pull_request.head.repo.fork }}
  119. run: curl -X POST -F 'key=${{ secrets.REINDEX_KEY }}' ${{ secrets.REINDEX_URL }}
  120. - name: 'Find Previous Comment'
  121. if: ${{ !github.event.pull_request.head.repo.fork && github.event.pull_request }}
  122. uses: peter-evans/find-comment@v2
  123. id: fc
  124. with:
  125. issue-number: ${{ github.event.pull_request.number }}
  126. comment-author: 'github-actions[bot]'
  127. body-includes: 'Compiled firmware for commit'
  128. - name: 'Create or update comment'
  129. if: ${{ !github.event.pull_request.head.repo.fork && github.event.pull_request}}
  130. uses: peter-evans/create-or-update-comment@v3
  131. with:
  132. comment-id: ${{ steps.fc.outputs.comment-id }}
  133. issue-number: ${{ github.event.pull_request.number }}
  134. body: |
  135. **Compiled firmware for commit `${{steps.names.outputs.commit_sha}}`:**
  136. - [📦 Update package](https://update.flipperzero.one/builds/firmware/${{steps.names.outputs.branch_name}}/flipper-z-${{steps.names.outputs.default_target}}-update-${{steps.names.outputs.suffix}}.tgz)
  137. - [📥 DFU file](https://update.flipperzero.one/builds/firmware/${{steps.names.outputs.branch_name}}/flipper-z-${{steps.names.outputs.default_target}}-full-${{steps.names.outputs.suffix}}.dfu)
  138. - [☁️ Web/App updater](https://lab.flipper.net/?url=https://update.flipperzero.one/builds/firmware/${{steps.names.outputs.branch_name}}/flipper-z-${{steps.names.outputs.default_target}}-update-${{steps.names.outputs.suffix}}.tgz&channel=${{steps.names.outputs.branch_name}}&version=${{steps.names.outputs.commit_sha}})
  139. edit-mode: replace
  140. compact:
  141. if: ${{ !startsWith(github.ref, 'refs/tags') }}
  142. runs-on: [self-hosted,FlipperZeroShell]
  143. strategy:
  144. matrix:
  145. target: [f7, f18]
  146. steps:
  147. - name: 'Wipe workspace'
  148. run: find ./ -mount -maxdepth 1 -exec rm -rf {} \;
  149. - name: 'Checkout code'
  150. uses: actions/checkout@v3
  151. with:
  152. fetch-depth: 1
  153. submodules: false
  154. ref: ${{ github.event.pull_request.head.sha }}
  155. - name: 'Get commit details'
  156. run: |
  157. if [[ ${{ github.event_name }} == 'pull_request' ]]; then
  158. TYPE="pull"
  159. elif [[ "${{ github.ref }}" == "refs/tags/"* ]]; then
  160. TYPE="tag"
  161. else
  162. TYPE="other"
  163. fi
  164. python3 scripts/get_env.py "--event_file=${{ github.event_path }}" "--type=$TYPE" || cat "${{ github.event_path }}"
  165. - name: 'Build the firmware'
  166. id: build-fw
  167. run: |
  168. set -e
  169. TARGET="$(echo '${{ matrix.target }}' | sed 's/f//')"; \
  170. ./fbt TARGET_HW=$TARGET DEBUG=0 COMPACT=1 fap_dist updater_package
  171. echo "sdk-file=$(ls dist/${{ matrix.target }}-*/flipper-z-${{ matrix.target }}-sdk-*.zip)" >> $GITHUB_OUTPUT
  172. echo "hw-target-code=$TARGET" >> $GITHUB_OUTPUT
  173. - name: Deploy uFBT with SDK
  174. uses: flipperdevices/flipperzero-ufbt-action@v0.1.0
  175. with:
  176. task: setup
  177. sdk-file: ${{ steps.build-fw.outputs.sdk-file }}
  178. sdk-hw-target: ${{ steps.build-fw.outputs.hw-target-code }}
  179. - name: Build test app with SDK
  180. run: |
  181. mkdir testapp
  182. cd testapp
  183. ufbt create APPID=testapp
  184. ufbt
  185. - name: Build example & external apps with uFBT
  186. run: |
  187. for appdir in 'applications/external' 'applications/examples'; do
  188. for app in $(find "$appdir" -maxdepth 1 -mindepth 1 -type d); do
  189. pushd $app
  190. TARGETS_FAM=$(grep "targets" application.fam || echo "${{ matrix.target }}")
  191. if ! grep -q "${{ matrix.target }}" <<< $TARGETS_FAM ; then
  192. echo Skipping unsupported app: $app
  193. popd
  194. continue
  195. fi
  196. echo Building $app
  197. ufbt
  198. popd
  199. done
  200. done