diff --git a/.github/workflows/after-signature.yml b/.github/workflows/after-signature.yml index d5011e1..b43c55b 100644 --- a/.github/workflows/after-signature.yml +++ b/.github/workflows/after-signature.yml @@ -1,12 +1,14 @@ name: Update latest.yml with SHA512 Hash on: - workflow_dispatch: + push: + # workflow_dispatch: jobs: update-latest-yml: permissions: contents: write # to get the draft versions + actions: write runs-on: windows-latest steps: @@ -31,28 +33,46 @@ jobs: echo "Draft release ID: $($draft_release.id)" echo "Draft release name: $($draft_release.name)" - echo "::set-output name=draft_release_id::$($draft_release.id)" - echo "::set-output name=draft_tag_name::$($draft_release.name)" + # echo "::set-output name=draft_release_id::$($draft_release.id)" + echo "{draft_release_id}={draft_release.id}" >> $GITHUB_OUTPUT - - name: Download Release Assets - env: - GITHUB_TOKEN: ${{ secrets.github_token }} - run: | - # Utiliser les sorties d'étape au lieu des variables d'environnement - echo "Draft release ID: ${{ steps.find_draft.outputs.draft_release_id }}" - echo "Draft tag name: ${{ steps.find_draft.outputs.draft_tag_name }}" + # echo "::set-output name=draft_tag_name::$($draft_release.name)" + echo "{draft_tag_name}={draft_release}.name" >> $GITHUB_OUTPUT - $release_info = Invoke-RestMethod -Uri "https://api.github.com/repos/KhiopsML/kv-electron/releases/${{ steps.find_draft.outputs.draft_release_id }}/assets" -Headers @{ Authorization = "Bearer $env:GITHUB_TOKEN" } - $exe_asset = $release_info | Where-Object { $_.name -match "khiops-visualization-Setup-.*\.exe" } - $yml_asset = $release_info | Where-Object { $_.name -eq "latest.yml" } + # echo "::set-output name=draft_tag::$($draft_release.tag_name)" + echo "{draft_tag}={draft_release.tag_name}" >> $GITHUB_OUTPUT - # Check if required assets exist - if (-not $exe_asset) { throw "The .exe asset was not found in the draft release." } - if (-not $yml_asset) { throw "The latest.yml asset was not found in the draft release." } + - name: Download Release Assets + uses: robinraju/release-downloader@v1.11 + with: + token: ${{ secrets.github_token }} + releaseId: ${{ steps.find_draft.outputs.draft_release_id }} + preRelease: true + fileName: "latest.yml" + + - name: Download Release Assets + uses: robinraju/release-downloader@v1.11 + with: + token: ${{ secrets.github_token }} + releaseId: ${{ steps.find_draft.outputs.draft_release_id }} + preRelease: true + fileName: "*.exe" + + - name: Verify latest.yml + shell: pwsh + run: | + if (Test-Path -Path latest.yml) { + Write-Output "latest.yml exists." + } else { + throw "latest.yml does not exist after download." + } - # Download assets - Invoke-WebRequest -Uri $exe_asset.browser_download_url -OutFile "khiops-visualization-Setup-$($release_info.tag_name).exe" - Invoke-WebRequest -Uri $yml_asset.browser_download_url -OutFile "latest.yml" + - name: Display latest content + shell: pwsh + run: | + $ct = Get-Content -Path latest.yml -Raw + Write-Output "Content of latest.yml:" + Write-Output "$ct" - name: Compute SHA512 Hash id: compute_hash @@ -63,6 +83,7 @@ jobs: $hash = Get-FileHash -Algorithm SHA512 -Path $exePath $lowercaseHash = $hash.Hash.ToLower() Write-Output "::set-output name=sha512::$lowercaseHash" + echo "-----------> lowercaseHash: $lowercaseHash" - name: Update latest.yml shell: pwsh @@ -72,26 +93,24 @@ jobs: ForEach-Object { if ($_ -match '^sha512:\s.*$') { "sha512: ${{ steps.compute_hash.outputs.sha512 }}" - } elseif ($_ -notmatch '^size:\s.*$') { + } elseif ($_ -match '^\s*sha512:\s.*$') { + " sha512: ${{ steps.compute_hash.outputs.sha512 }}" + } elseif ($_ -notmatch '^\s*size:\s.*$') { $_ } } | Set-Content -Path latest.yml - - name: Upload updated latest.yml to Draft Release - env: - RELEASE_ID: ${{ steps.find_draft.outputs.draft_release_id }} - GITHUB_TOKEN: ${{ secrets.github_token }} - run: | - # Get release info and find latest.yml asset - $release_info = Invoke-RestMethod -Uri "https://api.github.com/repos/KhiopsML/kv-electron/releases/$env:RELEASE_ID" -Headers @{ Authorization = "Bearer $env:GITHUB_TOKEN" } - $yml_asset = $release_info.assets | Where-Object { $_.name -eq "latest.yml" } - - # Update latest.yml asset with modified content - if ($yml_asset) { - Invoke-RestMethod -Uri "https://api.github.com/repos/KhiopsML/kv-electron/releases/assets/$($yml_asset.id)" ` - -Method PATCH ` - -Headers @{ Authorization = "Bearer $env:GITHUB_TOKEN"; "Content-Type" = "application/octet-stream" } ` - -InFile "latest.yml" - } else { - throw "Failed to find latest.yml asset in the draft release." - } + $ct = Get-Content -Path latest.yml -Raw + echo "Updated latest.yml content:" + echo "-----------------------------" + echo "$ct" + echo "-----------------------------" + + - uses: IsaacShelton/update-existing-release@v1.3.4 + with: + token: ${{secrets.GITHUB_TOKEN}} + release: ${{steps.find_draft.outputs.draft_tag_name}} + tag: ${{steps.find_draft.outputs.draft_tag}} + draft: true + files: > + latest.yml