build-with-firmwware.yml 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. jobs:
  19. build-and-upload:
  20. # runs-on: [self-hosted, linux]
  21. runs-on: ubuntu-latest
  22. concurrency:
  23. group: firmware-build-${{ vars.FIRMWARE_VERSION }}-${{ vars.RELEASE_VERSION }}
  24. cancel-in-progress: false
  25. env:
  26. REPO_SELF: ${{ vars.REPO_SELF }}
  27. IGNORED_PATH: "applications_user/subbrute"
  28. RELATIVE_PATH: "applications/external/subbrute"
  29. CURRENT_VERSION: ${{ vars.RELEASE_VERSION }}
  30. RELEASE_VERSION: ${{ vars.RELEASE_VERSION }}
  31. ZIP_NAME: ''
  32. ZIP_TAG: ''
  33. strategy:
  34. fail-fast: false
  35. matrix:
  36. firmware: [unlshd]
  37. include:
  38. - firmware: unlshd
  39. url: ${{ vars.REPO_UNLEASHED }}
  40. version: ${{ vars.FIRMWARE_VERSION }}
  41. src-included: 1
  42. #- firmware: official
  43. # url: ${{ vars.REPO_OFFICIAL }}
  44. # version: "official"
  45. steps:
  46. - name: Set version
  47. env:
  48. INPUT_VERSION: ${{ inputs.version }}
  49. CURRENT_VERSION: ${{ env.CURRENT_VERSION }}
  50. shell: pwsh
  51. run: |
  52. $ReleaseVersion = ([string]::IsNullOrWhitespace($env:INPUT_VERSION) ? $env:CURRENT_VERSION : $env:INPUT_VERSION)
  53. Write-Output ('RELEASE_VERSION={0}' -f $ReleaseVersion) >> $env:GITHUB_ENV
  54. - name: Copy Repo Files
  55. uses: actions/checkout@v3
  56. with:
  57. repository: "${{ matrix.url }}"
  58. clean: "true"
  59. submodules: "true"
  60. ref: "dev"
  61. - name: Copy Repo Files
  62. if: ${{ matrix.src-included == 0 }}
  63. uses: actions/checkout@v3
  64. with:
  65. repository: "${{ vars.REPO_SELF }}"
  66. clean: "true"
  67. submodules: "true"
  68. path: "${{ env.IGNORED_PATH }}"
  69. - name: Print vars about state or repo if Unleashed
  70. if: ${{ matrix.src-included == 1 }}
  71. shell: pwsh
  72. run: |
  73. git log --pretty=format:'%s by %C(yellow)%an%Creset (%ad)%n %n%b' --date=local --abbrev-commit --max-count=1
  74. git submodule set-branch --branch master '${{ env.RELATIVE_PATH }}'
  75. git submodule sync '${{ env.RELATIVE_PATH }}'
  76. cd '${{ env.RELATIVE_PATH }}'
  77. if ( '${{ env.CURRENT_VERSION }}' -ne '${{ env.RELEASE_VERSION }}' ) {
  78. Write-Output '::warning title=Different version::Current version is ${{ env.CURRENT_VERSION }} but we trying to build ${{ env.RELEASE_VERSION }}'
  79. git checkout tags/v${{ env.RELEASE_VERSION }} -b tmp-build
  80. if ( $LASTEXITCODE -ne 0 ) {
  81. Write-Error '::error title=Cannot checkout to this version::Error during execution checkout to this tag ${{ env.RELEASE_VERSION }}'
  82. exit 1
  83. }
  84. }
  85. $Output = (git log --pretty=format:'%s by %C(yellow)%an%Creset (%ad)%n %n%b' --date=local --abbrev-commit --max-count=1)
  86. if ( $LASTEXITCODE -ne 0 ) {
  87. Write-Error '::error title=Invalid checkout::Invalid checkout'
  88. exit 1
  89. }
  90. Write-Output ('::notice title=Git output::{0}' -f $Output)
  91. - name: Print vars about state or repo if Official
  92. if: ${{ matrix.src-included == 0 }}
  93. shell: pwsh
  94. run: |
  95. git log --pretty=format:'%s by %C(yellow)%an%Creset (%ad)%n %n%b' --date=local --abbrev-commit --max-count=1
  96. cd '${{ env.IGNORED_PATH }}'
  97. if ( '${{ env.CURRENT_VERSION }}' -ne '${{ env.RELEASE_VERSION }}' ) {
  98. Write-Output '::warning title=Different version::Current version is ${{ env.CURRENT_VERSION }} but we trying to build ${{ env.RELEASE_VERSION }}'
  99. git checkout tags/v${{ env.RELEASE_VERSION }} -b tmp-build
  100. if ( $LASTEXITCODE -ne 0 ) {
  101. Write-Error '::error title=Cannot checkout to this version::Error during execution checkout to this tag ${{ env.RELEASE_VERSION }}'
  102. exit 1
  103. }
  104. } else {
  105. $Output = (git log --pretty=format:'%s by %C(yellow)%an%Creset (%ad)%n %n%b' --date=local --abbrev-commit --max-count=1)
  106. if ( $LASTEXITCODE -ne 0 ) {
  107. Write-Error '::error title=Invalid checkout::Invalid checkout'
  108. exit 1
  109. }
  110. Write-Output ('::notice title=Git output::{0}' -f $Output)
  111. }
  112. # - name: Restore FBT
  113. # id: cache-restore
  114. # if: ${{ success() }}
  115. # uses: actions/cache/restore@v3
  116. # with:
  117. # path: |
  118. # build/**
  119. # debug/**
  120. # # An explicit key for restoring and saving the cache
  121. # key: 'fbt=${{ env.FIRMWARE_VERSION }}'
  122. #
  123. - name: Build Firmware
  124. shell: bash
  125. if: ${{ success() }}
  126. env:
  127. FBT_NO_SYNC: 0
  128. DIST_SUFFIX: ${{ matrix.version }}
  129. WORKFLOW_BRANCH_OR_TAG: release-cfw
  130. run: |
  131. ./fbt COMPACT=1 DEBUG=0 FBT_NO_SYNC=0
  132. - name: Build FAPs
  133. shell: bash
  134. if: ${{ success() }}
  135. env:
  136. FBT_NO_SYNC: 0
  137. DIST_SUFFIX: ${{ matrix.version }}
  138. WORKFLOW_BRANCH_OR_TAG: release-cfw
  139. # rm to remove problem FAP which includes non existent files
  140. run: |
  141. rm -Rf ./applications/debug/subghz_test
  142. ./fbt COMPACT=1 DEBUG=0 FBT_NO_SYNC=0 fap_dist
  143. # - name: Save FBT
  144. # id: cache-save
  145. # if: ${{ success() }}
  146. # uses: actions/cache/save@v3
  147. # with:
  148. # path: |
  149. # build/**
  150. # debug/**
  151. # # An explicit key for restoring and saving the cache
  152. # key: ${{ steps.cache-restore.outputs.cache-primary-key }}
  153. - name: Create assets
  154. if: ${{ success() }}
  155. shell: pwsh
  156. env:
  157. ZIP_NAME: "subghz_bruteforcer_${{ env.RELEASE_VERSION }}_${{ matrix.firmware }}.zip"
  158. TGZ_NAME: "subghz_bruteforcer_${{ env.RELEASE_VERSION }}_${{ matrix.firmware }}.tgz"
  159. run: |
  160. function Format-Bytes {
  161. param(
  162. [int]$number
  163. )
  164. $sizes = 'KB', 'MB', 'GB', 'TB', 'PB'
  165. for ($x = 0; $x -lt $sizes.count; $x++) {
  166. if ($number -lt [int64]"1$($sizes[$x])") {
  167. if ($x -eq 0) {
  168. return "$number B"
  169. }
  170. else {
  171. $num = $number / [int64]"1$($sizes[$x-1])"
  172. $num = "{0:N2}" -f $num
  173. return "$num $($sizes[$x-1])"
  174. }
  175. }
  176. }
  177. }
  178. $ZipName = $env:ZIP_NAME
  179. $TgzName = $env:TGZ_NAME
  180. $FapNamme = 'SubGHz_Bruteforcer.fap'
  181. $DstFap = "./$FapNamme"
  182. if (!(Test-Path -Path "dist/f7-C/apps/Sub-GHz/$FapNamme" -PathType Leaf)) {
  183. Write-Error '::error title=Files not found::Cannot find files in location'
  184. exit 1
  185. }
  186. $Size = (Get-Item -Path "dist/f7-C/apps/Sub-GHz/$FapNamme" | Get-ItemPropertyValue -Name Length)
  187. Write-Output ('Filesize: {0}' -f (Format-Bytes $Size))
  188. Copy-Item -Force -Path "dist/f7-C/apps/Sub-GHz/$FapNamme" -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: Create assets
  202. if: ${{ success() && env.ZIP_NAME != '' }}
  203. env:
  204. GITHUB_TOKEN: ${{ secrets.FLIPPER_TOKEN }}
  205. run: |
  206. gh release upload 'v${{ env.RELEASE_VERSION }}' --clobber \
  207. '${{ env.ZIP_NAME }}#${{ env.ZIP_TAG }}' '${{ env.TGZ_NAME }}#${{ env.TGZ_TAG }}' -R ${{ env.REPO_SELF }}
  208. gh release edit 'v${{ env.RELEASE_VERSION }}' --draft=false -R ${{ env.REPO_SELF }}
  209. #EOF