build.yml 6.0 KB

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