|
| 1 | +name: "Force 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 | + |
| 12 | +permissions: |
| 13 | + contents: write |
| 14 | + packages: write |
| 15 | + |
| 16 | +concurrency: |
| 17 | + group: force-firmware-build-${{ vars.FIRMWARE_VERSION }}-${{ vars.RELEASE_VERSION }} |
| 18 | + cancel-in-progress: false |
| 19 | + |
| 20 | +jobs: |
| 21 | + build-and-upload: |
| 22 | + runs-on: ["ubuntu-latest"] |
| 23 | + env: |
| 24 | + FAP_INCLUDED_IN_FW: 0 |
| 25 | + REPO_SELF: ${{ vars.REPO_SELF }} |
| 26 | + OFW_PATH: "applications_user/${{ vars.FAP_NAME }}" |
| 27 | + RELATIVE_PATH: "applications/external/${{ vars.FAP_NAME }}" |
| 28 | + CURRENT_VERSION: ${{ vars.RELEASE_VERSION }} |
| 29 | + RELEASE_VERSION: ${{ inputs.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 | +
|
| 57 | + - name: Copy Firmware Files |
| 58 | + uses: actions/checkout@v3 |
| 59 | + with: |
| 60 | + repository: "${{ matrix.url }}" |
| 61 | + clean: "true" |
| 62 | + submodules: "true" |
| 63 | + ref: "dev" |
| 64 | + |
| 65 | + - name: Copy Repo Files |
| 66 | + if: ${{ matrix.src-included == 0 }} |
| 67 | + uses: actions/checkout@v3 |
| 68 | + with: |
| 69 | + repository: "${{ vars.REPO_SELF }}" |
| 70 | + clean: "true" |
| 71 | + submodules: "true" |
| 72 | + path: "${{ env.OFW_PATH }}" |
| 73 | + |
| 74 | + - name: Print vars about state or repo if Unleashed |
| 75 | + if: ${{ matrix.src-included == 1 }} |
| 76 | + shell: pwsh |
| 77 | + run: | |
| 78 | + git log --pretty=format:'%s by %C(yellow)%an%Creset (%ad)%n %n%b' --date=local --abbrev-commit --max-count=1 |
| 79 | + if( ${{ env.FAP_INCLUDED_IN_FW }} -eq 1 ) { |
| 80 | + git submodule set-branch --branch master '${{ env.RELATIVE_PATH }}' |
| 81 | + git submodule sync '${{ env.RELATIVE_PATH }}' |
| 82 | + } |
| 83 | + cd '${{ env.OFW_PATH }}' |
| 84 | + $Output = (git log --pretty=format:'%s by %C(yellow)%an%Creset (%ad)%n %n%b' --date=local --abbrev-commit --max-count=1) |
| 85 | +
|
| 86 | + if ( $LASTEXITCODE -ne 0 ) { |
| 87 | + Write-Error '::error title=Invalid checkout::Invalid checkout' |
| 88 | + exit 1 |
| 89 | + } |
| 90 | + Write-Output ('::notice title=Git output::{0}' -f $Output) |
| 91 | +
|
| 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 | +
|
| 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 | + } 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 | + Write-Output ('::notice title=Git output::{0}' -f $Output) |
| 104 | + } |
| 105 | +
|
| 106 | + - name: Remove other apps |
| 107 | + shell: pwsh |
| 108 | + if: ${{ success() }} |
| 109 | + # rm to remove problem FAP which includes non-existent files |
| 110 | + run: | |
| 111 | + Remove-Item -Force -Recurse ./applications/debug -ErrorAction SilentlyContinue |
| 112 | + Remove-Item -Force -Recurse ./applications/examples -ErrorAction SilentlyContinue |
| 113 | +
|
| 114 | + - name: Build Firmware |
| 115 | + shell: bash |
| 116 | + if: ${{ success() }} |
| 117 | + env: |
| 118 | + FBT_NO_SYNC: 0 |
| 119 | + DIST_SUFFIX: ${{ matrix.version }} |
| 120 | + WORKFLOW_BRANCH_OR_TAG: release-cfw |
| 121 | + run: | |
| 122 | + ./fbt COMPACT=1 DEBUG=0 FBT_NO_SYNC=0 |
| 123 | +
|
| 124 | + - name: Build FAPs |
| 125 | + shell: bash |
| 126 | + if: ${{ success() }} |
| 127 | + env: |
| 128 | + FBT_NO_SYNC: 0 |
| 129 | + DIST_SUFFIX: ${{ matrix.version }} |
| 130 | + WORKFLOW_BRANCH_OR_TAG: release-cfw |
| 131 | + # rm to remove problem FAP which includes non-existent files |
| 132 | + run: | |
| 133 | + ./fbt COMPACT=1 DEBUG=0 FBT_NO_SYNC=0 fap_dist |
| 134 | +
|
| 135 | + - name: Create assets |
| 136 | + if: ${{ success() }} |
| 137 | + shell: pwsh |
| 138 | + env: |
| 139 | + ZIP_NAME: "${{ vars.FAP_NAME }}_${{ env.RELEASE_VERSION }}_${{ matrix.firmware }}.zip" |
| 140 | + TGZ_NAME: "${{ vars.FAP_NAME }}_${{ env.RELEASE_VERSION }}_${{ matrix.firmware }}.tgz" |
| 141 | + run: | |
| 142 | + function Format-Bytes { |
| 143 | + param( |
| 144 | + [int]$number |
| 145 | + ) |
| 146 | + $sizes = 'KB', 'MB', 'GB', 'TB', 'PB' |
| 147 | + for ($x = 0; $x -lt $sizes.count; $x++) { |
| 148 | + if ($number -lt [int64]"1$($sizes[$x])") { |
| 149 | + if ($x -eq 0) { |
| 150 | + return "$number B" |
| 151 | + } |
| 152 | + else { |
| 153 | + $num = $number / [int64]"1$($sizes[$x-1])" |
| 154 | + $num = "{0:N2}" -f $num |
| 155 | + return "$num $($sizes[$x-1])" |
| 156 | + } |
| 157 | + } |
| 158 | + } |
| 159 | + } |
| 160 | + $ZipName = $env:ZIP_NAME |
| 161 | + $TgzName = $env:TGZ_NAME |
| 162 | + $FapNamme = '${{ vars.FAP_NAME }}.fap' |
| 163 | + $DstFap = "./$FapNamme" |
| 164 | + $AppDir = "dist/f7-C/apps/Sub-GHz" |
| 165 | +
|
| 166 | + if (!(Test-Path -Path "$AppDir/$FapNamme" -PathType Leaf)) { |
| 167 | + Write-Error '::error title=Files not found::Cannot find files in location' |
| 168 | + exit 1 |
| 169 | + } |
| 170 | +
|
| 171 | + $Size = (Get-Item -Path "$AppDir/$FapNamme" | Get-ItemPropertyValue -Name Length) |
| 172 | + Write-Output ('Filesize: {0}' -f (Format-Bytes $Size)) |
| 173 | + Copy-Item -Force -Verbose -Path "$AppDir/$FapNamme" -Destination $DstFap |
| 174 | +
|
| 175 | + zip -r -qq $ZipName $DstFap |
| 176 | + tar zcf $TgzName $DstFap |
| 177 | +
|
| 178 | + if ( !(Test-Path -Path $ZipName -PathType Leaf) -or !(Test-Path -Path $TgzName -PathType Leaf) ) { |
| 179 | + Write-Error '::error title=Files not found::Cannot find files in location' |
| 180 | + exit 1 |
| 181 | + } |
| 182 | +
|
| 183 | + $ZipSize = Format-Bytes (Get-Item -Path $ZipName).Length |
| 184 | + $TgzSize = Format-Bytes (Get-Item -Path $TgzName ).Length |
| 185 | +
|
| 186 | + Write-Output ('ZIP_NAME={0}' -f $ZipName) >> $env:GITHUB_ENV |
| 187 | + Write-Output ('TGZ_NAME={0}' -f $TgzName ) >> $env:GITHUB_ENV |
| 188 | + Write-Output ('ZIP_TAG={0} ({1})' -f $ZipName, $ZipSize) >> $env:GITHUB_ENV |
| 189 | + Write-Output ('TGZ_TAG={0} ({1})' -f $TgzName , $TgzSize) >> $env:GITHUB_ENV |
| 190 | +
|
| 191 | + - name: Upload assets |
| 192 | + if: ${{ success() && env.ZIP_NAME != '' }} |
| 193 | + env: |
| 194 | + GITHUB_TOKEN: ${{ secrets.FLIPPER_TOKEN }} |
| 195 | + run: | |
| 196 | + gh release create v${{ env.RELEASE_VERSION }} --generate-notes --draft -R ${{ env.REPO_SELF }} |
| 197 | + gh release upload 'v${{ env.RELEASE_VERSION }}' '${{ env.ZIP_NAME }}#${{ env.ZIP_TAG }}' \ |
| 198 | + '${{ env.TGZ_NAME }}#${{ env.TGZ_TAG }}' --clobber -R ${{ env.REPO_SELF }} |
| 199 | + gh release edit 'v${{ env.RELEASE_VERSION }}' --draft=false -R ${{ env.REPO_SELF }} |
| 200 | +
|
| 201 | +#EOF |
0 commit comments