瀏覽代碼

feat: Refactor error handling and release creation in workflow

Refined the error handling in the Github Actions workflow to display a warning message instead of terminating the process unexpectedly. Additionally, improved the API call to create a release in Github. It now checks for a name attribute in the returned URL, hence ensuring that the release creation call is performed properly even if no previous release with the same version exists.
DerSkythe 2 年之前
父節點
當前提交
8763f248c0
共有 1 個文件被更改,包括 14 次插入12 次删除
  1. 14 12
      .github/workflows/build-with-firmwware.yml

+ 14 - 12
.github/workflows/build-with-firmwware.yml

@@ -93,18 +93,18 @@ jobs:
             git checkout tags/v${{ env.RELEASE_VERSION }} -b tmp-build
             git checkout tags/v${{ env.RELEASE_VERSION }} -b tmp-build
             
             
             if ( $LASTEXITCODE -ne 0 ) {
             if ( $LASTEXITCODE -ne 0 ) {
-              Write-Error '::error title=Cannot checkout to this version::Error during execution checkout to this tag ${{ env.RELEASE_VERSION }}'
-              exit 1
+              Write-Error '::warning title=Cannot checkout to this version::Error during execution checkout to this tag ${{ env.RELEASE_VERSION }}'
+              #exit 1
             }
             }
-          }
-
-          $output = (git log --pretty=format:'%s by %C(yellow)%an%Creset (%ad)%n %n%b' --date=local --abbrev-commit --max-count=1)
+          } else {
+            $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
+            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
       - name: Print vars about state or repo if Official
         if: ${{ matrix.src-included == 0 }}
         if: ${{ matrix.src-included == 0 }}
@@ -119,8 +119,8 @@ jobs:
             git checkout tags/v${{ env.RELEASE_VERSION }} -b tmp-build
             git checkout tags/v${{ env.RELEASE_VERSION }} -b tmp-build
 
 
             if ( $LASTEXITCODE -ne 0 ) {
             if ( $LASTEXITCODE -ne 0 ) {
-              Write-Error '::error title=Cannot checkout to this version::Error during execution checkout to this tag ${{ env.RELEASE_VERSION }}'
-              exit 1
+              Write-Error '::warning title=Cannot checkout to this version::Error during execution checkout to this tag ${{ env.RELEASE_VERSION }}'
+              #exit 1
             }
             }
           } else {
           } 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)
@@ -246,7 +246,9 @@ jobs:
         run: |
         run: |
           $url = (gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/${{ github.REPOSITORY }}/releases/tags/v${{ env.RELEASE_VERSION }}) | ConvertFrom-Json -AsHashtable
           $url = (gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/${{ github.REPOSITORY }}/releases/tags/v${{ env.RELEASE_VERSION }}) | ConvertFrom-Json -AsHashtable
           if ( [string]::IsNullOrWhitespace($url.name) ) {
           if ( [string]::IsNullOrWhitespace($url.name) ) {
-            gh release create v${{ env.RELEASE_VERSION }} --generate-notes --draft -R ${{ env.REPO_SELF }}  
+            $sha = (git rev-parse --verify HEAD)
+            gh api --method POST -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/${{ github.REPOSITORY }}/releases -f tag_name='v${{ env.RELEASE_VERSION }}' -f target_commitish="$sha" -f name='v${{ env.RELEASE_VERSION }}' -F draft=true -F prerelease=false -F generate_release_notes=true
+            #gh release create v${{ env.RELEASE_VERSION }} --generate-notes -f target_commitish='master' --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 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 }}
           gh release edit 'v${{ env.RELEASE_VERSION }}' --draft=false -R ${{ env.REPO_SELF }}