build-with-firmwware.yml 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. ZIP_NAME: ""
  31. ZIP_TAG: ""
  32. TGZ_NAME: ""
  33. TGZ_TAG: ""
  34. strategy:
  35. fail-fast: false
  36. matrix:
  37. firmware: [unlshd, official]
  38. include:
  39. - firmware: unlshd
  40. url: ${{ vars.REPO_UNLEASHED }}
  41. version: ${{ vars.FIRMWARE_VERSION }}
  42. src-included: 0
  43. - firmware: official
  44. url: ${{ vars.REPO_OFFICIAL }}
  45. version: "official"
  46. src-included: 0
  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 Firmware 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.OFW_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.OFW_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.OFW_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: Remove other apps
  126. shell: pwsh
  127. if: ${{ success() }}
  128. # rm to remove problem FAP which includes non-existent files
  129. run: |
  130. Remove-Item -Force -Recurse ./applications/debug -ErrorAction SilentlyContinue
  131. Remove-Item -Force -Recurse ./applications/examples -ErrorAction SilentlyContinue
  132. # New-Item -Force ./tmp -ItemType Directory -ErrorAction SilentlyContinue
  133. # Copy-Item -Force -Recurse ./applications/external/subbrute/ ./tmp/ -ErrorAction SilentlyContinue
  134. # Remove-Item -Force -Recurse ./applications/external/* -ErrorAction SilentlyContinue
  135. # Copy-Item -Force -Recurse /tmp/* ./applications/external/ -ErrorAction SilentlyContinue
  136. # Remove-Item -Force -Recurse ./tmp -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. ZIP_NAME: "subghz_bruteforcer_${{ env.RELEASE_VERSION }}_${{ matrix.firmware }}.zip"
  171. TGZ_NAME: "subghz_bruteforcer_${{ env.RELEASE_VERSION }}_${{ matrix.firmware }}.tgz"
  172. run: |
  173. function Format-Bytes {
  174. param(
  175. [int]$number
  176. )
  177. $sizes = 'KB', 'MB', 'GB', 'TB', 'PB'
  178. for ($x = 0; $x -lt $sizes.count; $x++) {
  179. if ($number -lt [int64]"1$($sizes[$x])") {
  180. if ($x -eq 0) {
  181. return "$number B"
  182. }
  183. else {
  184. $num = $number / [int64]"1$($sizes[$x-1])"
  185. $num = "{0:N2}" -f $num
  186. return "$num $($sizes[$x-1])"
  187. }
  188. }
  189. }
  190. }
  191. $ZipName = $env:ZIP_NAME
  192. $TgzName = $env:TGZ_NAME
  193. $FapNamme = 'subghz_bruteforcer.fap'
  194. $DstFap = "./$FapNamme"
  195. $AppDir = "dist/f7-C/apps/Sub-GHz"
  196. if (!(Test-Path -Path "$AppDir/$FapNamme" -PathType Leaf)) {
  197. Write-Error '::error title=Files not found::Cannot find files in location'
  198. exit 1
  199. }
  200. $Size = (Get-Item -Path "$AppDir/$FapNamme" | Get-ItemPropertyValue -Name Length)
  201. Write-Output ('Filesize: {0}' -f (Format-Bytes $Size))
  202. Copy-Item -Force -Verbose -Path "$AppDir/$FapNamme" -Destination $DstFap
  203. zip -r -qq $ZipName $DstFap
  204. tar zcf $TgzName $DstFap
  205. if ( !(Test-Path -Path $ZipName -PathType Leaf) -or !(Test-Path -Path $TgzName -PathType Leaf) ) {
  206. Write-Error '::error title=Files not found::Cannot find files in location'
  207. exit 1
  208. }
  209. $ZipSize = Format-Bytes (Get-Item -Path $ZipName).Length
  210. $TgzSize = Format-Bytes (Get-Item -Path $TgzName ).Length
  211. Write-Output ('ZIP_NAME={0}' -f $ZipName) >> $env:GITHUB_ENV
  212. Write-Output ('TGZ_NAME={0}' -f $TgzName ) >> $env:GITHUB_ENV
  213. Write-Output ('ZIP_TAG={0} ({1})' -f $ZipName, $ZipSize) >> $env:GITHUB_ENV
  214. Write-Output ('TGZ_TAG={0} ({1})' -f $TgzName , $TgzSize) >> $env:GITHUB_ENV
  215. - name: Upload assets
  216. if: ${{ success() && env.ZIP_NAME != '' }}
  217. env:
  218. GITHUB_TOKEN: ${{ secrets.FLIPPER_TOKEN }}
  219. run: |
  220. gh release create v${{ env.RELEASE_VERSION }} --generate-notes --draft -R ${{ env.REPO_SELF }}
  221. gh release upload 'v${{ env.RELEASE_VERSION }}' '${{ env.ZIP_NAME }}#${{ env.ZIP_TAG }}' \
  222. '${{ env.TGZ_NAME }}#${{ env.TGZ_TAG }}' --clobber -R ${{ env.REPO_SELF }}
  223. gh release edit 'v${{ env.RELEASE_VERSION }}' --draft=false -R ${{ env.REPO_SELF }}
  224. #EOF