build.yml 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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 ]
  20. then
  21. git submodule status \
  22. || git checkout `git rev-list --max-parents=0 HEAD | tail -n 1`
  23. fi
  24. - name: 'Checkout code'
  25. uses: actions/checkout@v2
  26. with:
  27. fetch-depth: 0
  28. ref: ${{ github.event.pull_request.head.sha }}
  29. - name: 'Make artifacts directory'
  30. run: |
  31. test -d artifacts && rm -rf artifacts || true
  32. mkdir artifacts
  33. - name: 'Generate suffix and folder name'
  34. id: names
  35. run: |
  36. REF=${{ github.ref }}
  37. if [[ ${{ github.event_name }} == 'pull_request' ]]; then
  38. REF=${{ github.head_ref }}
  39. fi
  40. BRANCH_OR_TAG=${REF#refs/*/}
  41. SHA=$(git rev-parse --short HEAD)
  42. if [[ "${{ github.ref }}" == "refs/tags/"* ]]; then
  43. SUFFIX=${BRANCH_OR_TAG//\//_}
  44. else
  45. SUFFIX=${BRANCH_OR_TAG//\//_}-$(date +'%d%m%Y')-${SHA}
  46. fi
  47. echo "WORKFLOW_BRANCH_OR_TAG=${BRANCH_OR_TAG}" >> $GITHUB_ENV
  48. echo "DIST_SUFFIX=${SUFFIX}" >> $GITHUB_ENV
  49. echo "::set-output name=artifacts-path::${BRANCH_OR_TAG}"
  50. echo "::set-output name=suffix::${SUFFIX}"
  51. echo "::set-output name=short-hash::${SHA}"
  52. echo "::set-output name=default-target::${DEFAULT_TARGET}"
  53. - name: 'Bundle scripts'
  54. if: ${{ !github.event.pull_request.head.repo.fork }}
  55. run: |
  56. tar czpf artifacts/flipper-z-any-scripts-${{steps.names.outputs.suffix}}.tgz scripts
  57. - name: 'Build the firmware'
  58. run: |
  59. set -e
  60. for TARGET in ${TARGETS}
  61. do
  62. FBT_TOOLCHAIN_PATH=/opt ./fbt TARGET_HW=`echo ${TARGET} | sed 's/f//'` updater_package ${{ startsWith(github.ref, 'refs/tags') && 'DEBUG=0 COMPACT=1' || '' }}
  63. done
  64. - name: 'Move upload files'
  65. if: ${{ !github.event.pull_request.head.repo.fork }}
  66. run: |
  67. set -e
  68. for TARGET in ${TARGETS}
  69. do
  70. mv dist/${TARGET}-*/* artifacts/
  71. done
  72. - name: 'Bundle self-update package'
  73. if: ${{ !github.event.pull_request.head.repo.fork }}
  74. run: |
  75. set -e
  76. for UPDATEBUNDLE in artifacts/*/
  77. do
  78. BUNDLE_NAME=`echo $UPDATEBUNDLE | cut -d'/' -f2`
  79. echo Packaging ${BUNDLE_NAME}
  80. tar czpf artifacts/flipper-z-${BUNDLE_NAME}.tgz -C artifacts ${BUNDLE_NAME}
  81. rm -rf artifacts/${BUNDLE_NAME}
  82. done
  83. - name: "Check for uncommited changes"
  84. run: |
  85. git diff --exit-code
  86. - name: 'Bundle resources'
  87. if: ${{ !github.event.pull_request.head.repo.fork }}
  88. run: |
  89. tar czpf artifacts/flipper-z-any-resources-${{steps.names.outputs.suffix}}.tgz -C assets resources
  90. - name: 'Bundle core2 firmware'
  91. if: ${{ !github.event.pull_request.head.repo.fork }}
  92. run: |
  93. FBT_TOOLCHAIN_PATH=/opt ./fbt copro_dist
  94. tar czpf artifacts/flipper-z-any-core2_firmware-${{steps.names.outputs.suffix}}.tgz -C assets core2_firmware
  95. - name: 'Upload artifacts to update server'
  96. if: ${{ !github.event.pull_request.head.repo.fork }}
  97. run: |
  98. echo "${{ secrets.RSYNC_DEPLOY_KEY }}" > deploy_key;
  99. chmod 600 ./deploy_key;
  100. rsync -avzP --delete --mkpath \
  101. -e 'ssh -p ${{ secrets.RSYNC_DEPLOY_PORT }} -i ./deploy_key' \
  102. artifacts/ ${{ secrets.RSYNC_DEPLOY_USER }}@${{ secrets.RSYNC_DEPLOY_HOST }}:"${{ secrets.RSYNC_DEPLOY_BASE_PATH }}${{steps.names.outputs.artifacts-path}}/";
  103. rm ./deploy_key;
  104. - name: 'Trigger update server reindex'
  105. if: ${{ !github.event.pull_request.head.repo.fork }}
  106. run: curl -X POST -F 'key=${{ secrets.REINDEX_KEY }}' ${{ secrets.REINDEX_URL }}
  107. - name: 'Find Previous Comment'
  108. if: ${{ !github.event.pull_request.head.repo.fork && github.event.pull_request }}
  109. uses: peter-evans/find-comment@v1
  110. id: fc
  111. with:
  112. issue-number: ${{ github.event.pull_request.number }}
  113. comment-author: 'github-actions[bot]'
  114. body-includes: 'Compiled firmware for commit'
  115. - name: 'Create or update comment'
  116. if: ${{ !github.event.pull_request.head.repo.fork && github.event.pull_request}}
  117. uses: peter-evans/create-or-update-comment@v1
  118. with:
  119. comment-id: ${{ steps.fc.outputs.comment-id }}
  120. issue-number: ${{ github.event.pull_request.number }}
  121. body: |
  122. **Compiled firmware for commit `${{steps.names.outputs.short-hash}}`:**
  123. - [📦 Update package](https://update.flipperzero.one/builds/firmware/${{steps.names.outputs.artifacts-path}}/flipper-z-${{steps.names.outputs.default-target}}-update-${{steps.names.outputs.suffix}}.tgz)
  124. - [📥 DFU file](https://update.flipperzero.one/builds/firmware/${{steps.names.outputs.artifacts-path}}/flipper-z-${{steps.names.outputs.default-target}}-full-${{steps.names.outputs.suffix}}.dfu)
  125. - [☁️ Web updater](https://my.flipp.dev/?url=https://update.flipperzero.one/builds/firmware/${{steps.names.outputs.artifacts-path}}/flipper-z-${{steps.names.outputs.default-target}}-update-${{steps.names.outputs.suffix}}.tgz&channel=${{steps.names.outputs.artifacts-path}}&version=${{steps.names.outputs.short-hash}})
  126. edit-mode: replace
  127. compact:
  128. if: ${{ !startsWith(github.ref, 'refs/tags') }}
  129. runs-on: [self-hosted,FlipperZeroShell]
  130. steps:
  131. - name: 'Decontaminate previous build leftovers'
  132. run: |
  133. if [ -d .git ]
  134. then
  135. git submodule status \
  136. || git checkout `git rev-list --max-parents=0 HEAD | tail -n 1`
  137. fi
  138. - name: 'Checkout code'
  139. uses: actions/checkout@v2
  140. with:
  141. fetch-depth: 0
  142. submodules: true
  143. ref: ${{ github.event.pull_request.head.sha }}
  144. - name: 'Generate suffix and folder name'
  145. id: names
  146. run: |
  147. REF=${{ github.ref }}
  148. if [[ ${{ github.event_name }} == 'pull_request' ]]; then
  149. REF=${{ github.head_ref }}
  150. fi
  151. BRANCH_OR_TAG=${REF#refs/*/}
  152. SHA=$(git rev-parse --short HEAD)
  153. if [[ "${{ github.ref }}" == "refs/tags/"* ]]; then
  154. SUFFIX=${BRANCH_OR_TAG//\//_}
  155. else
  156. SUFFIX=${BRANCH_OR_TAG//\//_}-$(date +'%d%m%Y')-${SHA}
  157. fi
  158. echo "WORKFLOW_BRANCH_OR_TAG=${BRANCH_OR_TAG}" >> $GITHUB_ENV
  159. echo "DIST_SUFFIX=${SUFFIX}" >> $GITHUB_ENV
  160. - name: 'Build the firmware'
  161. run: |
  162. set -e
  163. for TARGET in ${TARGETS}
  164. do
  165. FBT_TOOLCHAIN_PATH=/opt ./fbt TARGET_HW=`echo ${TARGET} | sed 's/f//'` updater_package DEBUG=0 COMPACT=1
  166. done