build-with-firmwware.yml 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. APP_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. SHA: ""
  36. FW_VERSION: ""
  37. FW_URL: ""
  38. strategy:
  39. fail-fast: false
  40. matrix:
  41. firmware: [unlshd, official]
  42. include:
  43. - firmware: unlshd
  44. url: ${{ vars.REPO_UNLEASHED }}
  45. version: ${{ vars.FIRMWARE_VERSION }}
  46. src-included: 0
  47. - firmware: official
  48. url: ${{ vars.REPO_OFFICIAL }}
  49. version: "official"
  50. src-included: 0
  51. steps:
  52. - name: Set version
  53. env:
  54. INPUT_VERSION: ${{ inputs.version }}
  55. CURRENT_VERSION: ${{ env.CURRENT_VERSION }}
  56. shell: pwsh
  57. run: |
  58. $releaseVersion = ([string]::IsNullOrWhitespace($env:INPUT_VERSION) ? $env:CURRENT_VERSION : $env:INPUT_VERSION)
  59. if ( $releaseVersion.StartsWith('v') ) {
  60. $releaseVersion = $releaseVersion.Substring(1)
  61. }
  62. Write-Output ('RELEASE_VERSION={0}' -f $releaseVersion) >> $env:GITHUB_ENV
  63. - name: Copy Firmware Files
  64. uses: actions/checkout@v3
  65. with:
  66. repository: ${{ matrix.url }}
  67. clean: "true"
  68. submodules: "true"
  69. ref: "dev"
  70. - name: Copy Repo Files
  71. if: ${{ matrix.src-included == 0 }}
  72. uses: actions/checkout@v3
  73. with:
  74. repository: ${{ vars.REPO_SELF }}
  75. clean: "true"
  76. submodules: "true"
  77. path: "${{ env.APP_PATH }}"
  78. # - name: Restore FBT
  79. # id: cache-restore
  80. # if: ${{ success() }}
  81. # uses: actions/cache/restore@v3
  82. # with:
  83. # path: |
  84. # build/**
  85. # debug/**
  86. # # An explicit key for restoring and saving the cache
  87. # key: 'fbt=${{ env.FIRMWARE_VERSION }}'
  88. #
  89. - name: Remove other apps
  90. shell: pwsh
  91. if: ${{ success() }}
  92. # rm to remove problem FAP which includes non-existent files
  93. run: |
  94. Remove-Item -Force -Recurse ./applications/debug -ErrorAction SilentlyContinue
  95. Remove-Item -Force -Recurse ./applications/examples -ErrorAction SilentlyContinue
  96. Remove-Item -Force -Recurse ${{ env.RELATIVE_PATH }} -ErrorAction SilentlyContinue
  97. - name: Get SHA of our application
  98. shell: pwsh
  99. env:
  100. GITHUB_TOKEN: ${{ secrets.FLIPPER_TOKEN }}
  101. run: |
  102. $fwInfo = ((gh release view --json tagName,url -R ${{ matrix.url }}) | ConvertFrom-Json)
  103. cd '${{ env.APP_PATH }}'
  104. $sha = (git rev-parse --verify HEAD)
  105. Write-Output ('SHA={0}' -f $sha) >> $env:GITHUB_ENV
  106. Write-Output ('FW_VERSION={0}' -f $fwInfo.tagName) >> $env:GITHUB_ENV
  107. Write-Output ('FW_URL={0}' -f $fwInfo.url) >> $env:GITHUB_ENV
  108. - name: Build Firmware
  109. shell: bash
  110. if: ${{ success() }}
  111. env:
  112. FBT_NO_SYNC: 0
  113. DIST_SUFFIX: ${{ matrix.version }}
  114. WORKFLOW_BRANCH_OR_TAG: release-cfw
  115. run: |
  116. ./fbt COMPACT=1 DEBUG=0 FBT_NO_SYNC=0
  117. - name: Build FAPs
  118. shell: bash
  119. if: ${{ success() }}
  120. env:
  121. FBT_NO_SYNC: 0
  122. DIST_SUFFIX: ${{ matrix.version }}
  123. WORKFLOW_BRANCH_OR_TAG: release-cfw
  124. # rm to remove problem FAP which includes non-existent files
  125. run: |
  126. ./fbt COMPACT=1 DEBUG=0 FBT_NO_SYNC=0 fap_dist
  127. # - name: Save FBT
  128. # id: cache-save
  129. # if: ${{ success() }}
  130. # uses: actions/cache/save@v3
  131. # with:
  132. # path: |
  133. # build/**
  134. # debug/**
  135. # # An explicit key for restoring and saving the cache
  136. # key: ${{ steps.cache-restore.outputs.cache-primary-key }}
  137. - name: Create assets
  138. if: ${{ success() }}
  139. shell: pwsh
  140. env:
  141. APP_NAME: "subghz_bruteforcer_${{ env.RELEASE_VERSION }}_${{ matrix.firmware }}"
  142. run: |
  143. function Format-Bytes {
  144. param(
  145. [int]$number
  146. )
  147. $sizes = 'KB', 'MB', 'GB', 'TB', 'PB'
  148. for ($x = 0; $x -lt $sizes.count; $x++) {
  149. if ($number -lt [int64]"1$($sizes[$x])") {
  150. if ($x -eq 0) {
  151. return "$number B"
  152. }
  153. else {
  154. $formattedNumber = $number / [int64]"1$($sizes[$x-1])"
  155. $formattedNumber = "{0:N2}" -f $formattedNumber
  156. return "$formattedNumber $($sizes[$x-1])"
  157. }
  158. }
  159. }
  160. }
  161. $zipName = ('{0}.zip' -f $env:APP_NAME)
  162. $tgzName = ('{0}.tgz' -f $env:APP_NAME)
  163. $fapName = 'subghz_bruteforcer.fap'
  164. $dstFap = "./$fapName"
  165. $appDir = "dist/f7-C/apps/Sub-GHz"
  166. if (!(Test-Path -Path "$appDir/$fapName" -PathType Leaf)) {
  167. Write-Error '::error title=Files not found::Cannot find files in location'
  168. exit 1
  169. }
  170. $size = (Get-Item -Path "$appDir/$fapName" | Get-ItemPropertyValue -Name Length)
  171. Write-Output ('Filesize: {0}' -f (Format-Bytes $size))
  172. Copy-Item -Force -Verbose -Path "$appDir/$fapName" -Destination $dstFap
  173. zip -r -qq $zipName $dstFap
  174. tar zcf $tgzName $dstFap
  175. if ( !(Test-Path -Path $zipName -PathType Leaf) -or !(Test-Path -Path $tgzName -PathType Leaf) ) {
  176. Write-Error '::error title=Files not found::Cannot find files in location'
  177. exit 1
  178. }
  179. $zipSize = Format-Bytes (Get-Item -Path $zipName).Length
  180. $tgzSize = Format-Bytes (Get-Item -Path $tgzName ).Length
  181. Write-Output ('ZIP_NAME={0}' -f $zipName) >> $env:GITHUB_ENV
  182. Write-Output ('TGZ_NAME={0}' -f $tgzName ) >> $env:GITHUB_ENV
  183. Write-Output ('ZIP_TAG={0} ({1})' -f $zipName, $zipSize) >> $env:GITHUB_ENV
  184. Write-Output ('TGZ_TAG={0} ({1})' -f $tgzName , $tgzSize) >> $env:GITHUB_ENV
  185. - name: Upload assets
  186. if: ${{ success() && env.ZIP_NAME != '' }}
  187. shell: pwsh
  188. env:
  189. GITHUB_TOKEN: ${{ secrets.FLIPPER_TOKEN }}
  190. run: |
  191. $mime = "Accept: application/vnd.github+json"
  192. $api = "X-GitHub-Api-Version: 2022-11-28"
  193. $json = (gh api -H $mime -H $api /repos/${{ github.REPOSITORY }}/releases) | ConvertFrom-Json
  194. $tagExists = ($json.GetEnumerator() | Where-Object { $_.tag_name -eq 'v${{ env.RELEASE_VERSION }}' }) -ne $null
  195. if ( $tagExists -eq $false ) {
  196. gh api --method POST -H $mime -H $api /repos/${{ github.REPOSITORY }}/releases -f tag_name='v${{ env.RELEASE_VERSION }}' -f target_commitish='${{ env.SHA }}' -f body='Firmware version: [${{ env.FW_VERSION }}](${{ env.FW_URL }}) ' -f name='v${{ env.RELEASE_VERSION }}' -F draft=true -F prerelease=false -F generate_release_notes=true
  197. }
  198. gh release upload 'v${{ env.RELEASE_VERSION }}' '${{ env.ZIP_NAME }}#${{ env.ZIP_TAG }}' '${{ env.TGZ_NAME }}#${{ env.TGZ_TAG }}' --clobber -R ${{ env.REPO_SELF }}
  199. gh release edit 'v${{ env.RELEASE_VERSION }}' --draft=false -R ${{ env.REPO_SELF }}
  200. #EOF