build.yml 7.8 KB

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