|
| 1 | +name: build-vtk-9.1.0 |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - develop* |
| 8 | + paths: |
| 9 | + - .github/workflows/build-vtk-9.1.0.yml |
| 10 | + - misc/CMakePresets-vtk-9.1.0.json |
| 11 | + |
| 12 | +env: |
| 13 | + CL: /MP |
| 14 | + VTK_VERSION: 9.1.0 |
| 15 | + VS_VERSION: vs2019 |
| 16 | + PRESET: VTK-9.1.0-vs2019-x64 |
| 17 | + |
| 18 | +jobs: |
| 19 | + |
| 20 | + cache-vtk-debug: |
| 21 | + # comment the next line if you want to compile vtk |
| 22 | + if: github.repository == 'MODFLOW-USGS/modelviewer-mf6' |
| 23 | + |
| 24 | + runs-on: windows-2019 |
| 25 | + |
| 26 | + steps: |
| 27 | + |
| 28 | + - uses: actions/checkout@v2 |
| 29 | + |
| 30 | + - name: Export env |
| 31 | + env: |
| 32 | + type: debug |
| 33 | + zipfile: v${{env.VTK_VERSION}}.zip |
| 34 | + instdir: C:/VTK-${{env.VTK_VERSION}}-${{env.VS_VERSION}}-x64 |
| 35 | + builddir: C:/VTK-${{env.VTK_VERSION}}-${{env.VS_VERSION}}-x64-build |
| 36 | + srcdir: C:/VTK-${{env.VTK_VERSION}} |
| 37 | + shell: pwsh |
| 38 | + run: | |
| 39 | + echo "type=$env:type" >> $env:GITHUB_ENV |
| 40 | + echo "zipfile=$env:zipfile" >> $env:GITHUB_ENV |
| 41 | + echo "instdir=$env:instdir" >> $env:GITHUB_ENV |
| 42 | + echo "builddir=$env:builddir" >> $env:GITHUB_ENV |
| 43 | + echo "srcdir=$env:srcdir" >> $env:GITHUB_ENV |
| 44 | +
|
| 45 | + - name: Cache vtk |
| 46 | + id: cache-vtk-debug |
| 47 | + uses: actions/cache@v2 |
| 48 | + with: |
| 49 | + path: ${{env.instdir}} |
| 50 | + key: windows-2019-vtk-${{env.type}}-${{hashFiles('misc\CMakePresets-vtk-9.1.0.json')}} |
| 51 | + |
| 52 | + - name: Download vtk |
| 53 | + if: steps.cache-vtk-debug.outputs.cache-hit != 'true' |
| 54 | + shell: pwsh |
| 55 | + run: | |
| 56 | + curl -L -O "https://github.com/Kitware/VTK/archive/refs/tags/${{env.zipfile}}" |
| 57 | + Get-FileHash ${{env.zipfile}} |
| 58 | + cd C:\ |
| 59 | + 7z x ${{github.workspace}}\${{env.zipfile}} |
| 60 | + rm ${{github.workspace}}\${{env.zipfile}} |
| 61 | +
|
| 62 | + - name: Build vtk |
| 63 | + if: steps.cache-vtk-debug.outputs.cache-hit != 'true' |
| 64 | + shell: pwsh |
| 65 | + run: | |
| 66 | + cp misc\CMakePresets.json ${{env.srcdir}} |
| 67 | + cd ${{env.srcdir}} |
| 68 | + cmake --preset ${{env.PRESET}} |
| 69 | + cmake --build --preset ${{env.PRESET}} --config ${{env.type}} |
| 70 | + cmake --install ${{env.builddir}} --prefix ${{env.instdir}} --config ${{env.type}} |
| 71 | +
|
| 72 | + - name: Check debug cache |
| 73 | + shell: pwsh |
| 74 | + run: | |
| 75 | + dir ${{env.instdir}}\bin |
| 76 | +
|
| 77 | + cache-vtk-release: |
| 78 | + # uncomment the next line if you want to compile vtk |
| 79 | + if: github.repository == 'MODFLOW-USGS/modelviewer-mf6' |
| 80 | + |
| 81 | + runs-on: windows-2019 |
| 82 | + |
| 83 | + steps: |
| 84 | + |
| 85 | + - uses: actions/checkout@v2 |
| 86 | + |
| 87 | + - name: Export env |
| 88 | + env: |
| 89 | + type: release |
| 90 | + zipfile: v${{env.VTK_VERSION}}.zip |
| 91 | + instdir: C:/VTK-${{env.VTK_VERSION}}-${{env.VS_VERSION}}-x64 |
| 92 | + builddir: C:/VTK-${{env.VTK_VERSION}}-${{env.VS_VERSION}}-x64-build |
| 93 | + srcdir: C:/VTK-${{env.VTK_VERSION}} |
| 94 | + shell: pwsh |
| 95 | + run: | |
| 96 | + echo "type=$env:type" >> $env:GITHUB_ENV |
| 97 | + echo "zipfile=$env:zipfile" >> $env:GITHUB_ENV |
| 98 | + echo "instdir=$env:instdir" >> $env:GITHUB_ENV |
| 99 | + echo "builddir=$env:builddir" >> $env:GITHUB_ENV |
| 100 | + echo "srcdir=$env:srcdir" >> $env:GITHUB_ENV |
| 101 | +
|
| 102 | + - name: Cache vtk |
| 103 | + id: cache-vtk-release |
| 104 | + uses: actions/cache@v2 |
| 105 | + with: |
| 106 | + path: ${{env.instdir}} |
| 107 | + key: windows-2019-vtk-${{env.type}}-${{hashFiles('misc\CMakePresets-vtk-9.1.0.json')}} |
| 108 | + |
| 109 | + - name: Download vtk |
| 110 | + if: steps.cache-vtk-release.outputs.cache-hit != 'true' |
| 111 | + shell: pwsh |
| 112 | + run: | |
| 113 | + curl -L -O "https://github.com/Kitware/VTK/archive/refs/tags/${{env.zipfile}}" |
| 114 | + Get-FileHash ${{env.zipfile}} |
| 115 | + cd C:\ |
| 116 | + 7z x ${{github.workspace}}\${{env.zipfile}} |
| 117 | + rm ${{github.workspace}}\${{env.zipfile}} |
| 118 | +
|
| 119 | + - name: Build vtk |
| 120 | + if: steps.cache-vtk-release.outputs.cache-hit != 'true' |
| 121 | + shell: pwsh |
| 122 | + run: | |
| 123 | + cp misc\CMakePresets.json ${{env.srcdir}} |
| 124 | + cd ${{env.srcdir}} |
| 125 | + cmake --preset ${{env.PRESET}} |
| 126 | + cmake --build --preset ${{env.PRESET}} --config ${{env.type}} |
| 127 | + cmake --install ${{env.builddir}} --prefix ${{env.instdir}} --config ${{env.type}} |
| 128 | +
|
| 129 | + - name: Check release cache |
| 130 | + shell: pwsh |
| 131 | + run: | |
| 132 | + dir ${{env.instdir}}\bin |
| 133 | +
|
| 134 | + cache-vtk: |
| 135 | + # uncomment the next line if you want to compile vtk |
| 136 | + if: github.repository == 'MODFLOW-USGS/modelviewer-mf6' |
| 137 | + |
| 138 | + runs-on: windows-2019 |
| 139 | + needs: [cache-vtk-debug, cache-vtk-release] |
| 140 | + |
| 141 | + steps: |
| 142 | + |
| 143 | + - name: Checkout |
| 144 | + uses: actions/checkout@v2 |
| 145 | + |
| 146 | + - name: Export env |
| 147 | + env: |
| 148 | + zipfile: v${{env.VTK_VERSION}}.zip |
| 149 | + instdir: C:/VTK-${{env.VTK_VERSION}}-${{env.VS_VERSION}}-x64 |
| 150 | + builddir: C:/VTK-${{env.VTK_VERSION}}-${{env.VS_VERSION}}-x64-build |
| 151 | + srcdir: C:/VTK-${{env.VTK_VERSION}} |
| 152 | + tag: vtk-${{env.VTK_VERSION}}-${{env.VS_VERSION}}-x64 |
| 153 | + shell: pwsh |
| 154 | + run: | |
| 155 | + echo "zipfile=$env:zipfile" >> $env:GITHUB_ENV |
| 156 | + echo "instdir=$env:instdir" >> $env:GITHUB_ENV |
| 157 | + echo "builddir=$env:builddir" >> $env:GITHUB_ENV |
| 158 | + echo "srcdir=$env:srcdir" >> $env:GITHUB_ENV |
| 159 | + echo "tag=$env:tag" >> $env:GITHUB_ENV |
| 160 | +
|
| 161 | + - name: Cache vtk |
| 162 | + id: cache-vtk |
| 163 | + uses: actions/cache@v2 |
| 164 | + with: |
| 165 | + path: ${{env.instdir}} |
| 166 | + key: windows-2019-vtk-${{hashFiles('misc\CMakePresets-vtk-9.1.0.json')}} |
| 167 | + |
| 168 | + - name: Cache vtk debug |
| 169 | + if: steps.cache-vtk.outputs.cache-hit != 'true' |
| 170 | + id: cache-vtk-debug |
| 171 | + uses: actions/cache@v2 |
| 172 | + with: |
| 173 | + path: ${{env.instdir}} |
| 174 | + key: windows-2019-vtk-debug-${{hashFiles('misc\CMakePresets-vtk-9.1.0.json')}} |
| 175 | + |
| 176 | + - name: Cache vtk release |
| 177 | + if: steps.cache-vtk.outputs.cache-hit != 'true' |
| 178 | + uses: actions/cache@v2 |
| 179 | + with: |
| 180 | + path: ${{env.instdir}} |
| 181 | + key: windows-2019-vtk-release-${{hashFiles('misc\CMakePresets-vtk-9.1.0.json')}} |
| 182 | + |
| 183 | + - name: Check merged cache |
| 184 | + shell: pwsh |
| 185 | + run: | |
| 186 | + dir ${{env.instdir}}\bin |
| 187 | +
|
| 188 | + - name: Compress cache |
| 189 | + shell: pwsh |
| 190 | + run: | |
| 191 | + 7z a ${{env.tag}}.7z ${{env.instdir}} |
| 192 | +
|
| 193 | + - name: Delete release |
| 194 | + env: |
| 195 | + releases_url: ${{github.api_url}}/repos/${{github.repository}}/releases |
| 196 | + run: | |
| 197 | + # create headers dictionary |
| 198 | + $h = @{"Authorization" = "token ${{secrets.GITHUB_TOKEN}}"} |
| 199 | +
|
| 200 | + try { |
| 201 | + # Get a release by tag name |
| 202 | + # https://docs.github.com/rest/reference/repos#get-a-release-by-tag-name |
| 203 | + # get /repos/{owner}/{repo}/releases/tags/{tag} |
| 204 | + $response = Invoke-WebRequest -Uri ${{env.releases_url}}/tags/${{env.tag}} -Headers $h -Method Get |
| 205 | + $hashtable = $response.Content | ConvertFrom-Json -AsHashtable |
| 206 | +
|
| 207 | + # Delete a release |
| 208 | + # https://docs.github.com/en/rest/reference/releases#delete-a-release |
| 209 | + # delete /repos/{owner}/{repo}/releases/{release_id} |
| 210 | + $id = $hashtable.id.ToString() |
| 211 | + $response = Invoke-WebRequest -Uri ${{env.releases_url}}/$id -Headers $h -Method Delete |
| 212 | + } |
| 213 | + catch { |
| 214 | + Write-Output "An error occured:" |
| 215 | + Write-Output $_ |
| 216 | + } |
| 217 | +
|
| 218 | + - name: Delete tag |
| 219 | + shell: pwsh |
| 220 | + run: | |
| 221 | + git push --delete origin refs/tags/${{env.tag}} |
| 222 | +
|
| 223 | + - name: Create release |
| 224 | + env: |
| 225 | + releases_url: ${{github.api_url}}/repos/${{github.repository}}/releases |
| 226 | + run: | |
| 227 | + # setup json variables |
| 228 | + $tag_name = "${{env.tag}}" |
| 229 | + $filename = "${{env.tag}}.7z" |
| 230 | + $hash = (Get-FileHash $filename).Hash.ToLower() |
| 231 | + # format using markdown |
| 232 | + $body = "```````nsha256`n$hash $filename`n``````" |
| 233 | +
|
| 234 | + # store commit |
| 235 | + $target_commitish = "${{github.sha}}" |
| 236 | +
|
| 237 | + # create headers dictionary |
| 238 | + $h = @{"Authorization" = "token ${{secrets.GITHUB_TOKEN}}"} |
| 239 | + $releases_url = "${{env.releases_url}}" |
| 240 | + # create release |
| 241 | + # POST /repos/{owner}/{repo}/releases |
| 242 | + # see https://docs.github.com/en/rest/reference/repos#create-a-release |
| 243 | + # |
| 244 | + $create = @{ |
| 245 | + "body" = $body |
| 246 | + "tag_name" = $tag_name |
| 247 | + "target_commitish" = $target_commitish |
| 248 | + "name" = $tag_name |
| 249 | + "draft" = $true |
| 250 | + } |
| 251 | + $create_json = $create | ConvertTo-Json |
| 252 | + $release = Invoke-WebRequest -Uri $releases_url -Headers $h -Method Post -Body $create_json |
| 253 | + # upload artifact (asset) |
| 254 | + # POST /repos/{owner}/{repo}/releases/{release_id}/assets |
| 255 | + # see https://docs.github.com/en/rest/reference/repos#upload-a-release-asset |
| 256 | + # |
| 257 | + $upload_uri = ($release.Content | ConvertFrom-Json).upload_url |
| 258 | + if (! ($upload_uri -match "(.*)\{\?name,label\}") ) { |
| 259 | + # expecting URI{?name,label} |
| 260 | + # ie https://uploads.github.com/repos/scharlton2/iricdev-2019/releases/24058628/assets{?name,label} |
| 261 | + throw "Bad upload_url" |
| 262 | + } |
| 263 | + $upload_uri = $Matches[1] + "?name=$filename" |
| 264 | + $h["Content-type"] = "application/x-7z-compressed" |
| 265 | + $bytes = [System.IO.File]::ReadAllBytes($filename) |
| 266 | + $upload = Invoke-WebRequest -Uri $upload_uri -Headers $h -Method Post -Body $bytes |
| 267 | + # update release |
| 268 | + # PATCH /repos/{owner}/{repo}/releases/{release_id} |
| 269 | + # see https://docs.github.com/en/rest/reference/repos#update-a-release |
| 270 | + # |
| 271 | + $release_id = ($release.Content | ConvertFrom-Json).id |
| 272 | + $h.Remove("Content-type") |
| 273 | + $update = @{ "draft" = $false } |
| 274 | + $update_json = $update | ConvertTo-Json |
| 275 | + $release = Invoke-WebRequest -Uri "$releases_url/$release_id" -Headers $h -Method Patch -Body $update_json |
| 276 | +
|
| 277 | + # display download url |
| 278 | + Write-Output "::group::Results" |
| 279 | + Write-Output "$((($release.Content | ConvertFrom-Json).assets).browser_download_url)" |
| 280 | + Write-Output "${{github.sha}}" |
| 281 | + Write-Output "sha256" |
| 282 | + Write-Output "$hash $filename" |
| 283 | + Write-Output "::endgroup::" |
0 commit comments