diff --git a/backend/test.txt b/backend/test.txt new file mode 100644 index 000000000..21eaa97fa Binary files /dev/null and b/backend/test.txt differ diff --git a/devops-pipelines/backend/backend-pr-build-and-test.yml b/devops-pipelines/backend/backend-pr-build-and-test.yml index ac382fefb..e0341dc73 100644 --- a/devops-pipelines/backend/backend-pr-build-and-test.yml +++ b/devops-pipelines/backend/backend-pr-build-and-test.yml @@ -3,7 +3,7 @@ trigger: none pr: branches: include: - - main + # - main - development paths: include: diff --git a/devops-pipelines/backend/backend-pr-integration-tests.yml b/devops-pipelines/backend/backend-pr-integration-tests.yml index 6efbf8b40..7969e32a4 100644 --- a/devops-pipelines/backend/backend-pr-integration-tests.yml +++ b/devops-pipelines/backend/backend-pr-integration-tests.yml @@ -4,124 +4,58 @@ pr: branches: include: - development + - main paths: include: - backend/* +parameters: + - name: environment + displayName: "Target Environment" + type: string + default: "dev" + values: + - dev + - staging + variables: - - template: ../templates/variables/backend-deploy-vars.yml - parameters: - environment: "dev" - - template: ../templates/variables/fa-config-dev.yml - - group: lacc-automated-testing-dev - - name: buildConfiguration - value: "Release" - - name: dotNetVersion - value: "10.x" - - name: efVersion - value: "10.0.*" - - name: testResultsDirectory - value: "$(Agent.TempDirectory)/TestResults" + prTargetBranch: $[ variables['System.PullRequest.TargetBranch'] ] + buildReason: $[ variables['Build.Reason'] ] pool: "LACC PreProd Pool" -jobs: - - job: Run_Integration_Tests - displayName: "Run Integration Test" +stages: + - stage: Test_for_Dev + condition: or( + eq(variables.prTargetBranch, 'development'), + and( + eq(variables.buildReason, 'Manual'), + ${{ eq(parameters.environment, 'dev') }} + ) + ) variables: - projectDir: "backend/CPS.ComplexCases.API.Integration.Tests" - Egress.Url: $(EgressOptionsUrl) - Egress.Username: $(EgressOptionsUsername) - Egress.Email: $(EgressEmail) - Egress.Password: $(EgressOptionsPassword) - Egress.WorkspaceId: $(EgressWorkspaceId) - Egress.WorkspaceName: $(EgressWorkspaceName) - Egress.TestDestinationPath: "integration-tests" - DDEI.BaseUrl: $[ replace( variables['DDEIOptionsBaseUrl'], '/api', '' ) ] - DDEI.AccessKey: $(DDEIOptionsAccessKey) - DDEI.Username: $(CmsUserName) - DDEI.Password: $(CmsUserPassword) - DDEI.TestCaseId: $(CmsTestCaseId) - DDEI.TestUrn: $(CmsTestUrn) - DDEI.TestOperationName: $(CmsTestOperationName) - DDEI.TestDefendantLastName: $(CmsTestDefendantLastName) - DDEI:TestCmsAreaCode: $(CmsTestCmsAreaCode) - Azure.TenantId: $(TenantId) - Azure.ClientId: $(CallingAppValidAudience) - Azure.ClientSecret: $(AadClientSecret) - Azure.UserScope: "api://$(CallingAppValidAudience)/user_impersonation" - Azure.TestUserEmail: $(AadUserName) - Azure.TestUserPassword: $(AadUserPassword) - NetApp.Url: $(NetAppOptionsUrl) - NetApp.ClusterUrl: $(NetAppOptionsClusterUrl) - NetApp.BucketName: $(NetAppOptionsBucketName) - NetApp.S3ServiceUuid: $(NetAppOptionsS3ServiceUuid) - NetApp.SessionDurationSeconds: $(NetAppOptionsSessionDurationSeconds) - NetApp.PepperVersion: $(NetAppOptionsPepperVersion) - NetApp.TestFolderPrefix: "integration-tests" - KeyVault.Url: "https://$(keyVaultName).vault.azure.net/" - ConnectionStrings.CaseManagementDatastoreConnection: $(DbConnectionString) - Postgres.AuthMode: "AAD" - Postgres.DbUserName: $(DbUserName) - steps: - - task: Bash@3 - displayName: "Ensure Azure CLI" - inputs: - targetType: "inline" - script: | - echo "Checking if Azure CLI is installed..." - - # Check if az command exists - if command -v az &> /dev/null; then - echo "Azure CLI is already installed" - az --version - exit 0 - fi - - echo "Azure CLI not found, installing..." - bash $(scripts_directory)/installAzureCli.sh - - - task: UseDotNet@2 - displayName: "Use .NET SDK" - inputs: - packageType: "sdk" - version: $(dotNetVersion) - - - task: FileTransform@2 - displayName: "Write App Settings to File" - inputs: - folderPath: "$(projectDir)" - enableXmlTransform: false - jsonTargetFiles: appsettings.template.json - - - script: mv $(projectDir)/appsettings.template.json $(projectDir)/appsettings.json - displayName: "Rename Appsettings File" - - - task: AzureCLI@2 - displayName: "Run Integration Tests" - inputs: - azureSubscription: "Azure Pipeline: Large and Complex Cases - Pre-Prod" - scriptType: bash - scriptLocation: inlineScript - addSpnToEnvironment: true - workingDirectory: "$(Build.SourcesDirectory)" - inlineScript: | - dotnet test $(projectDir)/CPS.ComplexCases.API.Integration.Tests.csproj \ - --configuration $(buildConfiguration) \ - --collect:"XPlat Code Coverage;Format=cobertura" \ - --settings backend/CodeCoverage.runsettings \ - --logger "trx;LogFileName=integration-tests.trx" \ - --results-directory $(testResultsDirectory) - - - task: PublishTestResults@2 - inputs: - testResultsFormat: "VSTest" - testResultsFiles: "$(testResultsDirectory)/integration-tests.trx" - condition: succeededOrFailed() - - - task: PublishCodeCoverageResults@2 - displayName: "Publish Code Coverage" - inputs: - summaryFileLocation: "$(Agent.TempDirectory)/**/coverage.cobertura.xml" - failIfCoverageEmpty: true - condition: succeededOrFailed() + - template: ../templates/variables/backend-deploy-vars.yml + parameters: + environment: "dev" + - template: ../templates/variables/fa-config-dev.yml + - group: lacc-automated-testing-dev + jobs: + - template: ../templates/backend-integration-test-job.yml + + - stage: Test_for_Staging + dependsOn: [] + condition: or( + eq(variables.prTargetBranch, 'main'), + and( + eq(variables.buildReason, 'Manual'), + ${{ eq(parameters.environment, 'staging') }} + ) + ) + variables: + - template: ../templates/variables/backend-deploy-vars.yml + parameters: + environment: "staging" + - template: ../templates/variables/fa-config-staging.yml + - group: lacc-automated-testing-staging + jobs: + - template: ../templates/backend-integration-test-job.yml diff --git a/devops-pipelines/cleanup-testfiles.yml b/devops-pipelines/cleanup-testfiles.yml index 0aa4cc955..3bf10dd8e 100644 --- a/devops-pipelines/cleanup-testfiles.yml +++ b/devops-pipelines/cleanup-testfiles.yml @@ -29,15 +29,51 @@ jobs: displayName: "Install PowerShell" - task: PowerShell@2 - displayName: "Clear integration-tests Egress folder" + displayName: "Clear integration-tests Egress folders" inputs: - filePath: "$(System.DefaultWorkingDirectory)/devops-pipelines/scripts/test-automation-cleanup/Clear-EgressFolder.ps1" - arguments: > - -BaseUrl $(EgressOptionsUrl) - -ServiceAccountAuth $(EgressServiceAccountAuth) - -WorkspaceId $(EgressWorkspaceId) - -FolderName "integration-tests" - -Force + targetType: "inline" + workingDirectory: "$(System.DefaultWorkingDirectory)/devops-pipelines/scripts/test-automation-cleanup" + script: | + $workspaceIds = @( + $env:devWorkspace + $env:stgWorkspace + ) + + $failedWorkspaces = @() + + foreach ($id in $workspaceIds) { + Write-Host "Attempting to clear the integration-tests folder in workspace $id..." + + try { + & ./Clear-EgressFolder.ps1 ` + -BaseUrl "$(EgressOptionsUrl)" ` + -ServiceAccountAuth "$(EgressServiceAccountAuth)" ` + -WorkspaceId "$Id" ` + -FolderName "integration-tests" ` + -Force + } + catch { + Write-Host "[ERROR] $_" + $failedWorkspaces += @{ + workspaceId = $id + error = $_ + } + } + } + + if ($failedWorkspaces.Count -gt 0) { + Write-Host "The integration-tests folder failed to clear in one or more workspaces:" + foreach ($failed in $failedWorkspaces) { + Write-Host " - $($failed.workspaceId) : $($failed.error) " + } + + throw "Egress cleanup failed for $($failedWorkspaces.Count) workspace(s)." + } + + Write-Host "All integration-tests folders cleared successfully." + env: + devWorkspace: "$(EgressWorkspaceId)" + stgWorkspace: "$(EgressWorkspaceIdIntegrationMain)" - task: PowerShell@2 displayName: "Clear ExistingCaseAutomation Egress folders" diff --git a/devops-pipelines/templates/backend-integration-test-job.yml b/devops-pipelines/templates/backend-integration-test-job.yml new file mode 100644 index 000000000..518a5cd6d --- /dev/null +++ b/devops-pipelines/templates/backend-integration-test-job.yml @@ -0,0 +1,103 @@ +jobs: + - job: Run_Integration_Tests + displayName: "Run Integration Test" + variables: + buildConfiguration: "Release" + dotNetVersion: "10.x" + testResultsDirectory: "$(Agent.TempDirectory)/TestResults" + projectDir: "backend/CPS.ComplexCases.API.Integration.Tests" + Egress.Url: $(EgressOptionsUrl) + Egress.Username: $(EgressOptionsUsername) + Egress.Email: $(EgressEmail) + Egress.Password: $(EgressOptionsPassword) + Egress.WorkspaceId: $(EgressWorkspaceId) + Egress.WorkspaceName: $(EgressWorkspaceName) + Egress.TestDestinationPath: "integration-tests" + DDEI.BaseUrl: $[ replace( variables['DDEIOptionsBaseUrl'], '/api', '' ) ] + DDEI.AccessKey: $(DDEIOptionsAccessKey) + DDEI.Username: $(CmsUserName) + DDEI.Password: $(CmsUserPassword) + DDEI.TestCaseId: $(CmsTestCaseId) + DDEI.TestUrn: $(CmsTestUrn) + DDEI.TestOperationName: $(CmsTestOperationName) + DDEI.TestDefendantLastName: $(CmsTestDefendantLastName) + DDEI:TestCmsAreaCode: $(CmsTestCmsAreaCode) + Azure.TenantId: $(TenantId) + Azure.ClientId: $(CallingAppValidAudience) + Azure.ClientSecret: $(AadClientSecret) + Azure.UserScope: "api://$(CallingAppValidAudience)/user_impersonation" + Azure.TestUserEmail: $(AadUserName) + Azure.TestUserPassword: $(AadUserPassword) + NetApp.Url: $(NetAppOptionsUrl) + NetApp.ClusterUrl: $(NetAppOptionsClusterUrl) + NetApp.BucketName: $(NetAppOptionsBucketName) + NetApp.S3ServiceUuid: $(NetAppOptionsS3ServiceUuid) + NetApp.SessionDurationSeconds: $(NetAppOptionsSessionDurationSeconds) + NetApp.PepperVersion: $(NetAppOptionsPepperVersion) + NetApp.TestFolderPrefix: "integration-tests" + KeyVault.Url: "https://$(keyVaultName).vault.azure.net/" + ConnectionStrings.CaseManagementDatastoreConnection: $(DbConnectionString) + Postgres.AuthMode: "AAD" + Postgres.DbUserName: $(DbUserName) + steps: + - task: Bash@3 + displayName: "Ensure Azure CLI" + inputs: + targetType: "inline" + script: | + echo "Checking if Azure CLI is installed..." + + # Check if az command exists + if command -v az &> /dev/null; then + echo "Azure CLI is already installed" + az --version + exit 0 + fi + + echo "Azure CLI not found, installing..." + bash $(scripts_directory)/installAzureCli.sh + + - task: UseDotNet@2 + displayName: "Use .NET SDK" + inputs: + packageType: "sdk" + version: $(dotNetVersion) + + - task: FileTransform@2 + displayName: "Write App Settings to File" + inputs: + folderPath: "$(projectDir)" + enableXmlTransform: false + jsonTargetFiles: appsettings.template.json + + - script: mv $(projectDir)/appsettings.template.json $(projectDir)/appsettings.json + displayName: "Rename Appsettings File" + + - task: AzureCLI@2 + displayName: "Run Integration Tests" + inputs: + azureSubscription: "Azure Pipeline: Large and Complex Cases - Pre-Prod" + scriptType: bash + scriptLocation: inlineScript + addSpnToEnvironment: true + workingDirectory: "$(Build.SourcesDirectory)" + inlineScript: | + dotnet test $(projectDir)/CPS.ComplexCases.API.Integration.Tests.csproj \ + --configuration $(buildConfiguration) \ + --collect:"XPlat Code Coverage;Format=cobertura" \ + --settings backend/CodeCoverage.runsettings \ + --logger "trx;LogFileName=integration-tests.trx" \ + --results-directory $(testResultsDirectory) + + - task: PublishTestResults@2 + inputs: + testResultsFormat: "VSTest" + testResultsFiles: "$(testResultsDirectory)/integration-tests.trx" + condition: succeededOrFailed() + + - task: PublishCodeCoverageResults@2 + displayName: "Publish Code Coverage" + inputs: + summaryFileLocation: "$(Agent.TempDirectory)/**/coverage.cobertura.xml" + failIfCoverageEmpty: true + condition: succeededOrFailed()