build-with-firmwware.yml 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. name: "Build for Firmware"
  2. run-name: "Build ${{ inputs.DEPLOY_TARGET }} by @${{ github.ACTOR }}"
  3. on:
  4. workflow_dispatch:
  5. inputs:
  6. version:
  7. description: "Enter version to build or left empty for current version"
  8. required: false
  9. type: string
  10. release:
  11. types: [created, prereleased]
  12. push:
  13. paths:
  14. - .github/workflows/build-with-firmware.yml
  15. permissions:
  16. contents: write
  17. packages: write
  18. concurrency:
  19. group: firmware-build-${{ vars.FIRMWARE_VERSION }}-${{ vars.RELEASE_VERSION }}
  20. cancel-in-progress: false
  21. jobs:
  22. build-and-upload:
  23. runs-on: ubuntu-latest
  24. env:
  25. REPO_SELF: ${{ vars.REPO_SELF }}
  26. OFW_PATH: "applications_user/subbrute"
  27. RELATIVE_PATH: "applications/external/subbrute"
  28. CURRENT_VERSION: ${{ vars.RELEASE_VERSION }}
  29. RELEASE_VERSION: ${{ vars.RELEASE_VERSION }}
  30. APP_NAME: ""
  31. ZIP_NAME: ""
  32. ZIP_TAG: ""
  33. TGZ_NAME: ""
  34. TGZ_TAG: ""
  35. strategy:
  36. fail-fast: false
  37. matrix:
  38. firmware: [unlshd, official]
  39. include:
  40. - firmware: unlshd
  41. url: ${{ vars.REPO_UNLEASHED }}
  42. version: ${{ vars.FIRMWARE_VERSION }}
  43. src-included: 0
  44. - firmware: official
  45. url: ${{ vars.REPO_OFFICIAL }}
  46. version: "official"
  47. src-included: 0
  48. steps:
  49. - name: Set version
  50. env:
  51. INPUT_VERSION: ${{ inputs.version }}
  52. CURRENT_VERSION: ${{ env.CURRENT_VERSION }}
  53. shell: pwsh
  54. run: |
  55. $releaseVersion = ([string]::IsNullOrWhitespace($env:INPUT_VERSION) ? $env:CURRENT_VERSION : $env:INPUT_VERSION)
  56. if ( $releaseVersion.StartsWith('v') ) {
  57. $releaseVersion = $releaseVersion.Substring(1)
  58. }
  59. Write-Output ('RELEASE_VERSION={0}' -f $releaseVersion) >> $env:GITHUB_ENV
  60. - name: Copy Firmware Files
  61. uses: actions/checkout@v3
  62. with:
  63. repository: ${{ matrix.url }}
  64. clean: "true"
  65. submodules: "true"
  66. ref: "dev"
  67. - name: Copy Repo Files
  68. if: ${{ matrix.src-included == 0 }}
  69. uses: actions/checkout@v3
  70. with:
  71. repository: ${{ vars.REPO_SELF }}
  72. clean: "true"
  73. submodules: "true"
  74. path: "${{ env.OFW_PATH }}"
  75. # - name: Restore FBT
  76. # id: cache-restore
  77. # if: ${{ success() }}
  78. # uses: actions/cache/restore@v3
  79. # with:
  80. # path: |
  81. # build/**
  82. # debug/**
  83. # # An explicit key for restoring and saving the cache
  84. # key: 'fbt=${{ env.FIRMWARE_VERSION }}'
  85. #
  86. - name: Remove other apps
  87. shell: pwsh
  88. if: ${{ success() }}
  89. # rm to remove problem FAP which includes non-existent files
  90. run: |
  91. Remove-Item -Force -Recurse ./applications/debug -ErrorAction SilentlyContinue
  92. Remove-Item -Force -Recurse ./applications/examples -ErrorAction SilentlyContinue
  93. - name: Build Firmware
  94. shell: bash
  95. if: ${{ success() }}
  96. env:
  97. FBT_NO_SYNC: 0
  98. DIST_SUFFIX: ${{ matrix.version }}
  99. WORKFLOW_BRANCH_OR_TAG: release-cfw
  100. run: |
  101. ./fbt COMPACT=1 DEBUG=0 FBT_NO_SYNC=0
  102. - name: Build FAPs
  103. shell: bash
  104. if: ${{ success() }}
  105. env:
  106. FBT_NO_SYNC: 0
  107. DIST_SUFFIX: ${{ matrix.version }}
  108. WORKFLOW_BRANCH_OR_TAG: release-cfw
  109. # rm to remove problem FAP which includes non-existent files
  110. run: |
  111. ./fbt COMPACT=1 DEBUG=0 FBT_NO_SYNC=0 fap_dist
  112. # - name: Save FBT
  113. # id: cache-save
  114. # if: ${{ success() }}
  115. # uses: actions/cache/save@v3
  116. # with:
  117. # path: |
  118. # build/**
  119. # debug/**
  120. # # An explicit key for restoring and saving the cache
  121. # key: ${{ steps.cache-restore.outputs.cache-primary-key }}
  122. - name: Create assets
  123. if: ${{ success() }}
  124. shell: pwsh
  125. env:
  126. APP_NAME: "subghz_bruteforcer_${{ env.RELEASE_VERSION }}_${{ matrix.firmware }}"
  127. run: |
  128. function Format-Bytes {
  129. param(
  130. [int]$number
  131. )
  132. $sizes = 'KB', 'MB', 'GB', 'TB', 'PB'
  133. for ($x = 0; $x -lt $sizes.count; $x++) {
  134. if ($number -lt [int64]"1$($sizes[$x])") {
  135. if ($x -eq 0) {
  136. return "$number B"
  137. }
  138. else {
  139. $formattedNumber = $number / [int64]"1$($sizes[$x-1])"
  140. $formattedNumber = "{0:N2}" -f $formattedNumber
  141. return "$formattedNumber $($sizes[$x-1])"
  142. }
  143. }
  144. }
  145. }
  146. $zipName = ('{0}.zip' -f $env:APP_NAME)
  147. $tgzName = ('{0}.tgz' -f $env:APP_NAME)
  148. $fapName = 'subghz_bruteforcer.fap'
  149. $dstFap = "./$fapName"
  150. $appDir = "dist/f7-C/apps/Sub-GHz"
  151. if (!(Test-Path -Path "$appDir/$fapName" -PathType Leaf)) {
  152. Write-Error '::error title=Files not found::Cannot find files in location'
  153. exit 1
  154. }
  155. $size = (Get-Item -Path "$appDir/$fapName" | Get-ItemPropertyValue -Name Length)
  156. Write-Output ('Filesize: {0}' -f (Format-Bytes $size))
  157. Copy-Item -Force -Verbose -Path "$appDir/$fapName" -Destination $dstFap
  158. zip -r -qq $zipName $dstFap
  159. tar zcf $tgzName $dstFap
  160. if ( !(Test-Path -Path $zipName -PathType Leaf) -or !(Test-Path -Path $tgzName -PathType Leaf) ) {
  161. Write-Error '::error title=Files not found::Cannot find files in location'
  162. exit 1
  163. }
  164. $zipSize = Format-Bytes (Get-Item -Path $zipName).Length
  165. $tgzSize = Format-Bytes (Get-Item -Path $tgzName ).Length
  166. Write-Output ('ZIP_NAME={0}' -f $zipName) >> $env:GITHUB_ENV
  167. Write-Output ('TGZ_NAME={0}' -f $tgzName ) >> $env:GITHUB_ENV
  168. Write-Output ('ZIP_TAG={0} ({1})' -f $zipName, $zipSize) >> $env:GITHUB_ENV
  169. Write-Output ('TGZ_TAG={0} ({1})' -f $tgzName , $tgzSize) >> $env:GITHUB_ENV
  170. - name: Upload assets
  171. if: ${{ success() && env.ZIP_NAME != '' }}
  172. shell: pwsh
  173. env:
  174. GITHUB_TOKEN: ${{ secrets.FLIPPER_TOKEN }}
  175. run: |
  176. $url = (gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/${{ github.REPOSITORY }}/releases/tags/v${{ env.RELEASE_VERSION }} >$null 2>&1) | ConvertFrom-Json -AsHashtable -ErrorAction SilentlyContinue
  177. if ( [string]::IsNullOrWhitespace($url.name) ) {
  178. $sha = (git rev-parse --verify HEAD)
  179. gh api --method POST -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/${{ github.REPOSITORY }}/releases -f tag_name='v${{ env.RELEASE_VERSION }}' -f target_commitish="$sha" -f name='v${{ env.RELEASE_VERSION }}' -F draft=true -F prerelease=false -F generate_release_notes=true
  180. #gh release create v${{ env.RELEASE_VERSION }} --generate-notes -f target_commitish='master' --draft -R ${{ env.REPO_SELF }}
  181. }
  182. gh release upload 'v${{ env.RELEASE_VERSION }}' '${{ env.ZIP_NAME }}#${{ env.ZIP_TAG }}' '${{ env.TGZ_NAME }}#${{ env.TGZ_TAG }}' --clobber -R ${{ env.REPO_SELF }}
  183. gh release edit 'v${{ env.RELEASE_VERSION }}' --draft=false -R ${{ env.REPO_SELF }}
  184. #EOF