build.yml 7.1 KB

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