forked from php/setup-php-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun.ps1
More file actions
143 lines (129 loc) · 4.5 KB
/
run.ps1
File metadata and controls
143 lines (129 loc) · 4.5 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
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
param (
[Parameter(Mandatory)] [String] $version,
[Parameter(Mandatory)] [String] $revision,
[Parameter(Mandatory)] [String] $baseurl,
[Parameter(Mandatory)] [String] $arch,
[Parameter(Mandatory)] [String] $ts,
[Parameter(Mandatory)] [AllowEmptyCollection()] [Array] $deps
)
$ErrorActionPreference = "Stop"
$versions = @{
"7.0" = "vc14"
"7.1" = "vc14"
"7.2" = "vc15"
"7.3" = "vc15"
"7.4" = "vc15"
"8.0" = "vs16"
"8.1" = "vs16"
"8.2" = "vs16"
"8.3" = "vs16"
"8.4" = "vs17"
"8.5" = "vs17"
}
$vs = $versions.$version
if (-not $vs) {
throw "unsupported version"
}
$toolsets = @{
"vc14" = "14.0"
}
$dir = vswhere -latest -find "VC\Tools\MSVC"
foreach ($toolset in (Get-ChildItem $dir)) {
$tsv = "$toolset".split(".")
if ((14 -eq $tsv[0]) -and (9 -ge $tsv[1])) {
$toolsets."vc14" = $toolset
} elseif ((14 -eq $tsv[0]) -and (19 -ge $tsv[1])) {
$toolsets."vc15" = $toolset
} elseif ((14 -eq $tsv[0]) -and (29 -ge $tsv[1])) {
$toolsets."vs16" = $toolset
} elseif (14 -eq $tsv[0]) {
$toolsets."vs17" = $toolset
}
}
$toolset = $toolsets.$vs
if (-not $toolset) {
throw "no suitable toolset available on this runner"
}
$cachePath="../cache"
if (!(Test-Path -Path $cachePath -PathType Container)) {
mkdir $cachePath
}
if (-not (Test-Path "php-sdk")) {
Write-Output "Install PHP SDK ..."
#$temp = New-TemporaryFile | Rename-Item -NewName {$_.Name + ".zip"} -PassThru
$temp="$cachePath\php-sdk.zip";
if (!(Test-Path -Path $temp -PathType Leaf)) {
$url = "https://github.com/php/php-sdk-binary-tools/releases/download/php-sdk-2.3.0/php-sdk-binary-tools-php-sdk-2.3.0.zip"
Invoke-WebRequest $url -OutFile $temp
}
Expand-Archive $temp -DestinationPath "."
Rename-Item "php-sdk-binary-tools-php-sdk-2.3.0" "php-sdk"
}
$tspart = if ($ts -eq "nts") {"nts-Win32"} else {"Win32"}
if (-not (Test-path "php-bin")) {
Write-Output "Install PHP $revision ..."
#$temp = New-TemporaryFile | Rename-Item -NewName {$_.Name + ".zip"} -PassThru
$fname = "php-$revision-$tspart-$vs-$arch.zip"
$temp="$cachePath\$fname"
if (!(Test-Path -Path $temp -PathType Leaf)) {
$url = "$baseurl/$fname"
Write-Output "Downloading $url ..."
Invoke-WebRequest $url -OutFile $temp
}
Expand-Archive $temp "php-bin"
}
if (-not (Test-Path "php-dev")) {
Write-Output "Install development pack ..."
#$temp = New-TemporaryFile | Rename-Item -NewName {$_.Name + ".zip"} -PassThru
$fname = "php-devel-pack-$revision-$tspart-$vs-$arch.zip"
$temp="$cachePath\$fname"
if (!(Test-Path -Path $temp -PathType Leaf)) {
$url = "$baseurl/$fname"
Write-Output "Downloading $url ..."
Invoke-WebRequest $url -OutFile $temp
}
Expand-Archive $temp "."
Rename-Item "php-$revision-devel-$vs-$arch" "php-dev"
}
if ($deps.Count -gt 0) {
$baseurl = "https://downloads.php.net/~windows/php-sdk/deps"
$series = Invoke-WebRequest "$baseurl/series/packages-$version-$vs-$arch-staging.txt"
$remainder = @()
$installed = $false
foreach ($dep in $deps) {
foreach ($line in ($series.Content -Split "[\r\n]+")) {
if ($line -match "^$dep") {
Write-Output "Install $line ..."
#$temp = New-TemporaryFile | Rename-Item -NewName {$_.Name + ".zip"} -PassThru
$temp="$cachePath\$vs\$arch\$line"
if (!(Test-Path -Path "$cachePath\$vs\$arch" -PathType Container)) {
mkdir "$cachePath\$vs\$arch"
}
if (!(Test-Path -Path $temp -PathType Leaf)) {
$url = "$baseurl/$vs/$arch/$line"
Write-Output "Downloading $url ..."
Invoke-WebRequest $url -OutFile $temp
}
Expand-Archive $temp "../deps"
$installed = $true
break
}
}
if (-not $installed) {
$remainder += $dep
}
}
if ($remainder.Count -gt 0) {
foreach ($dep in $remainder) {
Write-Output "$dep not available"
exit 1
}
}
}
Add-Content $Env:GITHUB_PATH "$pwd\php-sdk\bin"
Add-Content $Env:GITHUB_PATH "$pwd\php-sdk\msys2\usr\bin"
Add-Content $Env:GITHUB_PATH "$pwd\php-bin"
Add-Content $Env:GITHUB_PATH "$pwd\php-dev"
Write-Output "toolset=$toolset" >> $Env:GITHUB_OUTPUT
Write-Output "prefix=$pwd\php-bin" >> $Env:GITHUB_OUTPUT
Write-Output "vs=$vs" >> $Env:GITHUB_OUTPUT