build.yml 7.6 KB

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