build-with-firmwware.yml 8.2 KB

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