build-with-firmware.yml 9.3 KB

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