build-with-firmwware.yml 8.2 KB

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