|
| 1 | +name: "Build for Firmware" |
| 2 | +run-name: "Build ${{ inputs.DEPLOY_TARGET }} by @${{ github.ACTOR }}" |
| 3 | + |
| 4 | +on: |
| 5 | + workflow_dispatch: |
| 6 | + inputs: |
| 7 | + version: |
| 8 | + description: "Enter version to build or left empty for current version" |
| 9 | + required: false |
| 10 | + type: string |
| 11 | + release: |
| 12 | + types: [unpublished] |
| 13 | + push: |
| 14 | + paths: |
| 15 | + - .github/workflows/build-with-firmware.yml |
| 16 | + |
| 17 | +permissions: |
| 18 | + contents: write |
| 19 | + packages: write |
| 20 | + |
| 21 | +jobs: |
| 22 | + build-and-upload: |
| 23 | + # runs-on: [self-hosted, linux] |
| 24 | + runs-on: ubuntu-latest |
| 25 | + concurrency: |
| 26 | + group: firmware-build-${{ vars.FIRMWARE_VERSION }}-${{ vars.RELEASE_VERSION }} |
| 27 | + cancel-in-progress: false |
| 28 | + env: |
| 29 | + REPO_SELF: ${{ vars.REPO_SELF }} |
| 30 | + IGNORED_PATH: "applications_user/subbrute" |
| 31 | + RELATIVE_PATH: "applications/external/subbrute" |
| 32 | + CURRENT_VERSION: ${{ vars.RELEASE_VERSION }} |
| 33 | + strategy: |
| 34 | + fail-fast: false |
| 35 | + matrix: |
| 36 | + firmware: [unlshd] |
| 37 | + include: |
| 38 | + - firmware: unlshd |
| 39 | + url: ${{ vars.REPO_UNLEASHED }} |
| 40 | + version: ${{ vars.FIRMWARE_VERSION }} |
| 41 | + src-included: 1 |
| 42 | + #- firmware: official |
| 43 | + # url: ${{ vars.REPO_OFFICIAL }} |
| 44 | + # version: "official" |
| 45 | + steps: |
| 46 | + - name: Set version |
| 47 | + env: |
| 48 | + INPUT_VERSION: ${{ inputs.version }} |
| 49 | + CURRENT_VERSION: ${{ env.CURRENT_VERSION }} |
| 50 | + shell: pwsh |
| 51 | + run: | |
| 52 | + $ReleaseVersion = ([string]::IsNullOrWhitespace($env:INPUT_VERSION) ? $env:CURRENT_VERSION : $env:INPUT_VERSION) |
| 53 | + Write-Output ('RELEASE_VERSION={0}' -f $ReleaseVersion) >> $env:GITHUB_ENV |
| 54 | +
|
| 55 | + - name: Copy Repo Files |
| 56 | + uses: actions/checkout@v3 |
| 57 | + with: |
| 58 | + repository: "${{ matrix.url }}" |
| 59 | + clean: "true" |
| 60 | + submodules: "true" |
| 61 | + ref: "dev" |
| 62 | + |
| 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 | + |
| 72 | + - name: Print vars about state or repo if Unleashed |
| 73 | + if: ${{ matrix.src-included == 1 }} |
| 74 | + shell: pwsh |
| 75 | + run: | |
| 76 | + git log --pretty=format:'%s by %C(yellow)%an%Creset (%ad)%n %n%b' --date=local --abbrev-commit --max-count=1 |
| 77 | + git submodule set-branch --branch master '${{ env.RELATIVE_PATH }}' |
| 78 | + git submodule sync '${{ env.RELATIVE_PATH }}' |
| 79 | + cd '${{ env.RELATIVE_PATH }}' |
| 80 | + if ( '${{ env.CURRENT_VERSION }}' -ne '${{ env.RELEASE_VERSION }}' ) { |
| 81 | + Write-Output '::warning title=Different version::Current version is ${{ env.CURRENT_VERSION }} but we trying to build ${{ env.RELEASE_VERSION }}' |
| 82 | + git checkout tags/v${{ env.RELEASE_VERSION }} -b tmp-build |
| 83 | +
|
| 84 | + if ( $LASTEXITCODE -ne 0 ) { |
| 85 | + Write-Error '::error title=Cannot checkout to this version::Error during execution checkout to this tag ${{ env.RELEASE_VERSION }}' |
| 86 | + exit 1 |
| 87 | + } |
| 88 | + } |
| 89 | +
|
| 90 | + $Output = (git log --pretty=format:'%s by %C(yellow)%an%Creset (%ad)%n %n%b' --date=local --abbrev-commit --max-count=1) |
| 91 | +
|
| 92 | + if ( $LASTEXITCODE -ne 0 ) { |
| 93 | + Write-Error '::error title=Invalid checkout::Invalid checkout' |
| 94 | + exit 1 |
| 95 | + } |
| 96 | + Write-Output ('::notice title=Git output::{0}' -f $Output) |
| 97 | +
|
| 98 | + - name: Print vars about state or repo if Official |
| 99 | + if: ${{ matrix.src-included == 0 }} |
| 100 | + shell: pwsh |
| 101 | + run: | |
| 102 | + git log --pretty=format:'%s by %C(yellow)%an%Creset (%ad)%n %n%b' --date=local --abbrev-commit --max-count=1 |
| 103 | + cd '${{ env.IGNORED_PATH }}' |
| 104 | +
|
| 105 | + if ( '${{ env.CURRENT_VERSION }}' -ne '${{ env.RELEASE_VERSION }}' ) { |
| 106 | + Write-Output '::warning title=Different version::Current version is ${{ env.CURRENT_VERSION }} but we trying to build ${{ env.RELEASE_VERSION }}' |
| 107 | + git checkout tags/v${{ env.RELEASE_VERSION }} -b tmp-build |
| 108 | +
|
| 109 | + if ( $LASTEXITCODE -ne 0 ) { |
| 110 | + Write-Error '::error title=Cannot checkout to this version::Error during execution checkout to this tag ${{ env.RELEASE_VERSION }}' |
| 111 | + exit 1 |
| 112 | + } |
| 113 | + } else { |
| 114 | + $Output = (git log --pretty=format:'%s by %C(yellow)%an%Creset (%ad)%n %n%b' --date=local --abbrev-commit --max-count=1) |
| 115 | +
|
| 116 | + if ( $LASTEXITCODE -ne 0 ) { |
| 117 | + Write-Error '::error title=Invalid checkout::Invalid checkout' |
| 118 | + exit 1 |
| 119 | + } |
| 120 | + Write-Output ('::notice title=Git output::{0}' -f $Output) |
| 121 | + } |
| 122 | +
|
| 123 | + # - name: Restore FBT |
| 124 | + # id: cache-restore |
| 125 | + # if: ${{ success() }} |
| 126 | + # uses: actions/cache/restore@v3 |
| 127 | + # with: |
| 128 | + # path: | |
| 129 | + # build/** |
| 130 | + # debug/** |
| 131 | + # # An explicit key for restoring and saving the cache |
| 132 | + # key: 'fbt=${{ env.FIRMWARE_VERSION }}' |
| 133 | + # |
| 134 | + - name: Build Firmware |
| 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 | + run: | |
| 142 | + ./fbt COMPACT=1 DEBUG=0 fap_dist |
| 143 | +
|
| 144 | + # - name: Save FBT |
| 145 | + # id: cache-save |
| 146 | + # if: ${{ success() }} |
| 147 | + # uses: actions/cache/save@v3 |
| 148 | + # with: |
| 149 | + # path: | |
| 150 | + # build/** |
| 151 | + # debug/** |
| 152 | + # # An explicit key for restoring and saving the cache |
| 153 | + # key: ${{ steps.cache-restore.outputs.cache-primary-key }} |
| 154 | + |
| 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 | +
|
| 185 | + if (!(Test-Path -Path "dist/f7-C/apps/Sub-GHz/$FapNamme" -PathType Leaf)) { |
| 186 | + Write-Error '::error title=Files not found::Cannot find files in location' |
| 187 | + exit 1 |
| 188 | + } |
| 189 | +
|
| 190 | + $Size = (Get-Item -Path "dist/f7-C/apps/Sub-GHz/$FapNamme" | Get-ItemPropertyValue -Name Length) |
| 191 | + Write-Output ('Filesize: {0}' -f (Format-Bytes $Size)) |
| 192 | + Copy-Item -Force -Path "dist/f7-C/apps/Sub-GHz/$FapNamme" -Destination $DstFap |
| 193 | +
|
| 194 | + zip -r -qq $ZipName $DstFap |
| 195 | + tar zcf $TgzName $DstFap |
| 196 | +
|
| 197 | + if ( !(Test-Path -Path $ZipName -PathType Leaf) -or !(Test-Path -Path $TgzName -PathType Leaf) ) { |
| 198 | + Write-Error '::error title=Files not found::Cannot find files in location' |
| 199 | + exit 1 |
| 200 | + } |
| 201 | +
|
| 202 | + $ZipSize = Format-Bytes (Get-Item -Path $ZipName).Length |
| 203 | + $TgzSize = Format-Bytes (Get-Item -Path $TgzName ).Length |
| 204 | +
|
| 205 | + Write-Output ('ZIP_NAME={0}' -f $ZipName) >> $env:GITHUB_ENV |
| 206 | + Write-Output ('TGZ_NAME={0}' -f $TgzName ) >> $env:GITHUB_ENV |
| 207 | + Write-Output ('ZIP_TAG={0} ({1})' -f $ZipName, $ZipSize) >> $env:GITHUB_ENV |
| 208 | + Write-Output ('TGZ_TAG={0} ({1})' -f $TgzName , $TgzSize) >> $env:GITHUB_ENV |
| 209 | + - name: Create assets |
| 210 | + if: ${{ success() && env.ZIP_NAME != '' }} |
| 211 | + env: |
| 212 | + GITHUB_TOKEN: ${{ secrets.FLIPPER_TOKEN }} |
| 213 | + run: | |
| 214 | + gh release upload 'v${{ env.RELEASE_VERSION }}' --clobber \ |
| 215 | + '${{ env.ZIP_NAME }}#${{ env.ZIP_TAG }}' '${{ env.TGZ_NAME }}#${{ env.TGZ_TAG }}' -R ${{ env.REPO_SELF }} |
| 216 | + gh release edit 'v${{ env.RELEASE_VERSION }}' --draft=false -R ${{ env.REPO_SELF }} |
| 217 | +
|
| 218 | +#EOF |
0 commit comments