build-with-firmwware.yml 9.2 KB

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