build-with-firmwware.yml 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. Write-Output "::notice title=Version Number::v${{ inputs.version }}"
  91. $fwInfo = ((gh release view --json tagName,url -R ${{ matrix.url }}) | ConvertFrom-Json)
  92. cd '${{ env.APP_PATH }}'
  93. $sha = (git rev-parse --verify HEAD)
  94. $releaseVersion = ''
  95. if ( [string]::IsNullOrWhitespace($env:INPUT_VERSION) ) {
  96. $latestTag = ((gh release view --json tagName,url -R ${{ vars.REPO_SELF }}) | ConvertFrom-Json ).tagName
  97. Write-Output "::notice title=Latest tag::$latestTag"
  98. $lastIndex = $latestTag.LastIndexOf('.')
  99. $minorValue = $latestTag.Substring($latestTag.LastIndexOf('.') + 1)
  100. $minorValue = [Convert]::ToInt32($minorValue) + 1
  101. $latestTag = $latestTag.Substring(0, $lastIndex)
  102. $releaseVersion = ('{0}.{1}' -f $latestTag, $minorValue)
  103. } else {
  104. $releaseVersion = "$env:INPUT_VERSION"
  105. }
  106. Write-Output "::notice title=Obtain Version Number::$releaseVersion"
  107. if ( $releaseVersion.StartsWith('v') ) {
  108. $releaseVersion = $releaseVersion.Substring(1)
  109. }
  110. Write-Output ('RELEASE_VERSION={0}' -f $releaseVersion) >> $env:GITHUB_ENV
  111. Write-Output ('SHA={0}' -f $sha) >> $env:GITHUB_ENV
  112. Write-Output ('FW_VERSION={0}' -f $fwInfo.tagName) >> $env:GITHUB_ENV
  113. - name: Build Firmware
  114. shell: bash
  115. if: ${{ success() }}
  116. env:
  117. FBT_NO_SYNC: 0
  118. DIST_SUFFIX: ${{ matrix.version }}
  119. WORKFLOW_BRANCH_OR_TAG: release-cfw
  120. run: |
  121. ./fbt COMPACT=1 DEBUG=0 FBT_NO_SYNC=0
  122. - name: Build FAPs
  123. shell: bash
  124. if: ${{ success() }}
  125. env:
  126. FBT_NO_SYNC: 0
  127. DIST_SUFFIX: ${{ matrix.version }}
  128. WORKFLOW_BRANCH_OR_TAG: release-cfw
  129. # rm to remove problem FAP which includes non-existent files
  130. run: |
  131. ./fbt COMPACT=1 DEBUG=0 FBT_NO_SYNC=0 fap_dist
  132. # - name: Save FBT
  133. # id: cache-save
  134. # if: ${{ success() }}
  135. # uses: actions/cache/save@v3
  136. # with:
  137. # path: |
  138. # build/**
  139. # debug/**
  140. # # An explicit key for restoring and saving the cache
  141. # key: ${{ steps.cache-restore.outputs.cache-primary-key }}
  142. - name: Create assets
  143. if: ${{ success() }}
  144. shell: pwsh
  145. env:
  146. APP_NAME: "subghz_bruteforcer_${{ env.RELEASE_VERSION }}"
  147. run: |
  148. function Format-Bytes {
  149. param(
  150. [int]$number
  151. )
  152. $sizes = 'KB', 'MB', 'GB', 'TB', 'PB'
  153. for ($x = 0; $x -lt $sizes.count; $x++) {
  154. if ($number -lt [int64]"1$($sizes[$x])") {
  155. if ($x -eq 0) {
  156. return "$number B"
  157. }
  158. else {
  159. $formattedNumber = $number / [int64]"1$($sizes[$x-1])"
  160. $formattedNumber = "{0:N2}" -f $formattedNumber
  161. return "$formattedNumber $($sizes[$x-1])"
  162. }
  163. }
  164. }
  165. }
  166. $appName = $env:APP_NAME
  167. if ( '${{ matrix.firmware }}' -eq 'unlshd' ) {
  168. $appName = ('{0}_${{ env.FW_VERSION }}' -f $appName)
  169. } else {
  170. $appName = ('{0}_${{ matrix.firmware}}-${{ env.FW_VERSION }}' -f $appName)
  171. }
  172. $zipName = ('{0}.zip' -f $appName)
  173. $tgzName = ('{0}.tgz' -f $appName)
  174. $fapName = 'subghz_bruteforcer.fap'
  175. $dstFap = "./$fapName"
  176. $appDir = "dist/f7-C/apps/Sub-GHz"
  177. if (!(Test-Path -Path "$appDir/$fapName" -PathType Leaf)) {
  178. Write-Error '::error title=Files not found::Cannot find files in location'
  179. exit 1
  180. }
  181. $size = (Get-Item -Path "$appDir/$fapName" | Get-ItemPropertyValue -Name Length)
  182. Write-Output ('Filesize: {0}' -f (Format-Bytes $size))
  183. Copy-Item -Force -Verbose -Path "$appDir/$fapName" -Destination $dstFap
  184. zip -r -qq $zipName $dstFap
  185. tar zcf $tgzName $dstFap
  186. if ( !(Test-Path -Path $zipName -PathType Leaf) -or !(Test-Path -Path $tgzName -PathType Leaf) ) {
  187. Write-Error '::error title=Files not found::Cannot find files in location'
  188. exit 1
  189. }
  190. $zipSize = Format-Bytes (Get-Item -Path $zipName).Length
  191. $tgzSize = Format-Bytes (Get-Item -Path $tgzName ).Length
  192. Write-Output ('ZIP_NAME={0}' -f $zipName) >> $env:GITHUB_ENV
  193. Write-Output ('TGZ_NAME={0}' -f $tgzName ) >> $env:GITHUB_ENV
  194. Write-Output ('ZIP_TAG={0} ({1})' -f $zipName, $zipSize) >> $env:GITHUB_ENV
  195. Write-Output ('TGZ_TAG={0} ({1})' -f $tgzName , $tgzSize) >> $env:GITHUB_ENV
  196. - name: Upload assets
  197. if: ${{ success() && env.ZIP_NAME != '' }}
  198. shell: pwsh
  199. env:
  200. GITHUB_TOKEN: ${{ secrets.FLIPPER_TOKEN }}
  201. run: |
  202. $mime = "Accept: application/vnd.github+json"
  203. $api = "X-GitHub-Api-Version: 2022-11-28"
  204. $json = (gh api -H $mime -H $api /repos/${{ github.REPOSITORY }}/releases) | ConvertFrom-Json
  205. $tagExists = ($json.GetEnumerator() | Where-Object { $_.tag_name -eq 'v${{ env.RELEASE_VERSION }}' }) -ne $null
  206. if ( $tagExists -eq $false ) {
  207. 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
  208. }
  209. gh release upload 'v${{ env.RELEASE_VERSION }}' '${{ env.ZIP_NAME }}#${{ env.ZIP_TAG }}' '${{ env.TGZ_NAME }}#${{ env.TGZ_TAG }}' --clobber -R ${{ env.REPO_SELF }}
  210. gh release edit 'v${{ env.RELEASE_VERSION }}' --draft=false -R ${{ env.REPO_SELF }}
  211. #EOF