Skip to content

Commit

Permalink
PR resource names include build number (#1509)
Browse files Browse the repository at this point in the history
Change the names of the resources created in PRs to match the version number of the PR.
  • Loading branch information
LTA-Thinking authored Dec 15, 2020
1 parent ef8fb0c commit 073e656
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 43 deletions.
11 changes: 6 additions & 5 deletions build/ci-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@ stages:
vmImage: 'ubuntu-latest'
steps:
- template: ./jobs/update-semver.yml
- script: echo %Action%%BuildVersion%
displayName: 'Set build version'
env:
Action: '##vso[build.updatebuildnumber]'
BuildVersion: $(GitVersion.semVer)

- stage: BuildUnitTests
displayName: 'Build and run unit tests'
dependsOn:
- UpdateVersion
variables:
assemblySemVer: $[stageDependencies.UpdateVersion.Semver.outputs['SetVariablesFromGitVersion.assemblySemVer']]
assemblySemFileVer: $[stageDependencies.UpdateVersion.Semver.outputs['SetVariablesFromGitVersion.assemblySemFileVer']]
informationalVersion: $[stageDependencies.UpdateVersion.Semver.outputs['SetVariablesFromGitVersion.informationalVersion']]
majorMinorPatch: $[stageDependencies.UpdateVersion.Semver.outputs['SetVariablesFromGitVersion.majorMinorPatch']]
nuGetVersion: $[stageDependencies.UpdateVersion.Semver.outputs['SetVariablesFromGitVersion.nuGetVersion']]
jobs:
- job: Windows
pool:
Expand Down
1 change: 1 addition & 0 deletions build/ci-variables.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ variables:
resourceGroupRoot: 'msh-fhir-ci'
appServicePlanName: '$(resourceGroupRoot)-linux'
DeploymentEnvironmentName: '$(resourceGroupRoot)'
ResourceGroupName: '$(resourceGroupRoot)'
CrucibleEnvironmentUrl: 'https://crucible.mshapis.com/'
TestEnvironmentName: 'OSS CI'
ImageTag: '$(build.BuildNumber)'
7 changes: 4 additions & 3 deletions build/jobs/add-aad-test-environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ jobs:
}

# If a deleted keyvault exists, remove it first
if (Get-AzKeyVault -VaultName "$(DeploymentEnvironmentName)-ts" -Location "westus" -InRemovedState)
$environmentName = "$(DeploymentEnvironmentName)" -replace "\.", ""
if (Get-AzKeyVault -VaultName "${environmentName}-ts" -Location "westus" -InRemovedState)
{
Remove-AzKeyVault -VaultName "$(DeploymentEnvironmentName)-ts" -InRemovedState -Location "westus" -Force
Remove-AzKeyVault -VaultName "${environmentName}-ts" -InRemovedState -Location "westus" -Force
}

$response = Invoke-RestMethod -Method 'Post' -Uri $adTokenUrl -ContentType "application/x-www-form-urlencoded" -Body $body
Expand All @@ -48,4 +49,4 @@ jobs:
Import-Module $(System.DefaultWorkingDirectory)/samples/scripts/PowerShell/FhirServer/FhirServer.psd1
Import-Module $(System.DefaultWorkingDirectory)/release/scripts/PowerShell/FhirServerRelease/FhirServerRelease.psd1

$output = Add-AadTestAuthEnvironment -TestAuthEnvironmentPath $(System.DefaultWorkingDirectory)/testauthenvironment.json -EnvironmentName $(DeploymentEnvironmentName) -TenantAdminCredential $adminCredential
$output = Add-AadTestAuthEnvironment -TestAuthEnvironmentPath $(System.DefaultWorkingDirectory)/testauthenvironment.json -EnvironmentName $environmentName -ResourceGroupName $(ResourceGroupName) -TenantAdminCredential $adminCredential
4 changes: 1 addition & 3 deletions build/jobs/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ parameters:
packageArtifacts: true

steps:
- template: update-semver.yml

- task: UseDotNet@2
displayName: 'Use .NET Core sdk'
inputs:
Expand All @@ -14,7 +12,7 @@ steps:
displayName: 'dotnet build $(buildConfiguration)'
inputs:
command: build
arguments: '--configuration $(buildConfiguration) /p:AssemblyVersion="$(assemblySemVer)" /p:FileVersion="$(assemblySemFileVer)" /p:InformationalVersion="$(informationalVersion)" /warnaserror'
arguments: '--configuration $(buildConfiguration) /p:AssemblyVersion="$(assemblySemVer)" /p:FileVersion="$(assemblySemFileVer)" /p:InformationalVersion="$(informationalVersion)" /p:Version="$(majorMinorPatch)" /warnaserror'

- task: DotNetCoreCLI@2
displayName: 'dotnet test UnitTests'
Expand Down
2 changes: 1 addition & 1 deletion build/jobs/cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
azureSubscription: $(ConnectedServiceName)
azurePowerShellVersion: latestVersion
ScriptType: InlineScript
Inline: 'Get-AzResourceGroup -Name $(DeploymentEnvironmentName) | Remove-AzResourceGroup -Verbose -Force'
Inline: 'Get-AzResourceGroup -Name $(ResourceGroupName) | Remove-AzResourceGroup -Verbose -Force'

- job: cleanupAad
displayName: 'Cleanup Azure Active Directory'
Expand Down
12 changes: 9 additions & 3 deletions build/jobs/provision-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ jobs:
$additionalProperties["SqlServer__AllowDatabaseCreation"] = "true"
$additionalProperties["ASPNETCORE_FORWARDEDHEADERS_ENABLED"] = "true"

$webAppName = "${{ parameters.webAppName }}"
$templateParameters = @{
fhirVersion = "${{ parameters.version }}"
appServicePlanName = "${{ parameters.appServicePlanName }}"
appServicePlanSku = "B3"
serviceName = "${{ parameters.webAppName }}"
serviceName = $webAppName
securityAuthenticationAuthority = "https://login.microsoftonline.com/$(tenant-id)"
securityAuthenticationAudience = "${{ parameters.testEnvironmentUrl }}"
additionalFhirServerConfigProperties = $additionalProperties
Expand All @@ -74,7 +75,12 @@ jobs:
$templateParameters["sqlAdminPassword"] = "$(-join((((33,35,37,38,42,43,45,46,95) + (48..57) + (65..90) + (97..122) | Get-Random -Count 20) + ((33,35,37,38,42,43,45,46,95) | Get-Random -Count 1) + ((48..57) | Get-Random -Count 1) + ((65..90) | Get-Random -Count 1) + ((97..122) | Get-Random -Count 1) | Get-Random -Count 24) | % {[char]$_}))"
$templateParameters["sqlSchemaAutomaticUpdatesEnabled"] = if ("${{ parameters.schemaAutomaticUpdatesEnabled }}" -eq "true") { $true } else { $false }
}
New-AzResourceGroupDeployment -Name "${{ parameters.webAppName }}" -ResourceGroupName "${{ parameters.resourceGroup }}" -TemplateFile $(System.DefaultWorkingDirectory)/samples/templates/default-azuredeploy-docker.json -TemplateParameterObject $templateParameters -Verbose

Write-Host "Provisioning Resource Group"
Write-Host $webAppName
Write-Host "${{ parameters.resourceGroup }}"
New-AzResourceGroupDeployment -Name $webAppName -ResourceGroupName "${{ parameters.resourceGroup }}" -TemplateFile $(System.DefaultWorkingDirectory)/samples/templates/default-azuredeploy-docker.json -TemplateParameterObject $templateParameters -Verbose

Set-AzKeyVaultAccessPolicy -VaultName "${{ parameters.webAppName }}" -ObjectId 4d4d503d-9ca8-462e-9e18-b35fc8b5285b -PermissionsToSecrets list,get
Write-Host "Setting Key Vault access"
Set-AzKeyVaultAccessPolicy -VaultName $webAppName -ObjectId 4d4d503d-9ca8-462e-9e18-b35fc8b5285b -PermissionsToSecrets list,get

18 changes: 10 additions & 8 deletions build/jobs/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,20 @@ jobs:
azurePowerShellVersion: latestVersion
ScriptType: inlineScript
Inline: |
$secrets = Get-AzKeyVaultSecret -VaultName $(DeploymentEnvironmentName)-ts
$keyVault = "$(DeploymentEnvironmentName)-ts"
$secrets = Get-AzKeyVaultSecret -VaultName $keyVault
foreach($secret in $secrets)
{
$environmentVariableName = $secret.Name.Replace("--","_")
$secretValue = Get-AzKeyVaultSecret -VaultName $(DeploymentEnvironmentName)-ts -Name $secret.Name
$secretValue = Get-AzKeyVaultSecret -VaultName $keyVault -Name $secret.Name
Write-Host "##vso[task.setvariable variable=$($environmentVariableName)]$($secretValue.SecretValueText)"
}
$storageAccounts = Get-AzStorageAccount -ResourceGroupName $(DeploymentEnvironmentName)
$storageAccounts = Get-AzStorageAccount -ResourceGroupName $(ResourceGroupName)
foreach ($storageAccount in $storageAccounts) {
$accKey = Get-AzStorageAccountKey -ResourceGroupName $(DeploymentEnvironmentName) -Name $storageAccount.StorageAccountName | Where-Object {$_.KeyName -eq "key1"}
$accKey = Get-AzStorageAccountKey -ResourceGroupName $(ResourceGroupName) -Name $storageAccount.StorageAccountName | Where-Object {$_.KeyName -eq "key1"}
$storageSecretName = "$($storageAccount.StorageAccountName)_secret"
Write-Host "##vso[task.setvariable variable=$($storageSecretName)]$($accKey.Value)"
Expand Down Expand Up @@ -120,19 +121,20 @@ jobs:
azurePowerShellVersion: latestVersion
ScriptType: inlineScript
Inline: |
$secrets = Get-AzKeyVaultSecret -VaultName $(DeploymentEnvironmentName)-ts
$keyVault = "$(DeploymentEnvironmentName)-ts"
$secrets = Get-AzKeyVaultSecret -VaultName $keyVault
foreach($secret in $secrets)
{
$environmentVariableName = $secret.Name.Replace("--","_")
$secretValue = Get-AzKeyVaultSecret -VaultName $(DeploymentEnvironmentName)-ts -Name $secret.Name
$secretValue = Get-AzKeyVaultSecret -VaultName $keyVault -Name $secret.Name
Write-Host "##vso[task.setvariable variable=$($environmentVariableName)]$($secretValue.SecretValueText)"
}
$storageAccounts = Get-AzStorageAccount -ResourceGroupName $(DeploymentEnvironmentName)
$storageAccounts = Get-AzStorageAccount -ResourceGroupName $(ResourceGroupName)
foreach ($storageAccount in $storageAccounts) {
$accKey = Get-AzStorageAccountKey -ResourceGroupName $(DeploymentEnvironmentName) -Name $storageAccount.StorageAccountName | Where-Object {$_.KeyName -eq "key1"}
$accKey = Get-AzStorageAccountKey -ResourceGroupName $(ResourceGroupName) -Name $storageAccount.StorageAccountName | Where-Object {$_.KeyName -eq "key1"}
$storageSecretName = "$($storageAccount.StorageAccountName)_secret"
Write-Host "##vso[task.setvariable variable=$($storageSecretName)]$($accKey.Value)"
Expand Down
13 changes: 7 additions & 6 deletions build/jobs/update-semver.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ steps:

- task: GitVersion@5
displayName: 'GitVersion'
name: GitVersion
inputs:
configFilePath: '$(Build.SourcesDirectory)/GitVersion.yml'

# Can set these: https://github.com/GitTools/actions/blob/master/gitversion/execute/action.yml
- powershell: |
Write-Host "##vso[task.setvariable variable=semVer]$(GitVersion.semVer)"
Write-Host "##vso[task.setvariable variable=informationalVersion]$(GitVersion.informationalVersion)"
Write-Host "##vso[task.setvariable variable=majorMinorPatch]$(GitVersion.majorMinorPatch)"
Write-Host "##vso[task.setvariable variable=nuGetVersion]$(GitVersion.semVer)"
Write-Host "##vso[task.setvariable variable=assemblySemVer]$(GitVersion.assemblySemVer)"
Write-Host "##vso[task.setvariable variable=assemblySemFileVer]$(GitVersion.assemblySemFileVer)"
Write-Host "##vso[task.setvariable variable=informationalVersion;isOutput=true]$(GitVersion.informationalVersion)"
Write-Host "##vso[task.setvariable variable=majorMinorPatch;isOutput=true]$(GitVersion.majorMinorPatch)"
Write-Host "##vso[task.setvariable variable=nuGetVersion;isOutput=true]$(GitVersion.semVer)"
Write-Host "##vso[task.setvariable variable=assemblySemVer;isOutput=true]$(GitVersion.assemblySemVer)"
Write-Host "##vso[task.setvariable variable=assemblySemFileVer;isOutput=true]$(GitVersion.assemblySemFileVer)"
name: SetVariablesFromGitVersion

- powershell: |
Expand All @@ -28,4 +29,4 @@ steps:
Write-Host 'assemblySemVer: $(assemblySemVer)'
Write-Host 'assemblySemFileVer: $(assemblySemFileVer)'
Write-Host 'nuGetVersion: $(nuGetVersion)'
name: PrintVariablesFromGitVersion
name: PrintVariablesFromGitVersion
38 changes: 25 additions & 13 deletions build/pr-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,23 @@ stages:
pool:
vmImage: 'ubuntu-latest'
steps:
- template: ./jobs/update-semver.yml
- script: echo %Action%%BuildVersion%
displayName: 'Set build version'
env:
Action: '##vso[build.updatebuildnumber]'
BuildVersion: $(GitVersion.semVer)
- template: ./jobs/update-semver.yml
- powershell: |
$buildNumber = "$(GitVersion.semVer)" -replace "\.", ""
Write-Host "##vso[build.updatebuildnumber]$buildNumber"
Write-Host "Updated build number to '$buildNumber"
name: SetBuildVersion
- stage: BuildUnitTests
displayName: 'Build and run unit tests'
dependsOn:
- UpdateVersion
variables:
assemblySemVer: $[stageDependencies.UpdateVersion.Semver.outputs['SetVariablesFromGitVersion.assemblySemVer']]
assemblySemFileVer: $[stageDependencies.UpdateVersion.Semver.outputs['SetVariablesFromGitVersion.assemblySemFileVer']]
informationalVersion: $[stageDependencies.UpdateVersion.Semver.outputs['SetVariablesFromGitVersion.informationalVersion']]
majorMinorPatch: $[stageDependencies.UpdateVersion.Semver.outputs['SetVariablesFromGitVersion.majorMinorPatch']]
nuGetVersion: $[stageDependencies.UpdateVersion.Semver.outputs['SetVariablesFromGitVersion.nuGetVersion']]
jobs:
- job: Windows
pool:
Expand Down Expand Up @@ -64,7 +70,13 @@ stages:
azurePowerShellVersion: latestVersion
ScriptType: inlineScript
Inline: |
New-AzResourceGroup -Name "$(DeploymentEnvironmentName)" -Location "$(ResourceGroupRegion)" -Force
try
{
Get-AzResourceGroup -Name $(ResourceGroupName) | Remove-AzResourceGroup -Verbose -Force
}
catch
{}
New-AzResourceGroup -Name "$(ResourceGroupName)" -Location "$(ResourceGroupRegion)" -Force
- stage: aadTestEnvironment
displayName: Setup AAD Test Environment
Expand Down Expand Up @@ -143,7 +155,7 @@ stages:
appServicePlanName: $(appServicePlanName)
appServicePlanResourceGroup: $(appServicePlanResourceGroup)
subscription: $(ConnectedServiceName)
resourceGroup: $(DeploymentEnvironmentName)
resourceGroup: $(ResourceGroupName)
testEnvironmentUrl: $(TestEnvironmentUrl)
imageTag: $(ImageTag)

Expand All @@ -161,7 +173,7 @@ stages:
appServicePlanName: $(appServicePlanName)
appServicePlanResourceGroup: $(appServicePlanResourceGroup)
subscription: $(ConnectedServiceName)
resourceGroup: $(DeploymentEnvironmentName)
resourceGroup: $(ResourceGroupName)
testEnvironmentUrl: $(TestEnvironmentUrl)
imageTag: $(ImageTag)
schemaAutomaticUpdatesEnabled: true
Expand All @@ -179,7 +191,7 @@ stages:
appServicePlanName: $(appServicePlanName)
appServicePlanResourceGroup: $(appServicePlanResourceGroup)
subscription: $(ConnectedServiceName)
resourceGroup: $(DeploymentEnvironmentName)
resourceGroup: $(ResourceGroupName)
testEnvironmentUrl: $(TestEnvironmentUrl)
imageTag: $(ImageTag)

Expand All @@ -197,7 +209,7 @@ stages:
appServicePlanName: $(appServicePlanName)
appServicePlanResourceGroup: $(appServicePlanResourceGroup)
subscription: $(ConnectedServiceName)
resourceGroup: $(DeploymentEnvironmentName)
resourceGroup: $(ResourceGroupName)
testEnvironmentUrl: $(TestEnvironmentUrl)
imageTag: $(ImageTag)
schemaAutomaticUpdatesEnabled: true
Expand All @@ -215,7 +227,7 @@ stages:
appServicePlanName: $(appServicePlanName)
appServicePlanResourceGroup: $(appServicePlanResourceGroup)
subscription: $(ConnectedServiceName)
resourceGroup: $(DeploymentEnvironmentName)
resourceGroup: $(ResourceGroupName)
testEnvironmentUrl: $(TestEnvironmentUrl)
imageTag: $(ImageTag)

Expand All @@ -233,7 +245,7 @@ stages:
appServicePlanName: $(appServicePlanName)
appServicePlanResourceGroup: $(appServicePlanResourceGroup)
subscription: $(ConnectedServiceName)
resourceGroup: $(DeploymentEnvironmentName)
resourceGroup: $(ResourceGroupName)
testEnvironmentUrl: $(TestEnvironmentUrl)
imageTag: $(ImageTag)
schemaAutomaticUpdatesEnabled: true
Expand Down
3 changes: 2 additions & 1 deletion build/pr-variables.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ variables:
resourceGroupRoot: 'msh-fhir-pr'
appServicePlanName: '$(resourceGroupRoot)-$(prNumber)-asp'
prNumber: $(system.pullRequest.pullRequestNumber)
DeploymentEnvironmentName: '$(resourceGroupRoot)-$(prNumber)'
ResourceGroupName: '$(resourceGroupRoot)-$(prNumber)'
DeploymentEnvironmentName: 'f$(build.BuildNumber)'
CrucibleEnvironmentUrl: ''
TestEnvironmentName: 'OSS PR$(prNumber)'
ImageTag: '$(build.BuildNumber)'
2 changes: 2 additions & 0 deletions build/remove-environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ trigger: none
pr: none

variables:
- name: ResourceGroupName
value: 'msh-fhir-pr-$(pr_number)'
- name: DeploymentEnvironmentName
value: 'msh-fhir-pr-$(pr_number)'
- template: build-variables.yml
Expand Down

0 comments on commit 073e656

Please sign in to comment.