build.yml 7.2 KB

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