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