diff --git a/.github/workflows/continuous-integration-workflow.yml b/.github/workflows/continuous-integration-workflow.yml index e2a5e18..2e182a4 100644 --- a/.github/workflows/continuous-integration-workflow.yml +++ b/.github/workflows/continuous-integration-workflow.yml @@ -43,25 +43,77 @@ jobs: - name: Build SQL Server Database project run: | - # List all .sqlproj files except for .sqlproj + # Enable strict error handling + $ErrorActionPreference = 'Stop' + + # Initialize an error collection + $errors = @() + + # List all .sqlproj files $sqlproj_files = Get-ChildItem -Path . -Filter *.sqlproj -Recurse - - # Build each .csproj file - foreach ($sqlproj_file in $sqlproj_files) { - Write-Host "Building $($sqlproj_file.FullName)" - msbuild "$($sqlproj_file.FullName)" /p:Configuration=Release - } - - - name: Build solution excluding SQL project + + if ($sqlproj_files.Count -eq 0) { + $errors += "No .sqlproj files found." + } else { + foreach ($sqlproj_file in $sqlproj_files) { + Write-Host "Building $($sqlproj_file.FullName)" + try { + $output = &msbuild "$($sqlproj_file.FullName)" /p:Configuration=Release /nologo 2>&1 + if (!$?) { + $errors += "Failed to build $($csproj_file.FullName): $output" + } + } catch { + # Capture detailed error information + $errorMessage = "Error building $($sqlproj_file.FullName): $($_.Exception.Message)" + Write-Host $errorMessage + $errors += $errorMessage + } + } + } + + # Display all accumulated errors + if ($errors.Count -gt 0) { + Write-Host "SQL Project Build Errors:" + $errors | ForEach-Object { Write-Host $_ } + exit 1 + } + + - name: Build Solution Excluding SQL Project run: | - # List all .csproj files except for .sqlproj + # Enable strict error handling + $ErrorActionPreference = 'Stop' + + # Initialize an error collection + $errors = @() + + # List all .csproj files except .sqlproj $csproj_files = Get-ChildItem -Path . -Filter *.csproj -Recurse | Where-Object { $_.FullName -notmatch '\\.sqlproj$' } - - # Build each .csproj file - foreach ($csproj_file in $csproj_files) { - Write-Host "Building $($csproj_file.FullName)" - dotnet build "$($csproj_file.FullName)" - } + + if ($csproj_files.Count -eq 0) { + $errors += "No .csproj files found." + } else { + foreach ($csproj_file in $csproj_files) { + Write-Host "Building $($csproj_file.FullName)" + try { + $output = &dotnet build "$($csproj_file.FullName)" --configuration Release 2>&1 + if (!$?) { + $errors += "Failed to build $($csproj_file.FullName): $output" + } + } catch { + # Capture detailed error information + $errorMessage = "Error building $($csproj_file.FullName): $($_.Exception.Message)" + Write-Host $errorMessage + $errors += $errorMessage + } + } + } + + # Display all accumulated errors + if ($errors.Count -gt 0) { + Write-Host "Solution Build Errors:" + $errors | ForEach-Object { Write-Host $_ } + exit 1 + } #- name: Test # run: dotnet test ${{ env.BuildParameters.TestProjects }} diff --git a/LearningHub.Nhs.UserApi.Services.UnitTests/LearningHub.Nhs.UserApi.Services.UnitTests.csproj b/LearningHub.Nhs.UserApi.Services.UnitTests/LearningHub.Nhs.UserApi.Services.UnitTests.csproj index 9e355a8..51575ad 100644 --- a/LearningHub.Nhs.UserApi.Services.UnitTests/LearningHub.Nhs.UserApi.Services.UnitTests.csproj +++ b/LearningHub.Nhs.UserApi.Services.UnitTests/LearningHub.Nhs.UserApi.Services.UnitTests.csproj @@ -15,7 +15,7 @@ - +