Skip to content

Update latest.yml with SHA512 Hash #98

Update latest.yml with SHA512 Hash

Update latest.yml with SHA512 Hash #98

name: Update latest.yml with SHA512 Hash
on:
# push:
workflow_dispatch:
jobs:
update-latest-yml:
permissions:
contents: write # to get the draft versions
actions: write
runs-on: windows-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Debug GITHUB_OUTPUT
shell: pwsh
run: |
Write-Output "GITHUB_OUTPUT: $env:GITHUB_OUTPUT"
- name: Find Latest Draft Release
id: find_draft
env:
GITHUB_TOKEN: ${{ secrets.github_token }}
run: |
# Retrieve releases
$releases = Invoke-RestMethod -Uri "https://api.github.com/repos/KhiopsML/kv-electron/releases" -Headers @{ Authorization = "Bearer $env:GITHUB_TOKEN" }
# Select the latest draft release
$draft_release = $releases | Where-Object { $_.draft -eq $true } | Sort-Object -Property created_at -Descending | Select-Object -First 1
if (-not $draft_release) {
throw "No draft release found."
}
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_tag::$($draft_release.tag_name)"
# Write outputs
# echo "draft_release_id=$($draft_release.id)" >> $GITHUB_OUTPUT
# echo "draft_tag_name=$($draft_release.name)" >> $GITHUB_OUTPUT
# echo "draft_tag=$($draft_release.tag_name)" >> $GITHUB_OUTPUT
echo "draft_release_id=$($draft_release.id)" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
echo "draft_tag_name=$($draft_release.name)" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
echo "draft_tag=$($draft_release.tag_name)" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
- name: Debug Outputs
run: |
echo "Draft Release ID: ${{ steps.find_draft.outputs.draft_release_id }}"
echo "Draft Tag Name: ${{ steps.find_draft.outputs.draft_tag_name }}"
echo "Draft Tag: ${{ steps.find_draft.outputs.draft_tag }}"
- name: Download Release Assets
uses: robinraju/[email protected]
with:
token: ${{ secrets.github_token }}
releaseId: ${{ steps.find_draft.outputs.draft_release_id }}
preRelease: true
fileName: "latest.yml"
- name: Download Release Assets
uses: robinraju/[email protected]
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."
}
- 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
shell: pwsh
run: |
# Calculate SHA512 hash of the .exe file
$exePath = "khiops-visualization-Setup-${{ steps.find_draft.outputs.draft_tag_name }}.exe"
$hash = Get-FileHash -Algorithm SHA512 -Path $exePath
$lowercaseHash = $hash.Hash.ToLower()
# Write-Output "::set-output name=sha512::$lowercaseHash"
echo "sha512=$lowercaseHash" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
echo "-----------> lowercaseHash: $lowercaseHash"
- name: Update latest.yml
shell: pwsh
run: |
# Update sha512 hash and remove size attribute in latest.yml
(Get-Content -Path latest.yml) |
ForEach-Object {
if ($_ -match '^sha512:\s.*$') {
"sha512: ${{ steps.compute_hash.outputs.sha512 }}"
} elseif ($_ -match '^\s*sha512:\s.*$') {
" sha512: ${{ steps.compute_hash.outputs.sha512 }}"
} elseif ($_ -notmatch '^\s*size:\s.*$') {
$_
}
} | Set-Content -Path latest.yml
$ct = Get-Content -Path latest.yml -Raw
echo "Updated latest.yml content:"
echo "-----------------------------"
echo "$ct"
echo "-----------------------------"
- uses: IsaacShelton/[email protected]
with:
token: ${{secrets.GITHUB_TOKEN}}
release: ${{steps.find_draft.outputs.draft_tag_name}}
tag: ${{steps.find_draft.outputs.draft_tag}}
draft: true
body: ""
files: >
latest.yml