Skip to content

Commit

Permalink
minor updates to scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
FlaviuTritean committed Dec 5, 2024
1 parent ff01294 commit 1ba9491
Show file tree
Hide file tree
Showing 3 changed files with 152 additions and 20 deletions.
97 changes: 85 additions & 12 deletions build/PowerShellScripts/BuildSlnForCTE.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,77 @@
[string]$defaultWorkingDirectory = ""
)


if (-not $defaultWorkingDirectory) {
$defaultWorkingDirectory = $env:SYSTEM_DEFAULTWORKINGDIRECTORY
}

if (-not $poolname) {
$poolname = $env:SYSTEM_DEFAULTWORKINGDIRECTORY
}

$folderName = "NuGet"
$appDataPath = [System.Environment]::GetFolderPath('ApplicationData')
$folderPath = Join-Path -Path $appDataPath -ChildPath $folderName


# Get all .csproj files in the repository
$csprojFiles = Get-ChildItem -Path $defaultWorkingDirectory -Recurse -Filter *.sln | Select-Object -ExpandProperty FullName


function UnitTestsExists {
param (
[string]$solutionPath
)

$testAssemblie = Get-ChildItem -Path $solutionPath -Recurse -Include "*UnitTests.dll" | Where-Object { $_.FullName -notlike "*TestAdapter.dll" -and $_.FullName -notlike "*\obj\*" }

if ($testAssemblie.Count -ne 0) {
return $true
}

return $false
}

function BuildUnitTests {
param (
[string]$solutionPath
)

$testAssemblie = Get-ChildItem -Path $solutionPath -Recurse -Include "*UnitTests.dll" | Where-Object { $_.FullName -notlike "*TestAdapter.dll" -and $_.FullName -notlike "*\obj\*" }

if ($testAssemblie.Count -ne 0) {

& "$vsTestPath" "$testAssemblie" /Logger:"Console;Verbosity=normal" `
| Tee-Object -FilePath "$defaultWorkingDirectory\Logs\UnitTestsLog.txt" -Append

}

}

function Get-VSTestConsolePath {
$possibleLocations = @(
"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\Extensions\TestPlatform\vstest.console.exe",
"C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\Extensions\TestPlatform\vstest.console.exe",
"C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\Extensions\TestPlatform\vstest.console.exe",
"C:\Program Files\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\Extensions\TestPlatform\vstest.console.exe",
"C:\Program Files\Microsoft Visual Studio\2019\Professional\Common7\IDE\Extensions\TestPlatform\vstest.console.exe",
"C:\Program Files\Microsoft Visual Studio\2019\BuildTools\Common7\IDE\Extensions\TestPlatform\vstest.console.exe",
"C:\Program Files\Microsoft Visual Studio\2019\Community\Common7\IDE\Extensions\TestPlatform\vstest.console.exe"
)

foreach ($location in $possibleLocations) {
if (Test-Path $location) {
return $location
}
}

Write-Host "VSTest.Console.exe not found in the standard locations." -ForegroundColor Red
return $null
}

$vsTestPath = Get-VSTestConsolePath

# Function to find MSBuild location by checking common paths
function Get-MSBuildLocation {
# Array of possible paths where MSBuild might be located
Expand Down Expand Up @@ -48,22 +108,35 @@ Set-Alias MSBuild -Value $msbuildLocation;

$feedName = 'SDLNuget'
$nugetRestoreArguments = "/p:RestoreSources=https://pkgs.dev.azure.com/sdl/_packaging/$feedName/nuget/v3/index.json"
$msbuildArguments = "/flp:logfile=$defaultWorkingDirectory/GitHubLogs/MyLog.log;append=true"
$msbuildArguments = "/flp:logfile=$defaultWorkingDirectory/Logs/MyLog.log;append=true"

Write-Host ">>>>>>> : $poolName, $index"

foreach ($project in $csprojFiles) {
if (Test-Path -Path $folderPath) {
Remove-Item -Path $folderPath -Recurse -Force
}
# MSBuild "/bl" -m "$project" "/t:Restore" /p:nugetInteractive=true $nugetRestoreArguments
MSBuild "/bl" -m "$project" "/t:Restore" $nugetRestoreArguments -p:RestorePackagesConfig=true
MSBuild -m "$project" "/t:Rebuild" $msbuildArguments

if (! $?) { write-Host "msbuild failed" -ForegroundColor Red ; }

$itemFolder = $project -split '\\'
$joinedString = ($itemFolder[0..(4)] -join '\')
if (Test-Path -Path $joinedString) {
Write-Host "~~~ Following will be deleted: $joinedString"
Remove-Item -Path $joinedString -Recurse -Force

if (Test-Path -Path $project) {

MSBuild "/bl" -m "$project" "/t:Restore" $nugetRestoreArguments -p:RestorePackagesConfig=true
MSBuild -m "$project" "/t:Rebuild" $msbuildArguments

if (! $?) { write-Host "msbuild failed" -ForegroundColor Red ; }

$itemFolder = $project -split '\\'
$joinedString = ($itemFolder[0..($itemFolder.Count - 2)] -join '\')

$unitTestExists = UnitTestsExists -solutionPath $joinedString

if ($unitTestExists){
BuildUnitTests -solutionPath $joinedString
}

if (Test-Path -Path $joinedString) {
Write-Host "~~~ Following will be deleted: $joinedString"
Remove-Item -Path $joinedString -Recurse -Force
}
}

}
51 changes: 43 additions & 8 deletions build/PowerShellScripts/GenerateReportForCompileTimeError.ps1
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
param(
[string]$directoryPath = "",
[string]$resultPath = "",
[string]$reportName = ""
[string]$reportName = "",
[string]$poolName = ""
)

$agentDirectory

if (-not $directoryPath) {
$directoryPath = $env:SYSTEM_DEFAULTWORKINGDIRECTORY
}
Expand All @@ -12,6 +15,10 @@ if (-not $resultPath) {
$resultPath = $env:SYSTEM_DEFAULTWORKINGDIRECTORY
}

if (-not $poolName) {
$poolName = $env:SYSTEM_DEFAULTWORKINGDIRECTORY
}

if (-not $reportName) {
$reportName = "Report"
}
Expand All @@ -31,7 +38,7 @@ $reportFile = "$directoryPath\DemoReport.txt" # Path to your output report file

# Initialize flags and data
$inBuildFailedSection = $false
$buildFailedFound = $false
$inTestFailedSection = $false

# Clear the report file if it already exists
Clear-Content -Path $reportFile -ErrorAction Ignore
Expand All @@ -43,7 +50,6 @@ Get-Content $logFile | ForEach-Object {
# Check if the line contains "Build FAILED."
if ($line -match "Build FAILED.") {
$inBuildFailedSection = $true
$buildFailedFound = $true
}

# If we're in the failed build section, append the line to the report file
Expand All @@ -55,6 +61,19 @@ Get-Content $logFile | ForEach-Object {
if ($line -match "Time Elapsed") {
$inBuildFailedSection = $false
}

if ($line -match "Starting test execution, please wait...") {
$inTestFailedSection = $true
}

if ($inTestFailedSection) {
Add-Content -Path $reportFile -Value $line
}

if ($line -match "Total time:") {
$inTestFailedSection = $false
}

}

# Define file paths
Expand All @@ -68,7 +87,6 @@ $processedLine = $false
# Clear the output file if it already exists
Clear-Content -Path $outputFile -ErrorAction Ignore


if (Test-Path $inputFile) {
# Read the input file line by line
Get-Content $inputFile | ForEach-Object {
Expand All @@ -77,8 +95,12 @@ Get-Content $inputFile | ForEach-Object {
# Check if we are processing a section
if ($processing) {
if (-not $processedLine -and $line -ne "") {
# Process the first non-empty line
$line = $line -replace "D:\\a\\1\\s\\", "~"

if ($poolName -eq "FlaviusPool") {
$line = $line -replace "C:\\agent\\_work\\11\\s\\", "~"
} elseif ($poolName -eq "Azure Pipelines") {
$line = $line -replace "D:\\a\\1\\s\\", "~"
}

# Truncate at the first backslash
if ($line -match "\\") {
Expand Down Expand Up @@ -130,10 +152,24 @@ Get-Content $input1 | ForEach-Object {
$line = $_

# Check if the line does NOT contain the word 'warning'
if ($line -notmatch "warning") {
if ($line -notmatch "warning" -and $inTestFailedSection -eq $false) {
# Write the line to the output file
Add-Content -Path $output1 -Value $line
}

if ($line -match "Failed ") {
Add-Content -Path $output1 -Value $line
$inTestFailedSection = $true
}

if ($inTestFailedSection) {
Add-Content -Path $output1 -Value $line
}

if ($line -match "Stack Trace:") {
$inTestFailedSection = $false
}

}

# Define file paths
Expand Down Expand Up @@ -199,7 +235,6 @@ $output5 = "$directoryPath\ReplaceString.txt" # Path to the output file
# Clear the output file if it already exists
Clear-Content -Path $output5 -ErrorAction Ignore

# Read the input file line by line
Get-Content $input5 | ForEach-Object {
$line = $_

Expand Down
24 changes: 24 additions & 0 deletions build/PowerShellScripts/MergeReports.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
param(
[string]$directoryPath = "",
[string]$outputFile = "",
[string]$file1 = "",
[string]$file2 = ""
)

if (-not $directoryPath) {
$directoryPath = $env:SYSTEM_DEFAULTWORKINGDIRECTORY
}

if (-not $outputFile) {
$outputFile = $env:SYSTEM_DEFAULTWORKINGDIRECTORY
}

if (-not $file1) {
$file1 = $env:SYSTEM_DEFAULTWORKINGDIRECTORY
}

if (-not $file2) {
$file2 = $env:SYSTEM_DEFAULTWORKINGDIRECTORY
}

Get-Content -Path $file1, ($directoryPath + $file2) | Set-Content -Path $outputFile

0 comments on commit 1ba9491

Please sign in to comment.