build-with-firmware.yml 9.1 KB

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