build.yml 6.7 KB

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