diff --git a/.github/workflows/ci-dotnet.yml b/.github/workflows/ci-dotnet.yml index 7b6769d65e..5056812b9f 100644 --- a/.github/workflows/ci-dotnet.yml +++ b/.github/workflows/ci-dotnet.yml @@ -48,3 +48,79 @@ jobs: TESTS_DLL_FILE_PATH: '\source\Tests\bin\Release\net7.0\Tests.dll' DOWNLOAD_ATTEMPT_LIMIT: 12 DOTNET_VERSION: 7.0.200 + + # Deploy resources for acceptance testing + deploy_acceptance_test_resources: + runs-on: ubuntu-22.04 + environment: AzureAuth + permissions: + id-token: write + contents: read + outputs: + resourceGroup: ${{ steps.getResourceGroup.outputs.resourceGroup }} + namespaceName: ${{ steps.getServiceBusNamespace.outputs.namespaceName }} + steps: + - uses: actions/checkout@v3 + + - name: Login to Azure + uses: azure/login@v1 + with: + client-id: ${{ secrets.AZURE_SPN_ID_OIDC }} + tenant-id: ${{ secrets.AZURE_TENANT_ID }} + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + + - id: getResourceGroup + shell: pwsh + run: | + Write-Output "resourceGroup=$(` + az keyvault secret show ` + --vault-name ${{ secrets.AZURE_KEYVAULT_NAME }} ` + --name "AZURE-SHARED-RESOURCEGROUP" ` + --query value -o tsv)" >> $Env:GITHUB_OUTPUT + + - id: getServiceBusNamespace + shell: pwsh + run: Write-Output "namespaceName=$(` + az keyvault secret show ` + --vault-name ${{ secrets.AZURE_KEYVAULT_NAME }} ` + --name "AZURE-SERVICEBUS-NAMESPACE" ` + --query value -o tsv)" >> $Env:GITHUB_OUTPUT + + - name: Publish acceptance test resources + shell: pwsh + run: | + .\source\AcceptanceTests\deploy\deploy.ps1 ` + -PrNumber ${{ github.event.pull_request.number }} ` + -Subscription ${{ secrets.AZURE_SUBSCRIPTION_ID }} ` + -ResourceGroup ${{ steps.getResourceGroup.outputs.resourceGroup }} ` + -SqlServerName " " ` + -NamespaceName ${{ steps.getServiceBusNamespace.outputs.namespaceName }} + + # Teardown resources for acceptance testing + teardown_acceptance_test_resources: + needs: [deploy_acceptance_test_resources] + runs-on: ubuntu-22.04 + environment: AzureAuth + permissions: + id-token: write + contents: read + steps: + - uses: actions/checkout@v3 + + - name: Login to Azure + uses: azure/login@v1 + with: + client-id: ${{ secrets.AZURE_SPN_ID_OIDC }} + tenant-id: ${{ secrets.AZURE_TENANT_ID }} + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + + - name: Teardown acceptance test resources + shell: pwsh + run: | + .\source\AcceptanceTests\deploy\teardown.ps1 ` + -PrNumber ${{ github.event.pull_request.number }} ` + -Subscription ${{ secrets.AZURE_SUBSCRIPTION_ID }} ` + -ResourceGroup ${{ needs.deploy_acceptance_test_resources.outputs.resourceGroup }} ` + -SqlServerName " " ` + -NamespaceName ${{ needs.deploy_acceptance_test_resources.outputs.namespaceName }} + diff --git a/source/AcceptanceTests/deploy/deploy.ps1 b/source/AcceptanceTests/deploy/deploy.ps1 new file mode 100644 index 0000000000..10889f2b1e --- /dev/null +++ b/source/AcceptanceTests/deploy/deploy.ps1 @@ -0,0 +1,32 @@ +param ( + [Parameter(Mandatory=$true)] + [string]$Subscription, + [Parameter(Mandatory=$true)] + [string]$ResourceGroup, + [Parameter(Mandatory=$true)] + [string]$SqlServerName, + [Parameter(Mandatory=$true)] + [string]$NamespaceName, + [Parameter(Mandatory=$true)] + [string]$PrNumber) + +function CreateDatabase { + $databaseName = "Test-$PrNumber" + az sql db create --resource-group $ResourceGroup --server $SqlServerName --name $databaseName --edition Basic +} + +function CreateServiceBusTopics { + $integrationEventsTopic = "IntegrationEvents-$PrNumber" + $(az servicebus topic create --resource-group $ResourceGroup --namespace-name $NamespaceName --name $integrationEventsTopic) | Out-Null + $(az servicebus topic subscription create --resource-group $ResourceGroup --namespace-name $NamespaceName --topic-name $integrationEventsTopic --name All-Events) | Out-Null +} + +function CreateServiceBusQueues { + $(az servicebus queue create --resource-group $ResourceGroup --namespace-name $NamespaceName --name "Command-$PrNumber") | Out-Null +} + +az account set -s $Subscription + +#CreateDatabase +CreateServiceBusTopics +CreateServiceBusQueues \ No newline at end of file diff --git a/source/AcceptanceTests/deploy/teardown.ps1 b/source/AcceptanceTests/deploy/teardown.ps1 new file mode 100644 index 0000000000..642faf7f0c --- /dev/null +++ b/source/AcceptanceTests/deploy/teardown.ps1 @@ -0,0 +1,32 @@ +param( + [Parameter(Mandatory=$true)] + [string]$Subscription, + [Parameter(Mandatory=$true)] + [string]$ResourceGroup, + [Parameter(Mandatory=$true)] + [string]$SqlServerName, + [Parameter(Mandatory=$true)] + [string]$NamespaceName, + [Parameter(Mandatory=$true)] + [string]$PrNumber) + +function DeleteDatabase { + $databaseName = "Test-$prNumber" + az sql db delete --name $databaseName --resource-group $ResourceGroup --server $SqlServerName | Out-Null +} + +function DeleteServiceBusTopics { + $integrationEventsTopic = "IntegrationEvents-$PrNumber" + az servicebus topic subscription delete --resource-group $ResourceGroup --namespace-name $NamespaceName --topic-name $integrationEventsTopic --name All-Events | Out-Null + az servicebus topic delete --resource-group $ResourceGroup --namespace-name $NamespaceName --name $integrationEventsTopic | Out-Null +} + +function DeleteServiceBusQueues { + az servicebus queue delete --resource-group $ResourceGroup --namespace-name $NamespaceName --name "Command-$PrNumber" | Out-Null +} + +az account set -s $Subscription + +#DeleteDatabase +DeleteServiceBusTopics +DeleteServiceBusQueues \ No newline at end of file