Skip to content

Commit 3dcd752

Browse files
committed
Improve logs in extension action
1 parent 1cd88e6 commit 3dcd752

16 files changed

+614
-416
lines changed

extension/BuildPhpExtension/BuildPhpExtension.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
# NestedModules = @()
6161

6262
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
63-
FunctionsToExport = 'Invoke-PhpBuildExtension', 'Add-BuildRequirements', 'Add-Path', 'Get-PhpSdk', 'Add-Dependencies', 'Add-PhpDependencies', 'Get-VsVersion', 'Add-Extension', 'Get-Extension', 'Get-BuildDirectory', 'Get-ExtensionSource', 'Add-ExtensionDependencies', 'Add-BuildTools', 'Add-OciSdk', 'Add-OdbcCli', 'Get-ExtensionConfig', 'Add-Extensions', 'Get-PhpBuild', 'Get-PhpBuildDetails', 'Invoke-Build', 'Invoke-Tests', 'Add-Package', 'Get-PhpDevelBuild', 'Get-OlderVsVersion', 'Get-PeclLibraryZip'
63+
FunctionsToExport = 'Invoke-PhpBuildExtension', 'Add-BuildRequirements', 'Add-Path', 'Get-PhpSdk', 'Add-Dependencies', 'Add-PhpDependencies', 'Get-VsVersion', 'Add-Extension', 'Get-Extension', 'Get-BuildDirectory', 'Get-ExtensionSource', 'Add-ExtensionDependencies', 'Add-BuildTools', 'Add-OciSdk', 'Add-OdbcCli', 'Get-ExtensionConfig', 'Add-Extensions', 'Get-PhpBuild', 'Get-PhpBuildDetails', 'Invoke-Build', 'Invoke-Tests', 'Add-Package', 'Get-PhpDevelBuild', 'Get-OlderVsVersion', 'Get-PeclLibraryZip', 'Add-BuildLog', 'Add-StepLog', 'Set-GAGroup'
6464

6565
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
6666
CmdletsToExport = '*'
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
function Add-BuildLog
2+
{
3+
<#
4+
.SYNOPSIS
5+
Add a message to the build log.
6+
.PARAMETER Mark
7+
Mark as success or failure
8+
.PARAMETER Subject
9+
Subject of the message
10+
.PARAMETER Message
11+
Message to add to the build log
12+
#>
13+
[OutputType()]
14+
param(
15+
[Parameter(Mandatory = $true, Position = 0, HelpMessage = 'Mark as success or failure')]
16+
[string] $Mark,
17+
[Parameter(Mandatory = $true, Position = 1, HelpMessage = 'Subject of the message')]
18+
[string] $Subject,
19+
[Parameter(Mandatory = $true, Position = 2, HelpMessage = 'Message to add to the build log')]
20+
[string] $Message
21+
)
22+
begin {
23+
$tick = ([char]8730)
24+
$cross = ([char]10007)
25+
}
26+
process {
27+
if($Mark -eq 'tick') {
28+
$colorCode = 32; $MarkValue = $tick
29+
} else {
30+
$colorCode = 31; $MarkValue = $cross
31+
}
32+
$esc = [char]27
33+
$blue = "${esc}[34;1m"
34+
$grey = "${esc}[90;1m"
35+
$reset = "${esc}[0m"
36+
"$MarkValue $Subject $Message" | Out-File build.log -Append -Encoding UTF8
37+
Write-Host "${esc}[$colorCode;1m$MarkValue$reset $blue$Subject$reset $grey$Message$reset"
38+
}
39+
end {
40+
}
41+
}

extension/BuildPhpExtension/private/Add-BuildTools.ps1

Lines changed: 47 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,49 +13,59 @@ Function Add-BuildTools {
1313
begin {
1414
}
1515
process {
16+
if($Config.build_tools.Count -ne 0) {
17+
Add-StepLog "Adding build tools"
18+
}
1619
$Config.build_tools | ForEach-Object {
17-
if($null -eq (Get-Command $_ -ErrorAction SilentlyContinue)) {
18-
switch ($_)
19-
{
20-
nasm {
21-
choco install nasm -y --force
22-
Add-Path -Path "$env:ProgramFiles\NASM"
23-
}
24-
cmake {
25-
choco install cmake --installargs 'ADD_CMAKE_TO_PATH=User' -y --force
26-
}
27-
cargo {
28-
choco install rust -y --force
29-
Add-Path -Path "$env:USERPROFILE\.cargo\bin"
30-
}
31-
git {
32-
choco install git.install --params "'/GitAndUnixToolsOnPath /WindowsTerminal /NoAutoCrlf'" -y --force
33-
}
34-
Default {
35-
$program = $_
36-
$resultLines = (choco search $_ --limit-output) -split "\`r?\`n"
37-
if($resultLines | Where-Object { $_ -match "^$program\|" }) {
38-
choco install $_ -y --force
20+
try {
21+
$tool = $_
22+
if($null -eq (Get-Command $_ -ErrorAction SilentlyContinue)) {
23+
switch ($_)
24+
{
25+
nasm {
26+
choco install nasm -y --force
27+
Add-Path -Path "$env:ProgramFiles\NASM"
28+
}
29+
cmake {
30+
choco install cmake --installargs 'ADD_CMAKE_TO_PATH=User' -y --force
31+
}
32+
cargo {
33+
choco install rust -y --force
34+
Add-Path -Path "$env:USERPROFILE\.cargo\bin"
35+
}
36+
git {
37+
choco install git.install --params "'/GitAndUnixToolsOnPath /WindowsTerminal /NoAutoCrlf'" -y --force
38+
}
39+
Default {
40+
$program = $_
41+
$resultLines = (choco search $_ --limit-output) -split "\`r?\`n"
42+
if($resultLines | Where-Object { $_ -match "^$program\|" }) {
43+
choco install $_ -y --force
44+
}
3945
}
4046
}
41-
}
42-
} else {
43-
switch ($_)
44-
{
45-
# Check if python is actually installed.
46-
python {
47-
$pythonVersion = python --version 2>&1
48-
if($pythonVersion -match "not found") {
49-
choco install python -y --force
47+
} else {
48+
switch ($_)
49+
{
50+
# Check if python is actually installed.
51+
python {
52+
$pythonVersion = python --version 2>&1
53+
if($pythonVersion -match "not found") {
54+
choco install python -y --force
55+
}
56+
$pythonPath = (Get-Command python).Source
57+
$pythonHome = Split-Path $pythonPath
58+
[Environment]::SetEnvironmentVariable("PYTHONPATH", $pythonPATH, [System.EnvironmentVariableTarget]::User)
59+
$env:PYTHONPATH = $pythonPath
60+
[Environment]::SetEnvironmentVariable("PYTHONHOME", $pythonHome, [System.EnvironmentVariableTarget]::User)
61+
$env:PYTHONHOME = $pythonHome
5062
}
51-
$pythonPath = (Get-Command python).Source
52-
$pythonHome = Split-Path $pythonPath
53-
[Environment]::SetEnvironmentVariable("PYTHONPATH", $pythonPATH, [System.EnvironmentVariableTarget]::User)
54-
$env:PYTHONPATH = $pythonPath
55-
[Environment]::SetEnvironmentVariable("PYTHONHOME", $pythonHome, [System.EnvironmentVariableTarget]::User)
56-
$env:PYTHONHOME = $pythonHome
5763
}
5864
}
65+
Add-BuildLog tick $tool "Added"
66+
} catch {
67+
Add-BuildLog cross $tool "Failed to add $tool"
68+
throw
5969
}
6070
}
6171
}

extension/BuildPhpExtension/private/Add-ExtensionDependencies.ps1

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,40 @@ Function Add-ExtensionDependencies {
1313
begin {
1414
}
1515
process {
16+
if($Config.extension_libraries.Count -ne 0) {
17+
Add-StepLog "Adding libraries (third-party)"
18+
}
1619
$Config.extension_libraries | ForEach-Object {
17-
switch ($_)
18-
{
19-
boost {
20-
Add-Boost
21-
}
22-
instantclient {
23-
Add-OciSdk -Config $Config
24-
}
25-
odbc_cli {
26-
Add-OdbcCli -Config $Config
27-
}
28-
Default {
29-
$url = "https://downloads.php.net/~windows/pecl/deps/$_"
30-
Invoke-WebRequest -Uri $url -OutFile $_ -UseBasicParsing
31-
Expand-Archive -Path $_ -DestinationPath "..\deps"
32-
$libName = $_.split('-')[0]
33-
if(Test-Path "..\deps\LICENSE") {
34-
Rename-Item -Path "..\deps\LICENSE" -NewName "LICENSE.$libName"
20+
$library = $_.split('-')[0]
21+
try {
22+
switch ($_)
23+
{
24+
boost {
25+
Add-Boost
26+
}
27+
instantclient {
28+
Add-OciSdk -Config $Config
29+
}
30+
odbc_cli {
31+
Add-OdbcCli -Config $Config
3532
}
36-
if(Test-Path "..\deps\lib\ossl-modules") {
37-
Move-Item -Path "..\deps\lib\ossl-modules\*" -Destination "..\deps\lib"
38-
Remove-Item -Path "..\deps\lib\ossl-modules" -Force -Recurse
33+
Default {
34+
$url = "https://downloads.php.net/~windows/pecl/deps/$_"
35+
Invoke-WebRequest -Uri $url -OutFile $_ -UseBasicParsing
36+
Expand-Archive -Path $_ -DestinationPath "..\deps"
37+
if(Test-Path "..\deps\LICENSE") {
38+
Rename-Item -Path "..\deps\LICENSE" -NewName "LICENSE.$library"
39+
}
40+
if(Test-Path "..\deps\lib\ossl-modules") {
41+
Move-Item -Path "..\deps\lib\ossl-modules\*" -Destination "..\deps\lib"
42+
Remove-Item -Path "..\deps\lib\ossl-modules" -Force -Recurse
43+
}
3944
}
4045
}
46+
Add-BuildLog tick "$library" "Added $($_ -replace '\.zip$')"
47+
} catch {
48+
Add-BuildLog cross "$library" "Failed to download $library"
49+
throw
4150
}
4251
}
4352
}

extension/BuildPhpExtension/private/Add-Extensions.ps1

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,18 @@ Function Add-Extensions {
1717
begin {
1818
}
1919
process {
20+
if($config.extensions.Count -ne 0) {
21+
Add-StepLog "Adding extensions"
22+
}
2023
$config.extensions | ForEach-Object {
21-
Add-Extension -Extension $_ -Config $Config -Prefix $Prefix
24+
$extension = $_
25+
try {
26+
Add-Extension -Extension $extension -Config $Config -Prefix $Prefix
27+
Add-BuildLog tick $extension "Added"
28+
} catch {
29+
Add-BuildLog cross $extension "Failed to add $extension"
30+
throw
31+
}
2232
}
2333
}
2434
end {

extension/BuildPhpExtension/private/Add-Package.ps1

Lines changed: 71 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -13,83 +13,92 @@ function Add-Package {
1313
begin {
1414
}
1515
process {
16-
$currentDirectory = (Get-Location).Path
17-
New-Item -Path $currentDirectory\artifacts -ItemType Directory -Force | Out-Null
18-
$docsFiles = @("LICENSE", "COPYRIGHT", "COPYING")
19-
$docsFiles | ForEach-Object {
20-
if(Test-Path -Path $_) {
21-
Copy-Item -Path $_ -Destination artifacts -Force
22-
}
23-
}
24-
if(Test-Path ..\deps) {
25-
Get-ChildItem -Path ..\deps -Recurse -Filter "LICENSE*" | ForEach-Object {
26-
if(Test-Path -Path $_ -PathType Leaf) {
27-
Copy-Item -Path $_.FullName -Destination artifacts -Force
16+
Add-StepLog "Packaging $($Config.name) extension"
17+
try {
18+
Set-GAGroup start
19+
$currentDirectory = (Get-Location).Path
20+
New-Item -Path $currentDirectory\artifacts -ItemType Directory -Force | Out-Null
21+
$docsFiles = @("LICENSE", "COPYRIGHT", "COPYING")
22+
$docsFiles | ForEach-Object {
23+
if(Test-Path -Path $_) {
24+
Copy-Item -Path $_ -Destination artifacts -Force
2825
}
2926
}
30-
}
31-
$Config.docs | ForEach-Object {
32-
if($null -ne $_) {
33-
$directoryPath = [System.IO.Path]::GetDirectoryName($_)
34-
$targetDir = Join-Path -Path artifacts -ChildPath $directoryPath
35-
New-Item -ItemType Directory -Path $targetDir -Force | Out-Null
36-
Copy-Item -Path $_ -Destination $targetDir -Force
27+
if(Test-Path ..\deps) {
28+
Get-ChildItem -Path ..\deps -Recurse -Filter "LICENSE*" | ForEach-Object {
29+
if(Test-Path -Path $_ -PathType Leaf) {
30+
Copy-Item -Path $_.FullName -Destination artifacts -Force
31+
}
32+
}
3733
}
38-
}
39-
Get-ChildItem -Path $Config.build_directory -Recurse -Filter "*.dll" | ForEach-Object {
40-
Copy-Item -Path $_.FullName -Destination artifacts -Force
41-
}
42-
Get-ChildItem -Path "artifacts\*.dll" | ForEach-Object {
43-
$pdbFilePath = Join-Path -Path $Config.build_directory -ChildPath ($_.BaseName + ".pdb")
44-
if (Test-Path -Path $pdbFilePath) {
45-
Copy-Item -Path $pdbFilePath -Destination artifacts -Force
34+
$Config.docs | ForEach-Object {
35+
if($null -ne $_) {
36+
$directoryPath = [System.IO.Path]::GetDirectoryName($_)
37+
$targetDir = Join-Path -Path artifacts -ChildPath $directoryPath
38+
New-Item -ItemType Directory -Path $targetDir -Force | Out-Null
39+
Copy-Item -Path $_ -Destination $targetDir -Force
40+
}
4641
}
47-
}
48-
# TODO: Filter these using deplister
49-
if(Test-Path ..\deps\bin) {
50-
Get-ChildItem -Path ..\deps\bin -Recurse -Include "*.dll", "*.pdb" | ForEach-Object {
42+
Get-ChildItem -Path $Config.build_directory -Recurse -Filter "*.dll" | ForEach-Object {
5143
Copy-Item -Path $_.FullName -Destination artifacts -Force
5244
}
53-
if(Test-Path (Join-Path -Path ..\deps\bin -ChildPath "*.xml")) {
54-
New-Item -ItemType Directory -Path artifacts\config -Force | Out-Null
55-
Get-ChildItem -Path ..\deps\bin -Recurse -Filter "*.xml" | ForEach-Object {
56-
Copy-Item -Path $_.FullName -Destination artifacts\config -Force
45+
Get-ChildItem -Path "artifacts\*.dll" | ForEach-Object {
46+
$pdbFilePath = Join-Path -Path $Config.build_directory -ChildPath ($_.BaseName + ".pdb")
47+
if (Test-Path -Path $pdbFilePath) {
48+
Copy-Item -Path $pdbFilePath -Destination artifacts -Force
49+
}
50+
}
51+
# TODO: Filter these using deplister
52+
if(Test-Path ..\deps\bin) {
53+
Get-ChildItem -Path ..\deps\bin -Recurse -Include "*.dll", "*.pdb" | ForEach-Object {
54+
Copy-Item -Path $_.FullName -Destination artifacts -Force
55+
}
56+
if(Test-Path (Join-Path -Path ..\deps\bin -ChildPath "*.xml")) {
57+
New-Item -ItemType Directory -Path artifacts\config -Force | Out-Null
58+
Get-ChildItem -Path ..\deps\bin -Recurse -Filter "*.xml" | ForEach-Object {
59+
Copy-Item -Path $_.FullName -Destination artifacts\config -Force
60+
}
5761
}
5862
}
59-
}
6063

61-
Set-Location $currentDirectory\artifacts
62-
if(Test-Path -Path "vc140.pdb") {
63-
Remove-Item -Path "vc140.pdb" -Force
64-
}
64+
Set-Location $currentDirectory\artifacts
65+
if(Test-Path -Path "vc140.pdb") {
66+
Remove-Item -Path "vc140.pdb" -Force
67+
}
6568

66-
# As per https://github.com/ThePHPF/pie-design#windows-binaries
67-
$arch = $Config.arch
68-
if(-not(Test-Path -Path "php_$($Config.name).dll")) {
69-
throw "Failed to build extension"
70-
}
71-
if($env:ARTIFACT_NAMING_SCHEME -eq 'pie') {
72-
if($arch -eq 'x64') {
73-
$arch = 'x86_64'
69+
# As per https://github.com/ThePHPF/pie-design#windows-binaries
70+
$arch = $Config.arch
71+
if(-not(Test-Path -Path "php_$($Config.name).dll")) {
72+
throw "Failed to build extension"
7473
}
75-
$artifact = "php_$($Config.package_name)-$($Config.ref)-$($Config.php_version)-$($Config.ts)-$($Config.vs_version)-$arch"
76-
@("php_$($Config.name).dll", "php_$($Config.name).pdb") | ForEach-Object {
77-
$extension = $_.Split('.')[1]
78-
if(Test-Path -Path $_) {
79-
Move-Item -Path $_ -Destination "$artifact.$extension" -Force
74+
if($env:ARTIFACT_NAMING_SCHEME -eq 'pie') {
75+
if($arch -eq 'x64') {
76+
$arch = 'x86_64'
77+
}
78+
$artifact = "php_$($Config.package_name)-$($Config.ref)-$($Config.php_version)-$($Config.ts)-$($Config.vs_version)-$arch"
79+
@("php_$($Config.name).dll", "php_$($Config.name).pdb") | ForEach-Object {
80+
$extension = $_.Split('.')[1]
81+
if(Test-Path -Path $_) {
82+
Move-Item -Path $_ -Destination "$artifact.$extension" -Force
83+
}
8084
}
85+
} else {
86+
$artifact = "php_$($Config.package_name)-$($Config.ref)-$($Config.php_version)-$($Config.ts)-$($Config.vs_version)-$arch"
8187
}
82-
} else {
83-
$artifact = "php_$($Config.package_name)-$($Config.ref)-$($Config.php_version)-$($Config.ts)-$($Config.vs_version)-$arch"
84-
}
8588

86-
7z a -sdel "$artifact.zip" *
89+
7z a -sdel "$artifact.zip" *
8790

88-
Set-Location $currentDirectory
89-
New-Item -Path $currentDirectory\artifacts\logs -ItemType Directory -Force | Out-Null
90-
Copy-Item -Path build-*.txt -Destination artifacts\logs\ -Force
91-
Set-Location $currentDirectory\artifacts\logs
92-
7z a -sdel "$artifact.zip" *
91+
Set-Location $currentDirectory
92+
New-Item -Path $currentDirectory\artifacts\logs -ItemType Directory -Force | Out-Null
93+
Copy-Item -Path build-*.txt -Destination artifacts\logs\ -Force
94+
Set-Location $currentDirectory\artifacts\logs
95+
7z a -sdel "$artifact.zip" *
96+
Set-GAGroup end
97+
Add-BuildLog tick "Packaging" "Extension $($Config.name) packaged successfully"
98+
} catch {
99+
Add-BuildLog cross "Packaging" "Failed to package $($Config.name) extension"
100+
throw
101+
}
93102
}
94103
end {
95104
}

0 commit comments

Comments
 (0)