build.yml 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. name: 'Build'
  2. on:
  3. push:
  4. branches:
  5. - dev
  6. - "release*"
  7. tags:
  8. - '*'
  9. pull_request:
  10. env:
  11. TARGETS: f6 f7
  12. DEFAULT_TARGET: f7
  13. jobs:
  14. build:
  15. runs-on: [self-hosted]
  16. steps:
  17. - name: 'Cleanup workspace'
  18. uses: AutoModality/action-clean@v1
  19. - name: 'Decontaminate previous build leftovers'
  20. run: |
  21. if [ -d .git ]
  22. then
  23. git submodule status \
  24. || git checkout `git rev-list --max-parents=0 HEAD | tail -n 1`
  25. fi
  26. - name: 'Checkout code'
  27. uses: actions/checkout@v2
  28. with:
  29. fetch-depth: 0
  30. submodules: true
  31. ref: ${{ github.event.pull_request.head.sha }}
  32. - name: 'Docker cache'
  33. uses: satackey/action-docker-layer-caching@v0.0.11
  34. continue-on-error: true
  35. with:
  36. key: docker-cache-${{ hashFiles('docker/**') }}-{hash}
  37. restore-keys: docker-cache-${{ hashFiles('docker/**') }}-
  38. - name: 'Build docker image'
  39. uses: ./.github/actions/docker
  40. - name: 'Make artifacts directory'
  41. run: |
  42. test -d artifacts && rm -rf artifacts || true
  43. mkdir artifacts
  44. - name: 'Generate suffix and folder name'
  45. id: names
  46. run: |
  47. REF=${{ github.ref }}
  48. if [[ ${{ github.event_name }} == 'pull_request' ]]; then
  49. REF=${{ github.head_ref }}
  50. fi
  51. BRANCH_OR_TAG=${REF#refs/*/}
  52. SHA=$(git rev-parse --short HEAD)
  53. if [[ "${{ github.ref }}" == "refs/tags/"* ]]; then
  54. SUFFIX=${BRANCH_OR_TAG//\//_}
  55. else
  56. SUFFIX=${BRANCH_OR_TAG//\//_}-$(date +'%d%m%Y')-${SHA}
  57. fi
  58. echo "WORKFLOW_BRANCH_OR_TAG=${BRANCH_OR_TAG}" >> $GITHUB_ENV
  59. echo "DIST_SUFFIX=${SUFFIX}" >> $GITHUB_ENV
  60. echo "::set-output name=artifacts-path::${BRANCH_OR_TAG}"
  61. echo "::set-output name=suffix::${SUFFIX}"
  62. echo "::set-output name=short-hash::${SHA}"
  63. echo "::set-output name=default-target::${DEFAULT_TARGET}"
  64. - name: 'Bundle scripts'
  65. if: ${{ !github.event.pull_request.head.repo.fork }}
  66. run: |
  67. tar czpf artifacts/flipper-z-any-scripts-${{steps.names.outputs.suffix}}.tgz scripts
  68. - name: 'Build the firmware in docker'
  69. uses: ./.github/actions/docker
  70. with:
  71. run: |
  72. set -e
  73. for TARGET in ${TARGETS}
  74. do
  75. make TARGET=${TARGET}
  76. done
  77. - name: 'Move upload files'
  78. if: ${{ !github.event.pull_request.head.repo.fork }}
  79. uses: ./.github/actions/docker
  80. with:
  81. run: |
  82. set -e
  83. for TARGET in ${TARGETS}
  84. do
  85. mv dist/${TARGET}/* artifacts/
  86. done
  87. - name: 'Bundle resources'
  88. if: ${{ !github.event.pull_request.head.repo.fork }}
  89. run: |
  90. ./scripts/assets.py manifest assets/resources
  91. tar czpf artifacts/flipper-z-any-resources-${{steps.names.outputs.suffix}}.tgz -C assets resources
  92. - name: 'Bundle core2 firmware'
  93. if: ${{ !github.event.pull_request.head.repo.fork }}
  94. run: |
  95. test -d core2_firmware && rm -rf core2_firmware || true
  96. mkdir core2_firmware
  97. ./scripts/assets.py copro lib/STM32CubeWB core2_firmware STM32WB5x
  98. tar czpf artifacts/flipper-z-any-core2_firmware-${{steps.names.outputs.suffix}}.tgz core2_firmware
  99. - name: 'Upload artifacts to update server'
  100. if: ${{ !github.event.pull_request.head.repo.fork }}
  101. uses: burnett01/rsync-deployments@5.1
  102. with:
  103. switches: -avzP --delete --mkpath
  104. path: artifacts/
  105. remote_path: "${{ secrets.RSYNC_DEPLOY_BASE_PATH }}${{steps.names.outputs.artifacts-path}}/"
  106. remote_host: ${{ secrets.RSYNC_DEPLOY_HOST }}
  107. remote_port: ${{ secrets.RSYNC_DEPLOY_PORT }}
  108. remote_user: ${{ secrets.RSYNC_DEPLOY_USER }}
  109. remote_key: ${{ secrets.RSYNC_DEPLOY_KEY }}
  110. - name: 'Trigger update server reindex'
  111. if: ${{ !github.event.pull_request.head.repo.fork }}
  112. uses: wei/curl@master
  113. with:
  114. args: -X POST -F 'key=${{ secrets.REINDEX_KEY }}' ${{ secrets.REINDEX_URL }}
  115. - name: 'Find Previous Comment'
  116. if: ${{ !github.event.pull_request.head.repo.fork && github.event.pull_request }}
  117. uses: peter-evans/find-comment@v1
  118. id: fc
  119. with:
  120. issue-number: ${{ github.event.pull_request.number }}
  121. comment-author: 'github-actions[bot]'
  122. body-includes: 'to flash the'
  123. - name: 'Create or update comment'
  124. if: ${{ !github.event.pull_request.head.repo.fork && github.event.pull_request}}
  125. uses: peter-evans/create-or-update-comment@v1
  126. with:
  127. comment-id: ${{ steps.fc.outputs.comment-id }}
  128. issue-number: ${{ github.event.pull_request.number }}
  129. body: |
  130. [Click here](https://update.flipperzero.one/?url=https://update.flipperzero.one/builds/firmware/${{steps.names.outputs.artifacts-path}}/flipper-z-${{steps.names.outputs.default-target}}-full-${{steps.names.outputs.suffix}}.dfu&channel=${{steps.names.outputs.artifacts-path}}&version=${{steps.names.outputs.short-hash}}&target=${{steps.names.outputs.default-target}}) to flash the `${{steps.names.outputs.short-hash}}` version of this branch via WebUSB.
  131. edit-mode: replace