Skip to content

Update after signature script #78

Update after signature script

Update after signature script #78

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: 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)"
- 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 "-----------> 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}}
replace: true
files: >
stage/latest.yml
# - name: Upload Binaries to Release
# uses: svenstaro/upload-release-action@v2
# with:
# repo_token: ${{ secrets.GITHUB_TOKEN }}
# file: latest.yml
# tag: ${{steps.find_draft.outputs.draft_tag}}
# release_name: ${{steps.find_draft.outputs.draft_tag_name}}
# draft: true
# overwrite: true
# - name: Upload updated latest.yml to Draft Release
# uses: softprops/action-gh-release@v2
# with:
# # draft: true
# # name: ${{steps.find_draft.outputs.draft_tag_name}}
# files: latest.yml
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # GitHub token for authentication
# 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 }}/assets" -Headers @{ Authorization = "Bearer $env:GITHUB_TOKEN" }
# $yml_asset = $release_info | Where-Object { $_.name -eq "latest.yml" } | Select-Object -First 1
# if (-not $yml_asset) { throw "The latest.yml asset was not found in the draft release." }
# $upload_url = $yml_asset.url
# # Upload the updated latest.yml using curl
# Invoke-Expression -Command "curl -X POST -H 'Authorization: Bearer $env:GITHUB_TOKEN' -H 'Content-Type: application/octet-stream' --data-binary @latest.yml $upload_url"