Преглед изворни кода

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.
DerSkythe пре 2 година
родитељ
комит
e0bd2983bd
1 измењених фајлова са 17 додато и 14 уклоњено
  1. 17 14
      .github/workflows/build-with-firmwware.yml

+ 17 - 14
.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