build.yml 7.4 KB

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