Skip to content

Commit

Permalink
ci: provision environments for pipelines (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
ewingjm authored Jan 28, 2022
1 parent 90c7f76 commit 5a68747
Show file tree
Hide file tree
Showing 5 changed files with 307 additions and 115 deletions.
15 changes: 10 additions & 5 deletions azure-pipelines-pull-request.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
name: $(GITVERSION_FullSemVer)

trigger: none

pr:
- master

pool:
vmImage: 'windows-latest'
vmImage: windows-latest

stages:
- stage: BuildAndTest
displayName: Build and Test
jobs:
- template: templates/build-and-test-job.yml
- template: templates/build-and-test-stages.yml
parameters:
environmentIdentifier: $[ coalesce(variables['System.PullRequest.PullRequestNumber'], variables['Build.BuildId']) ]
environmentDisplayName: Package Deployer Template - PR
environmentDomainName: pdt-pr
25 changes: 11 additions & 14 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
name: $(GITVERSION_FullSemVer)

trigger:
batch: true
branches:
include:
- master

pr: none

pool:
vmImage: 'windows-latest'
variables:
- name: GitVersion.SemVer
value: ''
- name: solution
value: '**/*.sln'
- name: buildPlatform
value: 'anycpu'
- name: buildConfiguration
value: 'Release'
vmImage: windows-latest

stages:
- stage: BuildAndTest
displayName: Build and Test
jobs:
- template: templates/build-and-test-job.yml
- template: templates/build-and-test-stages.yml
parameters:
environmentIdentifier: $(Build.BuildId)
environmentDisplayName: Package Deployer Template - CI
environmentDomainName: pdt-ci
- stage: Publish
displayName: Publish
dependsOn: ManualValidation
jobs:
- job: PublishJob
displayName: Publish
Expand Down
66 changes: 66 additions & 0 deletions scripts/New-PowerAppFlowConnection.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#
# New-PowerAppFlowConnection.ps1
#
[CmdletBinding()]
param (
[string]
[Parameter(Mandatory = $true)]
$Username,
[securestring]
[Parameter(Mandatory = $true)]
$Password,
[Parameter(Mandatory = $true)]
[string]
$EnvironmentName,
[Parameter(Mandatory = $true)]
[string]
$Region,
[Parameter(Mandatory = $true)]
[string]
$Connector,
[Parameter(Mandatory = $false)]
[hashtable]
$ConnectionParameters = @{},
[string]
[parameter(Mandatory = $false)]
$DisplayName,
[string]
[Parameter(Mandatory = $false)]
$OutputVariable
)

$ErrorActionPreference = 'Stop'

Install-Module -Name Microsoft.PowerApps.Administration.PowerShell -Force -Scope CurrentUser -AllowClobber

Write-Host "Authenticating as $Username."
Add-PowerAppsAccount -Username $Username -Password $Password

if (!$ConnectionId) {
$ConnectionId = [Guid]::NewGuid().ToString("N")
}

$body = @{
properties = @{
environment = @{
name = "$EnvironmentName"
}
connectionParameters = $ConnectionParameters
displayName = $DisplayName
}
}

Write-Host "Creating $Connector connection with ID $ConnectionId on environment $EnvironmentName with $($ConnectionParameters.connectionString)"

$result = InvokeApi `
-Method PUT `
-Route "https://$Region.api.powerapps.com/providers/Microsoft.PowerApps/apis/$Connector/connections/$($ConnectionId)?api-version=2021-02-01&`$filter=environment eq '$EnvironmentName'" `
-Body $body `
-ThrowOnFailure

Write-Host "Connection $($result.name) created."

if ($OutputVariable) {
Write-Host "Setting $OutputVariable variable to $($result.name)."
Write-Host "##vso[task.setvariable variable=$OutputVariable]$($result.name)"
}
211 changes: 115 additions & 96 deletions templates/build-and-test-job.yml
Original file line number Diff line number Diff line change
@@ -1,97 +1,116 @@
jobs:
- job: BuildAndTestJob
displayName: Build and Test
variables:
- name: GitVersion.SemVer
value: ''
- name: solution
value: '**/*.sln'
- name: buildPlatform
value: 'anycpu'
- name: buildConfiguration
value: 'Release'
- group: Cap Dev - CI
steps:

- task: gitversion/setup@0
displayName: Install GitVersion
inputs:
versionSpec: '5.x'

- task: gitversion/execute@0
displayName: Execute GitVersion
inputs:
useConfigFile: true
configFilePath: '$(Build.SourcesDirectory)\GitVersion.yml'
updateAssemblyInfo: false

- pwsh: Write-Host "##vso[task.setvariable variable=SemVer;isOutput=true]$(GitVersion.SemVer)"
name: OutputSemVerTask
displayName: Output SemVer

- task: DotNetCoreCLI@2
displayName: Restore NuGet packages
inputs:
command: restore
projects: '**/*.csproj'

- task: SonarCloudPrepare@1
displayName: Prepare SonarCloud
inputs:
SonarCloud: 'SonarCloud'
organization: 'capgemini-1'
scannerMode: 'MSBuild'
projectKey: 'Capgemini_xrm-packagedeployer'
projectName: 'xrm-packagedeployer'
projectVersion: '$(GitVersion.SemVer)'
extraProperties: |
sonar.exclusions=**\*.css
parameters:
- name: environmentUrl
displayName: Environment URL
type: string
- name: environmentName
displayName: environmentName
type: string
- name: username
displayName: Username
type: string
- name: password
displayName: Password
type: string

- task: VSBuild@1
displayName: Build solution
inputs:
solution: '$(solution)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'

- task: VSTest@2
displayName: Run tests
env:
CAPGEMINI_PACKAGE_DEPLOYER_TESTS_URL: $(URL)
CAPGEMINI_PACKAGE_DEPLOYER_TESTS_USERNAME: $(User ADO Integration Username)
CAPGEMINI_PACKAGE_DEPLOYER_TESTS_PASSWORD: $(User ADO Integration Password)
inputs:
codeCoverageEnabled: true
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
testAssemblyVer2: '**\*Tests.dll'
searchFolder: tests

- task: SonarCloudAnalyze@1
displayName: Analyse with SonarCloud

- task: SonarCloudPublish@1
displayName: Publish SonarCloud results
inputs:
pollingTimeoutSec: '300'

- task: WhiteSource Bolt@20
displayName: Detect security and licence issues
inputs:
cwd: '$(Build.SourcesDirectory)'

- task: DotNetCoreCLI@2
displayName: Pack NuGet package
inputs:
command: pack
packagesToPack: src\Capgemini.PowerApps.PackageDeployerTemplate\Capgemini.PowerApps.PackageDeployerTemplate.csproj
modifyOutputPath: true
versioningScheme: byEnvVar
versionEnvVar: GitVersion.NuGetVersionV2
includesymbols: false
buildProperties: Configuration=$(buildConfiguration)
packDirectory: $(Build.ArtifactStagingDirectory)/out

- publish: $(Build.ArtifactStagingDirectory)/out
displayName: Publish NuGet artifact
artifact: Capgemini.PowerApps.PackageDeployerTemplate
jobs:
- job: BuildAndTestJob
displayName: Build and Test
variables:
- name: GitVersion.SemVer
value: ''
- name: solution
value: '**/*.sln'
- name: buildPlatform
value: 'anycpu'
- name: buildConfiguration
value: 'Release'
steps:
- task: gitversion/setup@0
displayName: Install GitVersion
inputs:
versionSpec: '5.x'
- task: gitversion/execute@0
displayName: Execute GitVersion
inputs:
useConfigFile: true
configFilePath: '$(Build.SourcesDirectory)\GitVersion.yml'
updateAssemblyInfo: false
- pwsh: Write-Host "##vso[task.setvariable variable=SemVer;isOutput=true]$(GitVersion.SemVer)"
name: OutputSemVerTask
displayName: Output SemVer
- task: DotNetCoreCLI@2
displayName: Restore NuGet packages
inputs:
command: restore
projects: '**/*.csproj'
- task: SonarCloudPrepare@1
displayName: Prepare SonarCloud
inputs:
SonarCloud: 'SonarCloud'
organization: 'capgemini-1'
scannerMode: 'MSBuild'
projectKey: 'Capgemini_xrm-packagedeployer'
projectName: 'xrm-packagedeployer'
projectVersion: '$(GitVersion.SemVer)'
extraProperties: |
sonar.exclusions=**\*.css
- task: VSBuild@1
displayName: Build solution
inputs:
solution: '$(solution)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: PowerShell@2
displayName: Create Approvals connection
inputs:
filePath: $(Build.SourcesDirectory)\scripts\New-PowerAppFlowConnection.ps1
arguments: >
-Username ${{ parameters.username }}
-Password (ConvertTo-SecureString -String $env:CONNECTIONOWNER_PASSWORD -AsPlainText -Force)
-EnvironmentName ${{ parameters.environmentName }}
-Region unitedkingdom
-Connector shared_approvals
-ConnectionParameters @{ }
-OutputVariable "TestEnvironment.Connection.Approvals"
targetType: filePath
env:
CONNECTIONOWNER_PASSWORD: ${{ parameters.password }}
- task: VSTest@2
displayName: Run tests
env:
CAPGEMINI_PACKAGE_DEPLOYER_TESTS_URL: ${{ parameters.environmentUrl }}
CAPGEMINI_PACKAGE_DEPLOYER_TESTS_USERNAME: ${{ parameters.username }}
CAPGEMINI_PACKAGE_DEPLOYER_TESTS_PASSWORD: ${{ parameters.password }}
PACKAGEDEPLOYER_SETTINGS_CONNREF_PDT_SHAREDAPPROVALS_D7DCB: $(TestEnvironment.Connection.Approvals)
PACKAGEDEPLOYER_SETTINGS_ENVVAR_PDT_TESTVARIABLE: Any string
PACKAGEDEPLOYER_SETTINGS_CONNBASEURL_pdt_5Fexample-20api: https://anyurl.com
inputs:
codeCoverageEnabled: true
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
testAssemblyVer2: '**\*Tests.dll'
searchFolder: tests
- task: SonarCloudAnalyze@1
displayName: Analyse with SonarCloud
- task: SonarCloudPublish@1
displayName: Publish SonarCloud results
inputs:
pollingTimeoutSec: '300'
- task: WhiteSource Bolt@20
displayName: Detect security and licence issues
inputs:
cwd: '$(Build.SourcesDirectory)'
- task: DotNetCoreCLI@2
displayName: Pack NuGet package
inputs:
command: pack
packagesToPack: src\Capgemini.PowerApps.PackageDeployerTemplate\Capgemini.PowerApps.PackageDeployerTemplate.csproj
modifyOutputPath: true
versioningScheme: byEnvVar
versionEnvVar: GitVersion.NuGetVersionV2
includesymbols: false
buildProperties: Configuration=$(buildConfiguration)
packDirectory: $(Build.ArtifactStagingDirectory)/out
- publish: $(Build.ArtifactStagingDirectory)/out
displayName: Publish NuGet artifact
artifact: Capgemini.PowerApps.PackageDeployerTemplate
Loading

0 comments on commit 5a68747

Please sign in to comment.