build.yml 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. FBT_TOOLCHAIN_PATH: /runner/_work
  14. jobs:
  15. main:
  16. runs-on: [self-hosted,FlipperZeroShell]
  17. steps:
  18. - name: 'Decontaminate previous build leftovers'
  19. run: |
  20. if [ -d .git ]; then
  21. git submodule status || (
  22. git ls-files --stage | egrep '^160000' | awk '{print $4}' | while read submodule
  23. do
  24. git rm -rf --cached "$submodule"
  25. done
  26. )
  27. fi
  28. - name: 'Checkout code'
  29. uses: actions/checkout@v3
  30. with:
  31. fetch-depth: 1
  32. ref: ${{ github.event.pull_request.head.sha }}
  33. - name: 'Get commit details'
  34. id: names
  35. run: |
  36. if [[ ${{ github.event_name }} == 'pull_request' ]]; then
  37. TYPE="pull"
  38. elif [[ "${{ github.ref }}" == "refs/tags/"* ]]; then
  39. TYPE="tag"
  40. else
  41. TYPE="other"
  42. fi
  43. python3 scripts/get_env.py "--event_file=${{ github.event_path }}" "--type=$TYPE"
  44. echo random_hash=$(openssl rand -base64 40 | shasum -a 256 | awk '{print $1}') >> $GITHUB_OUTPUT
  45. echo "event_type=$TYPE" >> $GITHUB_OUTPUT
  46. - name: 'Check API versions'
  47. run: |
  48. set -e
  49. N_API_HEADER_SIGNATURES=`ls -1 firmware/targets/f*/api_symbols.csv | xargs -I {} sh -c "head -n2 {} | md5sum" | sort -u | wc -l`
  50. if [ $N_API_HEADER_SIGNATURES != 1 ] ; then
  51. echo API versions aren\'t matching for available targets. Please update!
  52. head -n2 firmware/targets/f*/api_symbols.csv
  53. exit 1
  54. fi
  55. - name: 'Make artifacts directory'
  56. run: |
  57. rm -rf artifacts
  58. rm -rf map_analyser_files
  59. mkdir artifacts
  60. mkdir map_analyser_files
  61. - name: 'Bundle scripts'
  62. if: ${{ !github.event.pull_request.head.repo.fork }}
  63. run: |
  64. tar czpf artifacts/flipper-z-any-scripts-${SUFFIX}.tgz scripts debug
  65. - name: 'Build the firmware'
  66. run: |
  67. set -e
  68. for TARGET in ${TARGETS}; do
  69. TARGET="$(echo "${TARGET}" | sed 's/f//')"; \
  70. ./fbt TARGET_HW=$TARGET copro_dist updater_package \
  71. ${{ startsWith(github.ref, 'refs/tags') && 'DEBUG=0 COMPACT=1' || '' }}
  72. done
  73. - name: 'Move upload files'
  74. if: ${{ !github.event.pull_request.head.repo.fork }}
  75. run: |
  76. set -e
  77. for TARGET in ${TARGETS}; do
  78. mv dist/${TARGET}-*/* artifacts/
  79. done
  80. - name: "Check for uncommitted changes"
  81. run: |
  82. git diff --exit-code
  83. - name: 'Bundle resources'
  84. if: ${{ !github.event.pull_request.head.repo.fork }}
  85. run: |
  86. tar czpf "artifacts/flipper-z-any-resources-${SUFFIX}.tgz" -C assets resources
  87. - name: 'Bundle core2 firmware'
  88. if: ${{ !github.event.pull_request.head.repo.fork }}
  89. run: |
  90. cp build/core2_firmware.tgz "artifacts/flipper-z-any-core2_firmware-${SUFFIX}.tgz"
  91. - name: 'Copy map analyser files'
  92. if: ${{ !github.event.pull_request.head.repo.fork }}
  93. run: |
  94. cp build/f7-firmware-*/firmware.elf.map map_analyser_files/firmware.elf.map
  95. cp build/f7-firmware-*/firmware.elf map_analyser_files/firmware.elf
  96. cp ${{ github.event_path }} map_analyser_files/event.json
  97. - name: 'Upload map analyser files to storage'
  98. if: ${{ !github.event.pull_request.head.repo.fork }}
  99. uses: prewk/s3-cp-action@v2
  100. with:
  101. aws_s3_endpoint: "${{ secrets.MAP_REPORT_AWS_ENDPOINT }}"
  102. aws_access_key_id: "${{ secrets.MAP_REPORT_AWS_ACCESS_KEY }}"
  103. aws_secret_access_key: "${{ secrets.MAP_REPORT_AWS_SECRET_KEY }}"
  104. source: "./map_analyser_files/"
  105. dest: "s3://${{ secrets.MAP_REPORT_AWS_BUCKET }}/${{steps.names.outputs.random_hash}}"
  106. flags: "--recursive --acl public-read"
  107. - name: 'Trigger map file reporter'
  108. if: ${{ !github.event.pull_request.head.repo.fork }}
  109. uses: peter-evans/repository-dispatch@v2
  110. with:
  111. repository: flipperdevices/flipper-map-reporter
  112. token: ${{ secrets.REPOSITORY_DISPATCH_TOKEN }}
  113. event-type: map-file-analyse
  114. client-payload: '{"random_hash": "${{steps.names.outputs.random_hash}}", "event_type": "${{steps.names.outputs.event_type}}"}'
  115. - name: 'Upload artifacts to update server'
  116. if: ${{ !github.event.pull_request.head.repo.fork }}
  117. run: |
  118. mkdir -p ~/.ssh
  119. ssh-keyscan -p ${{ secrets.RSYNC_DEPLOY_PORT }} -H ${{ secrets.RSYNC_DEPLOY_HOST }} > ~/.ssh/known_hosts
  120. echo "${{ secrets.RSYNC_DEPLOY_KEY }}" > deploy_key;
  121. chmod 600 ./deploy_key;
  122. rsync -avzP --delete --mkpath \
  123. -e 'ssh -p ${{ secrets.RSYNC_DEPLOY_PORT }} -i ./deploy_key' \
  124. artifacts/ ${{ secrets.RSYNC_DEPLOY_USER }}@${{ secrets.RSYNC_DEPLOY_HOST }}:"${{ secrets.RSYNC_DEPLOY_BASE_PATH }}${BRANCH_NAME}/";
  125. rm ./deploy_key;
  126. - name: 'Trigger update server reindex'
  127. if: ${{ !github.event.pull_request.head.repo.fork }}
  128. run: curl -X POST -F 'key=${{ secrets.REINDEX_KEY }}' ${{ secrets.REINDEX_URL }}
  129. - name: 'Find Previous Comment'
  130. if: ${{ !github.event.pull_request.head.repo.fork && github.event.pull_request }}
  131. uses: peter-evans/find-comment@v1
  132. id: fc
  133. with:
  134. issue-number: ${{ github.event.pull_request.number }}
  135. comment-author: 'github-actions[bot]'
  136. body-includes: 'Compiled firmware for commit'
  137. - name: 'Create or update comment'
  138. if: ${{ !github.event.pull_request.head.repo.fork && github.event.pull_request}}
  139. uses: peter-evans/create-or-update-comment@v1
  140. with:
  141. comment-id: ${{ steps.fc.outputs.comment-id }}
  142. issue-number: ${{ github.event.pull_request.number }}
  143. body: |
  144. **Compiled firmware for commit `${{steps.names.outputs.commit_sha}}`:**
  145. - [📦 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)
  146. - [📥 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)
  147. - [☁️ 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}})
  148. edit-mode: replace
  149. compact:
  150. if: ${{ !startsWith(github.ref, 'refs/tags') }}
  151. runs-on: [self-hosted,FlipperZeroShell]
  152. steps:
  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@v3
  162. with:
  163. fetch-depth: 1
  164. submodules: false
  165. ref: ${{ github.event.pull_request.head.sha }}
  166. - name: 'Get commit details'
  167. run: |
  168. if [[ ${{ github.event_name }} == 'pull_request' ]]; then
  169. TYPE="pull"
  170. elif [[ "${{ github.ref }}" == "refs/tags/"* ]]; then
  171. TYPE="tag"
  172. else
  173. TYPE="other"
  174. fi
  175. python3 scripts/get_env.py "--event_file=${{ github.event_path }}" "--type=$TYPE"
  176. - name: 'Build the firmware'
  177. run: |
  178. set -e
  179. for TARGET in ${TARGETS}; do
  180. TARGET="$(echo "${TARGET}" | sed 's/f//')"; \
  181. ./fbt TARGET_HW=$TARGET DEBUG=0 COMPACT=1 fap_dist updater_package
  182. done