build.yml 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. name: "Build"
  2. on:
  3. push:
  4. branches:
  5. - "**"
  6. - "!release"
  7. tags:
  8. - "*"
  9. pull_request:
  10. concurrency:
  11. group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  12. cancel-in-progress: true
  13. env:
  14. DEFAULT_TARGET: f7
  15. FBT_GIT_SUBMODULE_SHALLOW: 1
  16. jobs:
  17. build:
  18. permissions:
  19. issues: write
  20. pull-requests: write
  21. runs-on: ubuntu-latest
  22. strategy:
  23. fail-fast: false
  24. matrix:
  25. target: [f7]
  26. steps:
  27. - name: "Checkout code"
  28. uses: actions/checkout@v4
  29. with:
  30. fetch-depth: 1
  31. ref: ${{ github.event.pull_request.head.sha }}
  32. - name: "Get commit details"
  33. id: names
  34. run: |
  35. BUILD_TYPE='DEBUG=0 COMPACT=1'
  36. if [[ ${{ github.event_name }} == 'pull_request' ]]; then
  37. TYPE="pull"
  38. elif [[ "${{ github.ref }}" == "refs/tags/"* ]]; then
  39. TYPE="tag"
  40. else
  41. TYPE="other"
  42. fi
  43. python3 scripts/get_env.py "--event_file=${{ github.event_path }}" "--type=$TYPE" || cat "${{ github.event_path }}"
  44. echo "event_type=$TYPE" >> $GITHUB_OUTPUT
  45. echo "FBT_BUILD_TYPE=$BUILD_TYPE" >> $GITHUB_ENV
  46. echo "TARGET=${{ matrix.target }}" >> $GITHUB_ENV
  47. echo "TARGET_HW=$(echo "${{ matrix.target }}" | sed 's/f//')" >> $GITHUB_ENV
  48. - name: "Check API versions for consistency between targets"
  49. run: |
  50. set -e
  51. N_API_HEADER_SIGNATURES=`ls -1 targets/f*/api_symbols.csv | xargs -I {} sh -c "head -n2 {} | md5sum" | sort -u | wc -l`
  52. if [ $N_API_HEADER_SIGNATURES != 1 ] ; then
  53. echo API versions aren\'t matching for available targets. Please update!
  54. echo API versions are:
  55. head -n2 targets/f*/api_symbols.csv
  56. exit 1
  57. fi
  58. - name: "Check API version for consistency with OFW release-candidate"
  59. run: |
  60. set -e
  61. symbols="targets/$TARGET/api_symbols.csv"
  62. ofw_api="$(curl -s "https://raw.githubusercontent.com/flipperdevices/flipperzero-firmware/release-candidate/${symbols}" | head -n2)"
  63. our_api="$(head -n2 "${symbols}")"
  64. if [ "$our_api" != "$ofw_api" ] ; then
  65. echo API versions aren\'t matching OFW. Please update!
  66. echo API versions are:
  67. echo "Official: $(tail -n1 <<< "$ofw_api")"
  68. echo "Momentum: $(tail -n1 <<< "$our_api")"
  69. exit 1
  70. fi
  71. - name: "Build the firmware and apps"
  72. id: build-fw
  73. run: |
  74. ./fbt TARGET_HW=$TARGET_HW $FBT_BUILD_TYPE updater_package
  75. echo "firmware_api=$(./fbt TARGET_HW=$TARGET_HW get_apiversion)" >> $GITHUB_OUTPUT
  76. - name: "Check for uncommitted changes"
  77. run: |
  78. git diff --exit-code
  79. - name: "Upload artifacts to GitHub"
  80. uses: actions/upload-artifact@v3
  81. with:
  82. path: |
  83. dist/${{ env.TARGET }}-*/flipper-z-${{ env.TARGET }}-update-*
  84. dist/${{ env.TARGET }}-*/flipper-z-${{ env.TARGET }}-sdk-*
  85. - name: "Copy build output"
  86. env:
  87. INDEXER_URL: ${{ secrets.INDEXER_URL }}
  88. if: ${{ env.INDEXER_URL != '' && (github.event.pull_request || (github.event_name == 'push' && ((github.ref_name == 'dev' && !contains(github.event.head_commit.message, '--nobuild')) || startsWith(github.ref, 'refs/tags/')))) }}
  89. run: |
  90. set -e
  91. rm -rf artifacts || true
  92. mkdir artifacts
  93. cp dist/${TARGET}-*/flipper-z-${TARGET}-{update,sdk}-* artifacts/
  94. cd dist/${TARGET}-*/${TARGET}-update-*/
  95. ARTIFACT_TAG=flipper-z-"$(basename "$(realpath .)")"
  96. 7z a ../../../artifacts/${ARTIFACT_TAG}.zip .
  97. echo "ARTIFACT_TAG=$ARTIFACT_TAG" >> $GITHUB_ENV
  98. VERSION_TAG="$(basename "$(realpath .)" | cut -d- -f3-)"
  99. echo "VERSION_TAG=$VERSION_TAG" >> $GITHUB_ENV
  100. - name: "Upload artifacts to update server"
  101. env:
  102. INDEXER_URL: ${{ secrets.INDEXER_URL }}
  103. if: ${{ env.INDEXER_URL != '' && (github.event.pull_request || (github.event_name == 'push' && ((github.ref_name == 'dev' && !contains(github.event.head_commit.message, '--nobuild')) || startsWith(github.ref, 'refs/tags/')))) }}
  104. run: |
  105. curl "${{ secrets.INDEXER_URL }}"/firmware/directory.json > previndex.json
  106. FILES=$(for ARTIFACT in $(find artifacts -maxdepth 1 -not -type d); do echo "-F files=@${ARTIFACT}"; done)
  107. curl --fail -L -H "Token: ${{ secrets.INDEXER_TOKEN }}" \
  108. -F "branch=${BRANCH_NAME}" \
  109. -F "version_token=${COMMIT_SHA}" \
  110. ${FILES[@]} \
  111. "${{ secrets.INDEXER_URL }}"/firmware/uploadfiles
  112. - name: "Find previous comment"
  113. env:
  114. INDEXER_URL: ${{ secrets.INDEXER_URL }}
  115. if: ${{ env.INDEXER_URL != '' && github.event.pull_request && matrix.target == env.DEFAULT_TARGET }}
  116. uses: peter-evans/find-comment@v3
  117. id: find-comment
  118. with:
  119. issue-number: ${{ github.event.pull_request.number }}
  120. comment-author: "github-actions[bot]"
  121. body-includes: "Compiled ${{ matrix.target }} firmware for commit"
  122. - name: "Create or update comment"
  123. env:
  124. INDEXER_URL: ${{ secrets.INDEXER_URL }}
  125. if: ${{ env.INDEXER_URL != '' && github.event.pull_request && matrix.target == env.DEFAULT_TARGET }}
  126. uses: peter-evans/create-or-update-comment@v4
  127. with:
  128. comment-id: ${{ steps.find-comment.outputs.comment-id }}
  129. issue-number: ${{ github.event.pull_request.number }}
  130. body: |
  131. **Compiled ${{ matrix.target }} firmware for commit `${{steps.names.outputs.commit_sha}}`:**
  132. - [☁️ Flipper Lab/App](https://lab.flipper.net/?url=${{secrets.INDEXER_URL}}/firmware/${{steps.names.outputs.branch_name}}/flipper-z-${{steps.names.outputs.default_target}}-update-${{steps.names.outputs.suffix}}.tgz&channel=mntm-${{steps.names.outputs.branch_name}}&version=${{steps.names.outputs.commit_sha}})
  133. - [📦 qFlipper Package](${{secrets.INDEXER_URL}}/firmware/${{steps.names.outputs.branch_name}}/flipper-z-${{steps.names.outputs.default_target}}-update-${{steps.names.outputs.suffix}}.tgz)
  134. edit-mode: replace
  135. - name: Send devbuild webhook
  136. env:
  137. INDEXER_URL: ${{ secrets.INDEXER_URL }}
  138. BUILD_WEBHOOK: ${{ secrets.BUILD_WEBHOOK }}
  139. if: ${{ env.INDEXER_URL != '' && github.event_name == 'push' && github.ref_name == 'dev' && !contains(github.event.head_commit.message, '--nobuild') }}
  140. run: |
  141. python .github/workflow_data/devbuild.py