-
Notifications
You must be signed in to change notification settings - Fork 0
133 lines (113 loc) · 4.82 KB
/
after-signature.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
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