-
Notifications
You must be signed in to change notification settings - Fork 2
279 lines (240 loc) · 9.68 KB
/
build-vtk.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
name: build-vtk
on:
push:
branches:
- main
paths:
- .github/workflows/build-vtk.yml
- misc/CMakePresets.json
env:
VTK_VERSION: 6.3.0
jobs:
cache-vtk-debug:
# uncomment the next line if you want to compile vtk
if: github.repository == 'MODFLOW-USGS/modelviewer-mf6'
runs-on: windows-2016
steps:
- uses: actions/checkout@v2
- name: Export env
env:
type: debug
zipfile: v${{env.VTK_VERSION}}.zip
instdir: C:/VTK-${{env.VTK_VERSION}}-vs2017-x64
builddir: C:/VTK-${{env.VTK_VERSION}}-vs2017-x64-build
srcdir: C:/VTK-${{env.VTK_VERSION}}
shell: pwsh
run: |
echo "type=$env:type" >> $env:GITHUB_ENV
echo "zipfile=$env:zipfile" >> $env:GITHUB_ENV
echo "instdir=$env:instdir" >> $env:GITHUB_ENV
echo "builddir=$env:builddir" >> $env:GITHUB_ENV
echo "srcdir=$env:srcdir" >> $env:GITHUB_ENV
- name: Cache vtk
id: cache-vtk-debug
uses: actions/cache@v2
with:
path: ${{env.instdir}}
key: windows-2016-vtk-${{env.type}}-${{hashFiles('misc/CMakePresets.json')}}
- name: Download vtk
if: steps.cache-vtk-debug.outputs.cache-hit != 'true'
shell: pwsh
run: |
curl -L -O "https://github.com/Kitware/VTK/archive/refs/tags/${{env.zipfile}}"
Get-FileHash ${{env.zipfile}}
cd C:\
7z x ${{github.workspace}}\${{env.zipfile}}
rm ${{github.workspace}}\${{env.zipfile}}
- name: Build vtk
if: steps.cache-vtk-debug.outputs.cache-hit != 'true'
shell: pwsh
run: |
cp misc\CMakePresets.json ${{env.srcdir}}
cd ${{env.srcdir}}
cmake --preset vs2017
cmake --build --preset vs2017 --config ${{env.type}}
cmake --install ${{env.builddir}} --prefix ${{env.instdir}} --config ${{env.type}}
- name: Check debug cache
shell: pwsh
run: |
dir ${{env.instdir}}\bin
cache-vtk-release:
# uncomment the next line if you want to compile vtk
if: github.repository == 'MODFLOW-USGS/modelviewer-mf6'
runs-on: windows-2016
steps:
- uses: actions/checkout@v2
- name: Export env
env:
type: release
zipfile: v${{env.VTK_VERSION}}.zip
instdir: C:/VTK-${{env.VTK_VERSION}}-vs2017-x64
builddir: C:/VTK-${{env.VTK_VERSION}}-vs2017-x64-build
srcdir: C:/VTK-${{env.VTK_VERSION}}
shell: pwsh
run: |
echo "type=$env:type" >> $env:GITHUB_ENV
echo "zipfile=$env:zipfile" >> $env:GITHUB_ENV
echo "instdir=$env:instdir" >> $env:GITHUB_ENV
echo "builddir=$env:builddir" >> $env:GITHUB_ENV
echo "srcdir=$env:srcdir" >> $env:GITHUB_ENV
- name: Cache vtk
id: cache-vtk-release
uses: actions/cache@v2
with:
path: ${{env.instdir}}
key: windows-2016-vtk-${{env.type}}-${{hashFiles('misc/CMakePresets.json')}}
- name: Download vtk
if: steps.cache-vtk-release.outputs.cache-hit != 'true'
shell: pwsh
run: |
curl -L -O "https://github.com/Kitware/VTK/archive/refs/tags/${{env.zipfile}}"
Get-FileHash ${{env.zipfile}}
cd C:\
7z x ${{github.workspace}}\${{env.zipfile}}
rm ${{github.workspace}}\${{env.zipfile}}
- name: Build vtk
if: steps.cache-vtk-release.outputs.cache-hit != 'true'
shell: pwsh
run: |
cp misc\CMakePresets.json ${{env.srcdir}}
cd ${{env.srcdir}}
cmake --preset vs2017
cmake --build --preset vs2017 --config ${{env.type}}
cmake --install ${{env.builddir}} --prefix ${{env.instdir}} --config ${{env.type}}
- name: Check release cache
shell: pwsh
run: |
dir ${{env.instdir}}\bin
cache-vtk:
# uncomment the next line if you want to compile vtk
if: github.repository == 'MODFLOW-USGS/modelviewer-mf6'
runs-on: windows-2016
needs: [cache-vtk-debug, cache-vtk-release]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Export env
env:
zipfile: v${{env.VTK_VERSION}}.zip
instdir: C:/VTK-${{env.VTK_VERSION}}-vs2017-x64
builddir: C:/VTK-${{env.VTK_VERSION}}-vs2017-x64-build
srcdir: C:/VTK-${{env.VTK_VERSION}}
tag: vtk-${{env.VTK_VERSION}}-vs2017-x64
shell: pwsh
run: |
echo "zipfile=$env:zipfile" >> $env:GITHUB_ENV
echo "instdir=$env:instdir" >> $env:GITHUB_ENV
echo "builddir=$env:builddir" >> $env:GITHUB_ENV
echo "srcdir=$env:srcdir" >> $env:GITHUB_ENV
echo "tag=$env:tag" >> $env:GITHUB_ENV
- name: Cache vtk
id: cache-vtk
uses: actions/cache@v2
with:
path: ${{env.instdir}}
key: windows-2016-vtk-${{hashFiles('misc/CMakePresets.json')}}
- name: Cache vtk debug
if: steps.cache-vtk.outputs.cache-hit != 'true'
id: cache-vtk-debug
uses: actions/cache@v2
with:
path: ${{env.instdir}}
key: windows-2016-vtk-debug-${{hashFiles('misc/CMakePresets.json')}}
- name: Cache vtk release
if: steps.cache-vtk.outputs.cache-hit != 'true'
uses: actions/cache@v2
with:
path: ${{env.instdir}}
key: windows-2016-vtk-release-${{hashFiles('misc/CMakePresets.json')}}
- name: Check merged cache
shell: pwsh
run: |
dir ${{env.instdir}}\bin
- name: Compress cache
shell: pwsh
run: |
7z a ${{env.tag}}.7z ${{env.instdir}}
- name: Delete release
env:
releases_url: ${{github.api_url}}/repos/${{github.repository}}/releases
run: |
# create headers dictionary
$h = @{"Authorization" = "token ${{secrets.GITHUB_TOKEN}}"}
try {
# Get a release by tag name
# https://docs.github.com/rest/reference/repos#get-a-release-by-tag-name
# get /repos/{owner}/{repo}/releases/tags/{tag}
$response = Invoke-WebRequest -Uri ${{env.releases_url}}/tags/${{env.tag}} -Headers $h -Method Get
$hashtable = $response.Content | ConvertFrom-Json -AsHashtable
# Delete a release
# https://docs.github.com/en/rest/reference/releases#delete-a-release
# delete /repos/{owner}/{repo}/releases/{release_id}
$id = $hashtable.id.ToString()
$response = Invoke-WebRequest -Uri ${{env.releases_url}}/$id -Headers $h -Method Delete
}
catch {
Write-Output "An error occured:"
Write-Output $_
}
- name: Delete tag
shell: pwsh
run: |
git push --delete origin refs/tags/${{env.tag}}
- name: Create release
env:
releases_url: ${{github.api_url}}/repos/${{github.repository}}/releases
run: |
# setup json variables
$tag_name = "${{env.tag}}"
$filename = "${{env.tag}}.7z"
$hash = (Get-FileHash $filename).Hash.ToLower()
# format using markdown
$body = "```````nsha256`n$hash $filename`n``````"
# store commit
$target_commitish = "${{github.sha}}"
# create headers dictionary
$h = @{"Authorization" = "token ${{secrets.GITHUB_TOKEN}}"}
$releases_url = "${{env.releases_url}}"
# create release
# POST /repos/{owner}/{repo}/releases
# see https://docs.github.com/en/rest/reference/repos#create-a-release
#
$create = @{
"body" = $body
"tag_name" = $tag_name
"target_commitish" = $target_commitish
"name" = $tag_name
"draft" = $true
}
$create_json = $create | ConvertTo-Json
$release = Invoke-WebRequest -Uri $releases_url -Headers $h -Method Post -Body $create_json
# upload artifact (asset)
# POST /repos/{owner}/{repo}/releases/{release_id}/assets
# see https://docs.github.com/en/rest/reference/repos#upload-a-release-asset
#
$upload_uri = ($release.Content | ConvertFrom-Json).upload_url
if (! ($upload_uri -match "(.*)\{\?name,label\}") ) {
# expecting URI{?name,label}
# ie https://uploads.github.com/repos/scharlton2/iricdev-2019/releases/24058628/assets{?name,label}
throw "Bad upload_url"
}
$upload_uri = $Matches[1] + "?name=$filename"
$h["Content-type"] = "application/x-7z-compressed"
$bytes = [System.IO.File]::ReadAllBytes($filename)
$upload = Invoke-WebRequest -Uri $upload_uri -Headers $h -Method Post -Body $bytes
# update release
# PATCH /repos/{owner}/{repo}/releases/{release_id}
# see https://docs.github.com/en/rest/reference/repos#update-a-release
#
$release_id = ($release.Content | ConvertFrom-Json).id
$h.Remove("Content-type")
$update = @{ "draft" = $false }
$update_json = $update | ConvertTo-Json
$release = Invoke-WebRequest -Uri "$releases_url/$release_id" -Headers $h -Method Patch -Body $update_json
# display download url
Write-Output "::group::Results"
Write-Output "$((($release.Content | ConvertFrom-Json).assets).browser_download_url)"
Write-Output "${{github.sha}}"
Write-Output "sha256"
Write-Output "$hash $filename"
Write-Output "::endgroup::"