-
Notifications
You must be signed in to change notification settings - Fork 0
135 lines (114 loc) · 4.96 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
134
135
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 "-----------------------------"
- 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}}
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"