-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck-and-build.ps1
80 lines (72 loc) · 2.16 KB
/
check-and-build.ps1
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
#! powershell
# Based off of https://github.com/instrumentisto/rust-docker-image
param (
[Parameter(Mandatory)]
[ValidateSet("stable", "beta", "nightly")]
[String]
$train,
[String]
$username,
[String]
$password
)
$ErrorActionPreference = "Stop"
Invoke-WebRequest `
-OutFile ".\channel-rust-${train}.toml" `
-Uri "https://static.rust-lang.org/dist/channel-rust-${train}.toml"
$latestToolchainVer = ( `
Select-String `
-Path ".\channel-rust-${train}.toml" `
-Pattern "\[pkg.rustc]" `
-Context 0,1 `
| Select-Object -Expand Context `
| Select-Object -Expand PostContext `
| Select-String -Pattern "version" `
| Out-String -Stream `
).split('"')[2].trim()
echo "--> Latest toolchain version: rustc $latestToolchainVer"
docker pull yodal/rust-windows:${train}
if($LASTEXITCODE) {
exit $LASTEXITCODE
}
$currentImageVer = ( `
(docker run --rm yodal/rust-windows:${train} rustc -V) `
| Select-String -Pattern "rustc" `
| Select-Object -Expand Line `
).trim()
if($LASTEXITCODE) {
exit $LASTEXITCODE
}
echo "--> Current image toolchain version: $currentImageVer"
if("rustc $latestToolchainVer" -ne "$currentImageVer") {
echo "--> Image is out-of-date, rebuilding iamge"
docker build -t yodal/rust-windows:${train} -f .\${train}\Dockerfile .
if($LASTEXITCODE) {
exit $LASTEXITCODE
}
if($username -and $password) {
docker login -u $username -p $password
if($LASTEXITCODE) {
exit $LASTEXITCODE
}
docker push yodal/rust-windows:${train}
if($LASTEXITCODE) {
exit $LASTEXITCODE
}
if($train -eq "stable") {
docker tag yodal/rust-windows:stable yodal/rust-windows:latest
if($LASTEXITCODE) {
exit $LASTEXITCODE
}
docker push yodal/rust-windows:latest
if($LASTEXITCODE) {
exit $LASTEXITCODE
}
}
} else {
echo "--> Docker username or password not set"
exit 1
}
} else {
echo "--> Image is up-to-date, no need to rebuild"
}