build.yml 6.6 KB

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