build-with-firmwware.yml 8.4 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. RELEASE_VERSION: ""
  29. APP_NAME: ""
  30. ZIP_NAME: ""
  31. ZIP_TAG: ""
  32. TGZ_NAME: ""
  33. TGZ_TAG: ""
  34. SHA: ""
  35. FW_VERSION: ""
  36. strategy:
  37. fail-fast: false
  38. matrix:
  39. firmware: [unlshd, official]
  40. include:
  41. - firmware: unlshd
  42. url: ${{ vars.REPO_UNLEASHED }}
  43. version: ${{ vars.FIRMWARE_VERSION }}
  44. src-included: 0
  45. - firmware: official
  46. url: ${{ vars.REPO_OFFICIAL }}
  47. version: "official"
  48. src-included: 0
  49. steps:
  50. - name: Copy Firmware Files
  51. uses: actions/checkout@v3
  52. with:
  53. repository: ${{ matrix.url }}
  54. clean: true
  55. submodules: true
  56. ref: dev
  57. - name: Copy Repo Files
  58. if: ${{ matrix.src-included == 0 }}
  59. uses: actions/checkout@v3
  60. with:
  61. repository: ${{ vars.REPO_SELF }}
  62. clean: true
  63. submodules: true
  64. path: ${{ env.APP_PATH }}
  65. # - name: Restore FBT
  66. # id: cache-restore
  67. # if: ${{ success() }}
  68. # uses: actions/cache/restore@v3
  69. # with:
  70. # path: |
  71. # build/**
  72. # debug/**
  73. # # An explicit key for restoring and saving the cache
  74. # key: 'fbt=${{ env.FIRMWARE_VERSION }}'
  75. #
  76. - name: Remove other apps
  77. shell: pwsh
  78. if: ${{ success() }}
  79. # rm to remove problem FAP which includes non-existent files
  80. run: |
  81. Remove-Item -Force -Recurse ./applications/debug -ErrorAction SilentlyContinue
  82. Remove-Item -Force -Recurse ./applications/examples -ErrorAction SilentlyContinue
  83. Remove-Item -Force -Recurse ${{ env.RELATIVE_PATH }} -ErrorAction SilentlyContinue
  84. - name: Get SHA of our application and release version
  85. shell: pwsh
  86. env:
  87. GITHUB_TOKEN: ${{ secrets.FLIPPER_TOKEN }}
  88. INPUT_VERSION: ${{ inputs.version }}
  89. run: |
  90. $fwInfo = ((gh release view --json tagName,url -R ${{ matrix.url }}) | ConvertFrom-Json)
  91. cd '${{ env.APP_PATH }}'
  92. $sha = (git rev-parse --verify HEAD)
  93. $releaseVersion = $env:INPUT_VERSION
  94. if ( [string]::IsNullOrWhitespace($env:INPUT_VERSION) ) {
  95. $latestTag = ((gh release view --json tagName,url -R ${{ vars.REPO_SELF }}) | ConvertFrom-Json ).tagName
  96. $lastIndex = $latestTag.LastIndexOf('.')
  97. $minorValue = $latestTag.Substring($latestTag.LastIndexOf('.'))
  98. $minorValue = [Convert]::ToInt32($minorValue) + 1
  99. $latestTag = $latestTag.Substring(0, $lastIndex)
  100. $releaseVersion = ('{0}.{1}', $latestTag, $minorValue)
  101. }
  102. if ( $releaseVersion.StartsWith('v') ) {
  103. $releaseVersion = $releaseVersion.Substring(1)
  104. }
  105. Write-Output ('RELEASE_VERSION={0}' -f $releaseVersion) >> $env:GITHUB_ENV
  106. Write-Output ('SHA={0}' -f $sha) >> $env:GITHUB_ENV
  107. Write-Output ('FW_VERSION={0}' -f $fwInfo.tagName) >> $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 }}"
  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. $appName = $env:APP_NAME
  162. if ( '${{ matrix.firmware }}' -eq 'unlshd' ) {
  163. $appName = ('{0}_${{ env.FW_VERSION }}' -f $appName)
  164. } else {
  165. $appName = ('{0}_${{ matrix.firmware}}-${{ env.FW_VERSION }}' -f $appName)
  166. }
  167. $zipName = ('{0}.zip' -f $appName)
  168. $tgzName = ('{0}.tgz' -f $appName)
  169. $fapName = 'subghz_bruteforcer.fap'
  170. $dstFap = "./$fapName"
  171. $appDir = "dist/f7-C/apps/Sub-GHz"
  172. if (!(Test-Path -Path "$appDir/$fapName" -PathType Leaf)) {
  173. Write-Error '::error title=Files not found::Cannot find files in location'
  174. exit 1
  175. }
  176. $size = (Get-Item -Path "$appDir/$fapName" | Get-ItemPropertyValue -Name Length)
  177. Write-Output ('Filesize: {0}' -f (Format-Bytes $size))
  178. Copy-Item -Force -Verbose -Path "$appDir/$fapName" -Destination $dstFap
  179. zip -r -qq $zipName $dstFap
  180. tar zcf $tgzName $dstFap
  181. if ( !(Test-Path -Path $zipName -PathType Leaf) -or !(Test-Path -Path $tgzName -PathType Leaf) ) {
  182. Write-Error '::error title=Files not found::Cannot find files in location'
  183. exit 1
  184. }
  185. $zipSize = Format-Bytes (Get-Item -Path $zipName).Length
  186. $tgzSize = Format-Bytes (Get-Item -Path $tgzName ).Length
  187. Write-Output ('ZIP_NAME={0}' -f $zipName) >> $env:GITHUB_ENV
  188. Write-Output ('TGZ_NAME={0}' -f $tgzName ) >> $env:GITHUB_ENV
  189. Write-Output ('ZIP_TAG={0} ({1})' -f $zipName, $zipSize) >> $env:GITHUB_ENV
  190. Write-Output ('TGZ_TAG={0} ({1})' -f $tgzName , $tgzSize) >> $env:GITHUB_ENV
  191. - name: Upload assets
  192. if: ${{ success() && env.ZIP_NAME != '' }}
  193. shell: pwsh
  194. env:
  195. GITHUB_TOKEN: ${{ secrets.FLIPPER_TOKEN }}
  196. run: |
  197. $mime = "Accept: application/vnd.github+json"
  198. $api = "X-GitHub-Api-Version: 2022-11-28"
  199. $json = (gh api -H $mime -H $api /repos/${{ github.REPOSITORY }}/releases) | ConvertFrom-Json
  200. $tagExists = ($json.GetEnumerator() | Where-Object { $_.tag_name -eq 'v${{ env.RELEASE_VERSION }}' }) -ne $null
  201. if ( $tagExists -eq $false ) {
  202. 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
  203. }
  204. gh release upload 'v${{ env.RELEASE_VERSION }}' '${{ env.ZIP_NAME }}#${{ env.ZIP_TAG }}' '${{ env.TGZ_NAME }}#${{ env.TGZ_TAG }}' --clobber -R ${{ env.REPO_SELF }}
  205. gh release edit 'v${{ env.RELEASE_VERSION }}' --draft=false -R ${{ env.REPO_SELF }}
  206. #EOF