From e0bd2983bd08f0e3736a6810030e2b27f4e3bb5f Mon Sep 17 00:00:00 2001 From: DerSkythe Date: Tue, 19 Dec 2023 08:01:36 +0400 Subject: [PATCH 1/2] refactor: Refactor build workflow and simplify naming scheme The build workflow definition has been refactored to simplify the scheme of naming files. This change includes the introduction of an APP_NAME environment variable to reduce duplication in naming related variables like ZIP_NAME and TGZ_NAME. Moreover, some redundant usage of string interpolation in repository names have been eliminated for clarity. --- .github/workflows/build-with-firmwware.yml | 31 ++++++++++++---------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build-with-firmwware.yml b/.github/workflows/build-with-firmwware.yml index e26169e1b24..ba3e2e307a4 100644 --- a/.github/workflows/build-with-firmwware.yml +++ b/.github/workflows/build-with-firmwware.yml @@ -31,6 +31,7 @@ jobs: RELATIVE_PATH: "applications/external/subbrute" CURRENT_VERSION: ${{ vars.RELEASE_VERSION }} RELEASE_VERSION: ${{ vars.RELEASE_VERSION }} + APP_NAME: "" ZIP_NAME: "" ZIP_TAG: "" TGZ_NAME: "" @@ -64,7 +65,7 @@ jobs: - name: Copy Firmware Files uses: actions/checkout@v3 with: - repository: "${{ matrix.url }}" + repository: ${{ matrix.url }} clean: "true" submodules: "true" ref: "dev" @@ -73,7 +74,7 @@ jobs: if: ${{ matrix.src-included == 0 }} uses: actions/checkout@v3 with: - repository: "${{ vars.REPO_SELF }}" + repository: ${{ vars.REPO_SELF }} clean: "true" submodules: "true" path: "${{ env.OFW_PATH }}" @@ -191,8 +192,7 @@ jobs: if: ${{ success() }} shell: pwsh env: - ZIP_NAME: "subghz_bruteforcer_${{ env.RELEASE_VERSION }}_${{ matrix.firmware }}.zip" - TGZ_NAME: "subghz_bruteforcer_${{ env.RELEASE_VERSION }}_${{ matrix.firmware }}.tgz" + APP_NAME: "subghz_bruteforcer_${{ env.RELEASE_VERSION }}_${{ matrix.firmware }}" run: | function Format-Bytes { param( @@ -212,20 +212,20 @@ jobs: } } } - $ZipName = $env:ZIP_NAME - $TgzName = $env:TGZ_NAME - $FapNamme = 'subghz_bruteforcer.fap' - $DstFap = "./$FapNamme" + $ZipName = ('{0}.zip' -f $env:APP_NAME) + $TgzName = ('{0}.tgz' -f $env:APP_NAME) + $FapName = 'subghz_bruteforcer.fap' + $DstFap = "./$FapName" $AppDir = "dist/f7-C/apps/Sub-GHz" - if (!(Test-Path -Path "$AppDir/$FapNamme" -PathType Leaf)) { + if (!(Test-Path -Path "$AppDir/$FapName" -PathType Leaf)) { Write-Error '::error title=Files not found::Cannot find files in location' exit 1 } - $Size = (Get-Item -Path "$AppDir/$FapNamme" | Get-ItemPropertyValue -Name Length) + $Size = (Get-Item -Path "$AppDir/$FapName" | Get-ItemPropertyValue -Name Length) Write-Output ('Filesize: {0}' -f (Format-Bytes $Size)) - Copy-Item -Force -Verbose -Path "$AppDir/$FapNamme" -Destination $DstFap + Copy-Item -Force -Verbose -Path "$AppDir/$FapName" -Destination $DstFap zip -r -qq $ZipName $DstFap tar zcf $TgzName $DstFap @@ -245,12 +245,15 @@ jobs: - name: Upload assets if: ${{ success() && env.ZIP_NAME != '' }} + shell: pwsh env: GITHUB_TOKEN: ${{ secrets.FLIPPER_TOKEN }} run: | - gh release create v${{ env.RELEASE_VERSION }} --generate-notes --draft -R ${{ env.REPO_SELF }} - gh release upload 'v${{ env.RELEASE_VERSION }}' '${{ env.ZIP_NAME }}#${{ env.ZIP_TAG }}' \ - '${{ env.TGZ_NAME }}#${{ env.TGZ_TAG }}' --clobber -R ${{ env.REPO_SELF }} + $Url = (gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/${{ github.REPOSITORY }}/releases/tags/${{ env.RELEASE_VERSION }}) | ConvertFrom-Json -AsHashtable + if ( [string]::IsNullOrWhitespace($Url) ) { + gh release create v${{ env.RELEASE_VERSION }} --generate-notes --draft -R ${{ env.REPO_SELF }} + } + gh release upload 'v${{ env.RELEASE_VERSION }}' '${{ env.ZIP_NAME }}#${{ env.ZIP_TAG }}' '${{ env.TGZ_NAME }}#${{ env.TGZ_TAG }}' --clobber -R ${{ env.REPO_SELF }} gh release edit 'v${{ env.RELEASE_VERSION }}' --draft=false -R ${{ env.REPO_SELF }} #EOF From 84c94c3c612b70d9e588457cc890d309ceb7ced7 Mon Sep 17 00:00:00 2001 From: DerSkythe Date: Tue, 19 Dec 2023 08:20:18 +0400 Subject: [PATCH 2/2] refactor: Refactor variable naming in build workflow Variables within the build workflow have been re-named to use a more consistent and simplified naming scheme, improving readability and maintainability. Some redundant code related to file directory operations has also been removed to streamline the process. --- .github/workflows/build-with-firmwware.yml | 67 ++++++++++------------ 1 file changed, 31 insertions(+), 36 deletions(-) diff --git a/.github/workflows/build-with-firmwware.yml b/.github/workflows/build-with-firmwware.yml index ba3e2e307a4..1e1f488fc75 100644 --- a/.github/workflows/build-with-firmwware.yml +++ b/.github/workflows/build-with-firmwware.yml @@ -56,11 +56,11 @@ jobs: CURRENT_VERSION: ${{ env.CURRENT_VERSION }} shell: pwsh run: | - $ReleaseVersion = ([string]::IsNullOrWhitespace($env:INPUT_VERSION) ? $env:CURRENT_VERSION : $env:INPUT_VERSION) - if ( $ReleaseVersion.StartsWith('v') ) { - $ReleaseVersion = $ReleaseVersion.Substring(1) + $releaseVersion = ([string]::IsNullOrWhitespace($env:INPUT_VERSION) ? $env:CURRENT_VERSION : $env:INPUT_VERSION) + if ( $releaseVersion.StartsWith('v') ) { + $releaseVersion = $releaseVersion.Substring(1) } - Write-Output ('RELEASE_VERSION={0}' -f $ReleaseVersion) >> $env:GITHUB_ENV + Write-Output ('RELEASE_VERSION={0}' -f $releaseVersion) >> $env:GITHUB_ENV - name: Copy Firmware Files uses: actions/checkout@v3 @@ -98,13 +98,13 @@ jobs: } } - $Output = (git log --pretty=format:'%s by %C(yellow)%an%Creset (%ad)%n %n%b' --date=local --abbrev-commit --max-count=1) + $output = (git log --pretty=format:'%s by %C(yellow)%an%Creset (%ad)%n %n%b' --date=local --abbrev-commit --max-count=1) if ( $LASTEXITCODE -ne 0 ) { Write-Error '::error title=Invalid checkout::Invalid checkout' exit 1 } - Write-Output ('::notice title=Git output::{0}' -f $Output) + Write-Output ('::notice title=Git output::{0}' -f $output) - name: Print vars about state or repo if Official if: ${{ matrix.src-included == 0 }} @@ -123,13 +123,13 @@ jobs: exit 1 } } else { - $Output = (git log --pretty=format:'%s by %C(yellow)%an%Creset (%ad)%n %n%b' --date=local --abbrev-commit --max-count=1) + $output = (git log --pretty=format:'%s by %C(yellow)%an%Creset (%ad)%n %n%b' --date=local --abbrev-commit --max-count=1) if ( $LASTEXITCODE -ne 0 ) { Write-Error '::error title=Invalid checkout::Invalid checkout' exit 1 } - Write-Output ('::notice title=Git output::{0}' -f $Output) + Write-Output ('::notice title=Git output::{0}' -f $output) } # - name: Restore FBT @@ -150,11 +150,6 @@ jobs: run: | Remove-Item -Force -Recurse ./applications/debug -ErrorAction SilentlyContinue Remove-Item -Force -Recurse ./applications/examples -ErrorAction SilentlyContinue - # New-Item -Force ./tmp -ItemType Directory -ErrorAction SilentlyContinue - # Copy-Item -Force -Recurse ./applications/external/subbrute/ ./tmp/ -ErrorAction SilentlyContinue - # Remove-Item -Force -Recurse ./applications/external/* -ErrorAction SilentlyContinue - # Copy-Item -Force -Recurse /tmp/* ./applications/external/ -ErrorAction SilentlyContinue - # Remove-Item -Force -Recurse ./tmp -ErrorAction SilentlyContinue - name: Build Firmware shell: bash @@ -205,43 +200,43 @@ jobs: return "$number B" } else { - $num = $number / [int64]"1$($sizes[$x-1])" - $num = "{0:N2}" -f $num - return "$num $($sizes[$x-1])" + $formattedNumber = $number / [int64]"1$($sizes[$x-1])" + $formattedNumber = "{0:N2}" -f $formattedNumber + return "$formattedNumber $($sizes[$x-1])" } } } } - $ZipName = ('{0}.zip' -f $env:APP_NAME) - $TgzName = ('{0}.tgz' -f $env:APP_NAME) - $FapName = 'subghz_bruteforcer.fap' - $DstFap = "./$FapName" - $AppDir = "dist/f7-C/apps/Sub-GHz" + $zipName = ('{0}.zip' -f $env:APP_NAME) + $tgzName = ('{0}.tgz' -f $env:APP_NAME) + $fapName = 'subghz_bruteforcer.fap' + $dstFap = "./$fapName" + $appDir = "dist/f7-C/apps/Sub-GHz" - if (!(Test-Path -Path "$AppDir/$FapName" -PathType Leaf)) { + if (!(Test-Path -Path "$appDir/$fapName" -PathType Leaf)) { Write-Error '::error title=Files not found::Cannot find files in location' exit 1 } - $Size = (Get-Item -Path "$AppDir/$FapName" | Get-ItemPropertyValue -Name Length) - Write-Output ('Filesize: {0}' -f (Format-Bytes $Size)) - Copy-Item -Force -Verbose -Path "$AppDir/$FapName" -Destination $DstFap + $size = (Get-Item -Path "$appDir/$fapName" | Get-ItemPropertyValue -Name Length) + Write-Output ('Filesize: {0}' -f (Format-Bytes $size)) + Copy-Item -Force -Verbose -Path "$appDir/$fapName" -Destination $dstFap - zip -r -qq $ZipName $DstFap - tar zcf $TgzName $DstFap + zip -r -qq $zipName $dstFap + tar zcf $tgzName $dstFap - if ( !(Test-Path -Path $ZipName -PathType Leaf) -or !(Test-Path -Path $TgzName -PathType Leaf) ) { + if ( !(Test-Path -Path $zipName -PathType Leaf) -or !(Test-Path -Path $tgzName -PathType Leaf) ) { Write-Error '::error title=Files not found::Cannot find files in location' exit 1 } - $ZipSize = Format-Bytes (Get-Item -Path $ZipName).Length - $TgzSize = Format-Bytes (Get-Item -Path $TgzName ).Length + $zipSize = Format-Bytes (Get-Item -Path $zipName).Length + $tgzSize = Format-Bytes (Get-Item -Path $tgzName ).Length - Write-Output ('ZIP_NAME={0}' -f $ZipName) >> $env:GITHUB_ENV - Write-Output ('TGZ_NAME={0}' -f $TgzName ) >> $env:GITHUB_ENV - Write-Output ('ZIP_TAG={0} ({1})' -f $ZipName, $ZipSize) >> $env:GITHUB_ENV - Write-Output ('TGZ_TAG={0} ({1})' -f $TgzName , $TgzSize) >> $env:GITHUB_ENV + Write-Output ('ZIP_NAME={0}' -f $zipName) >> $env:GITHUB_ENV + Write-Output ('TGZ_NAME={0}' -f $tgzName ) >> $env:GITHUB_ENV + Write-Output ('ZIP_TAG={0} ({1})' -f $zipName, $zipSize) >> $env:GITHUB_ENV + Write-Output ('TGZ_TAG={0} ({1})' -f $tgzName , $tgzSize) >> $env:GITHUB_ENV - name: Upload assets if: ${{ success() && env.ZIP_NAME != '' }} @@ -249,8 +244,8 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.FLIPPER_TOKEN }} run: | - $Url = (gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/${{ github.REPOSITORY }}/releases/tags/${{ env.RELEASE_VERSION }}) | ConvertFrom-Json -AsHashtable - if ( [string]::IsNullOrWhitespace($Url) ) { + $url = (gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/${{ github.REPOSITORY }}/releases/tags/${{ env.RELEASE_VERSION }}) | ConvertFrom-Json -AsHashtable + if ( [string]::IsNullOrWhitespace($url) ) { gh release create v${{ env.RELEASE_VERSION }} --generate-notes --draft -R ${{ env.REPO_SELF }} } gh release upload 'v${{ env.RELEASE_VERSION }}' '${{ env.ZIP_NAME }}#${{ env.ZIP_TAG }}' '${{ env.TGZ_NAME }}#${{ env.TGZ_TAG }}' --clobber -R ${{ env.REPO_SELF }}