build-with-firmwware.yml 8.5 KB

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