Repository navigation
Expand file tree
/
Copy pathbuild_and_smoke_paclet.ps1
More file actions
72 lines (59 loc) · 2.25 KB
/
Copy pathbuild_and_smoke_paclet.ps1
File metadata and controls
72 lines (59 loc) · 2.25 KB
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
$ErrorActionPreference = 'Stop'
$repositoryRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
$buildScript = Join-Path $repositoryRoot 'build_paclet.wls'
$latestBuildFile = Join-Path $repositoryRoot 'build\latest-build.txt'
$archive = $null
function Get-LatestBuildArchive {
if (-not (Test-Path -LiteralPath $latestBuildFile)) {
return $null
}
$candidateDirectory = (Get-Content -LiteralPath $latestBuildFile -Raw).Trim()
if (-not (Test-Path -LiteralPath $candidateDirectory -PathType Container)) {
return $null
}
$candidateArchives = @(Get-ChildItem -LiteralPath $candidateDirectory -Filter '*.paclet' -File)
if ($candidateArchives.Count -eq 1) {
return $candidateArchives[0].FullName
}
return $null
}
if (Test-Path -LiteralPath $latestBuildFile) {
$archive = Get-LatestBuildArchive
if (-not $archive -and (Get-Item -LiteralPath $latestBuildFile).LastWriteTime -gt (Get-Date).AddMinutes(-5)) {
for ($poll = 1; $poll -le 10 -and -not $archive; $poll++) {
Start-Sleep -Seconds 2
$archive = Get-LatestBuildArchive
}
}
}
for ($attempt = 1; $attempt -le 3; $attempt++) {
if ($archive) {
break
}
& wolframscript -file $buildScript
if ($LASTEXITCODE -ne 0) {
throw "Paclet build stage $attempt failed with exit code $LASTEXITCODE."
}
$archive = Get-LatestBuildArchive
if ($archive) {
break
}
}
if (-not $archive) {
throw 'PacletTools did not produce exactly one archive after three resumable stages.'
}
$archiveDirectory = Split-Path -Parent $archive
$finalizedMarker = Join-Path $archiveDirectory 'finalized.ok'
if (-not (Test-Path -LiteralPath $finalizedMarker)) {
& wolframscript -file (Join-Path $repositoryRoot 'finalize_paclet.wls')
if ($LASTEXITCODE -ne 0) {
throw "Paclet finalization failed with exit code $LASTEXITCODE."
}
New-Item -ItemType File -Path $finalizedMarker -Force | Out-Null
}
Set-Content -LiteralPath $latestBuildFile -Value $archiveDirectory -Encoding utf8
& wolframscript -file (Join-Path $repositoryRoot 'smoke_paclet.wls')
if ($LASTEXITCODE -ne 0) {
throw "Paclet smoke test failed with exit code $LASTEXITCODE."
}
Remove-Item -LiteralPath $latestBuildFile -Force