build-with-firmwware.yml 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. OFW_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. 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: Set version
  50. env:
  51. INPUT_VERSION: ${{ inputs.version }}
  52. CURRENT_VERSION: ${{ env.CURRENT_VERSION }}
  53. shell: pwsh
  54. run: |
  55. $releaseVersion = ([string]::IsNullOrWhitespace($env:INPUT_VERSION) ? $env:CURRENT_VERSION : $env:INPUT_VERSION)
  56. if ( $releaseVersion.StartsWith('v') ) {
  57. $releaseVersion = $releaseVersion.Substring(1)
  58. }
  59. Write-Output ('RELEASE_VERSION={0}' -f $releaseVersion) >> $env:GITHUB_ENV
  60. - name: Copy Firmware Files
  61. uses: actions/checkout@v3
  62. with:
  63. repository: ${{ matrix.url }}
  64. clean: "true"
  65. submodules: "true"
  66. ref: "dev"
  67. - name: Copy Repo Files
  68. if: ${{ matrix.src-included == 0 }}
  69. uses: actions/checkout@v3
  70. with:
  71. repository: ${{ vars.REPO_SELF }}
  72. clean: "true"
  73. submodules: "true"
  74. path: "${{ env.OFW_PATH }}"
  75. - name: Print vars about state or repo if Unleashed
  76. if: ${{ matrix.src-included == 1 }}
  77. shell: pwsh
  78. run: |
  79. git log --pretty=format:'%s by %C(yellow)%an%Creset (%ad)%n %n%b' --date=local --abbrev-commit --max-count=1
  80. git submodule set-branch --branch master '${{ env.RELATIVE_PATH }}'
  81. git submodule sync '${{ env.RELATIVE_PATH }}'
  82. cd '${{ env.OFW_PATH }}'
  83. if ( '${{ env.CURRENT_VERSION }}' -ne '${{ env.RELEASE_VERSION }}' ) {
  84. Write-Output '::warning title=Different version::Current version is ${{ env.CURRENT_VERSION }} but we trying to build ${{ env.RELEASE_VERSION }}'
  85. git checkout tags/v${{ env.RELEASE_VERSION }} -b tmp-build
  86. if ( $LASTEXITCODE -ne 0 ) {
  87. Write-Error '::warning title=Cannot checkout to this version::Error during execution checkout to this tag ${{ env.RELEASE_VERSION }}'
  88. #exit 1
  89. }
  90. } else {
  91. $output = (git log --pretty=format:'%s by %C(yellow)%an%Creset (%ad)%n %n%b' --date=local --abbrev-commit --max-count=1)
  92. if ( $LASTEXITCODE -ne 0 ) {
  93. Write-Error '::error title=Invalid checkout::Invalid checkout'
  94. exit 1
  95. }
  96. Write-Output ('::notice title=Git output::{0}' -f $output)
  97. }
  98. - name: Print vars about state or repo if Official
  99. if: ${{ matrix.src-included == 0 }}
  100. shell: pwsh
  101. run: |
  102. git log --pretty=format:'%s by %C(yellow)%an%Creset (%ad)%n %n%b' --date=local --abbrev-commit --max-count=1
  103. cd '${{ env.OFW_PATH }}'
  104. if ( '${{ env.CURRENT_VERSION }}' -ne '${{ env.RELEASE_VERSION }}' ) {
  105. Write-Output '::warning title=Different version::Current version is ${{ env.CURRENT_VERSION }} but we trying to build ${{ env.RELEASE_VERSION }}'
  106. git checkout tags/v${{ env.RELEASE_VERSION }} -b tmp-build
  107. if ( $LASTEXITCODE -ne 0 ) {
  108. Write-Error '::warning title=Cannot checkout to this version::Error during execution checkout to this tag ${{ env.RELEASE_VERSION }}'
  109. #exit 1
  110. }
  111. } else {
  112. $output = (git log --pretty=format:'%s by %C(yellow)%an%Creset (%ad)%n %n%b' --date=local --abbrev-commit --max-count=1)
  113. if ( $LASTEXITCODE -ne 0 ) {
  114. Write-Error '::error title=Invalid checkout::Invalid checkout'
  115. exit 1
  116. }
  117. Write-Output ('::notice title=Git output::{0}' -f $output)
  118. }
  119. # - name: Restore FBT
  120. # id: cache-restore
  121. # if: ${{ success() }}
  122. # uses: actions/cache/restore@v3
  123. # with:
  124. # path: |
  125. # build/**
  126. # debug/**
  127. # # An explicit key for restoring and saving the cache
  128. # key: 'fbt=${{ env.FIRMWARE_VERSION }}'
  129. #
  130. - name: Remove other apps
  131. shell: pwsh
  132. if: ${{ success() }}
  133. # rm to remove problem FAP which includes non-existent files
  134. run: |
  135. Remove-Item -Force -Recurse ./applications/debug -ErrorAction SilentlyContinue
  136. Remove-Item -Force -Recurse ./applications/examples -ErrorAction SilentlyContinue
  137. - name: Build Firmware
  138. shell: bash
  139. if: ${{ success() }}
  140. env:
  141. FBT_NO_SYNC: 0
  142. DIST_SUFFIX: ${{ matrix.version }}
  143. WORKFLOW_BRANCH_OR_TAG: release-cfw
  144. run: |
  145. ./fbt COMPACT=1 DEBUG=0 FBT_NO_SYNC=0
  146. - name: Build FAPs
  147. shell: bash
  148. if: ${{ success() }}
  149. env:
  150. FBT_NO_SYNC: 0
  151. DIST_SUFFIX: ${{ matrix.version }}
  152. WORKFLOW_BRANCH_OR_TAG: release-cfw
  153. # rm to remove problem FAP which includes non-existent files
  154. run: |
  155. ./fbt COMPACT=1 DEBUG=0 FBT_NO_SYNC=0 fap_dist
  156. # - name: Save FBT
  157. # id: cache-save
  158. # if: ${{ success() }}
  159. # uses: actions/cache/save@v3
  160. # with:
  161. # path: |
  162. # build/**
  163. # debug/**
  164. # # An explicit key for restoring and saving the cache
  165. # key: ${{ steps.cache-restore.outputs.cache-primary-key }}
  166. - name: Create assets
  167. if: ${{ success() }}
  168. shell: pwsh
  169. env:
  170. APP_NAME: "subghz_bruteforcer_${{ env.RELEASE_VERSION }}_${{ matrix.firmware }}"
  171. run: |
  172. function Format-Bytes {
  173. param(
  174. [int]$number
  175. )
  176. $sizes = 'KB', 'MB', 'GB', 'TB', 'PB'
  177. for ($x = 0; $x -lt $sizes.count; $x++) {
  178. if ($number -lt [int64]"1$($sizes[$x])") {
  179. if ($x -eq 0) {
  180. return "$number B"
  181. }
  182. else {
  183. $formattedNumber = $number / [int64]"1$($sizes[$x-1])"
  184. $formattedNumber = "{0:N2}" -f $formattedNumber
  185. return "$formattedNumber $($sizes[$x-1])"
  186. }
  187. }
  188. }
  189. }
  190. $zipName = ('{0}.zip' -f $env:APP_NAME)
  191. $tgzName = ('{0}.tgz' -f $env:APP_NAME)
  192. $fapName = 'subghz_bruteforcer.fap'
  193. $dstFap = "./$fapName"
  194. $appDir = "dist/f7-C/apps/Sub-GHz"
  195. if (!(Test-Path -Path "$appDir/$fapName" -PathType Leaf)) {
  196. Write-Error '::error title=Files not found::Cannot find files in location'
  197. exit 1
  198. }
  199. $size = (Get-Item -Path "$appDir/$fapName" | Get-ItemPropertyValue -Name Length)
  200. Write-Output ('Filesize: {0}' -f (Format-Bytes $size))
  201. Copy-Item -Force -Verbose -Path "$appDir/$fapName" -Destination $dstFap
  202. zip -r -qq $zipName $dstFap
  203. tar zcf $tgzName $dstFap
  204. if ( !(Test-Path -Path $zipName -PathType Leaf) -or !(Test-Path -Path $tgzName -PathType Leaf) ) {
  205. Write-Error '::error title=Files not found::Cannot find files in location'
  206. exit 1
  207. }
  208. $zipSize = Format-Bytes (Get-Item -Path $zipName).Length
  209. $tgzSize = Format-Bytes (Get-Item -Path $tgzName ).Length
  210. Write-Output ('ZIP_NAME={0}' -f $zipName) >> $env:GITHUB_ENV
  211. Write-Output ('TGZ_NAME={0}' -f $tgzName ) >> $env:GITHUB_ENV
  212. Write-Output ('ZIP_TAG={0} ({1})' -f $zipName, $zipSize) >> $env:GITHUB_ENV
  213. Write-Output ('TGZ_TAG={0} ({1})' -f $tgzName , $tgzSize) >> $env:GITHUB_ENV
  214. - name: Upload assets
  215. if: ${{ success() && env.ZIP_NAME != '' }}
  216. shell: pwsh
  217. env:
  218. GITHUB_TOKEN: ${{ secrets.FLIPPER_TOKEN }}
  219. run: |
  220. $url = (gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/${{ github.REPOSITORY }}/releases/tags/v${{ env.RELEASE_VERSION }}) | ConvertFrom-Json -AsHashtable
  221. if ( [string]::IsNullOrWhitespace($url.name) ) {
  222. $sha = (git rev-parse --verify HEAD)
  223. gh api --method POST -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/${{ github.REPOSITORY }}/releases -f tag_name='v${{ env.RELEASE_VERSION }}' -f target_commitish="$sha" -f name='v${{ env.RELEASE_VERSION }}' -F draft=true -F prerelease=false -F generate_release_notes=true
  224. #gh release create v${{ env.RELEASE_VERSION }} --generate-notes -f target_commitish='master' --draft -R ${{ env.REPO_SELF }}
  225. }
  226. gh release upload 'v${{ env.RELEASE_VERSION }}' '${{ env.ZIP_NAME }}#${{ env.ZIP_TAG }}' '${{ env.TGZ_NAME }}#${{ env.TGZ_TAG }}' --clobber -R ${{ env.REPO_SELF }}
  227. gh release edit 'v${{ env.RELEASE_VERSION }}' --draft=false -R ${{ env.REPO_SELF }}
  228. #EOF