Skip to content

Commit

Permalink
Merge 46c2e96 into 0ccba2b
Browse files Browse the repository at this point in the history
  • Loading branch information
kft authored Mar 28, 2023
2 parents 0ccba2b + 46c2e96 commit 5db9a1a
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 0 deletions.
76 changes: 76 additions & 0 deletions .github/workflows/ci-dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
32 changes: 32 additions & 0 deletions source/AcceptanceTests/deploy/deploy.ps1
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions source/AcceptanceTests/deploy/teardown.ps1
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5db9a1a

Please sign in to comment.