Created
September 30, 2021 21:41
-
-
Save 1k-off/cae9c627d7894c19f9db9f49fa505022 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
parameters: | |
- name: Environment | |
displayName: Environment | |
type: string | |
default: 'Development' | |
values: | |
- Development | |
- Staging | |
- Production | |
pool: | |
vmImage: 'windows-latest' | |
variables: | |
- group: UmbracoCloud | |
- name: solution | |
value: 'SkriftExample.sln' | |
- name: webProjectPath | |
value: 'SkriftExample.Web' | |
- name: webFrontendPath | |
value: '' | |
stages: | |
- stage: build | |
displayName: Build | |
jobs: | |
- job: build | |
steps: | |
- task: PowerShell@2 | |
name: "detect_environment" | |
displayName: Detect environment | |
inputs: | |
targetType: 'inline' | |
script: | | |
switch ("${{ parameters.Environment }}") { | |
{$_ -match 'Development'} { $gitUmbracoCloudRepoURL = "$(gitUmbracoCloudRepoURLDevelopment)"; break } | |
{$_ -match 'Staging'} { $gitUmbracoCloudRepoURL = "$(gitUmbracoCloudRepoURLStaging)"; break } | |
{$_ -match 'Production'} { $gitUmbracoCloudRepoURL = "$(gitUmbracoCloudRepoURLProduction)"; break } | |
default { $gitUmbracoCloudRepoURL = "$(gitUmbracoCloudRepoURLDevelopment)" } | |
} | |
Write-Host "##vso[task.setvariable variable=gitUmbracoCloudRepoURL]$gitUmbracoCloudRepoURL" | |
- task: PowerShell@2 | |
name: "setup_git" | |
displayName: Setup git | |
inputs: | |
targetType: 'inline' | |
script: | | |
git config --global core.safecrlf false | |
git config --global user.name $(gitFriendlyUserName) | |
git config --global user.email $(gitUserEmail) | |
- task: PowerShell@2 | |
name: "setup_versioning" | |
displayName: Setup versioning | |
inputs: | |
targetType: 'inline' | |
script: | | |
$git_version = (git describe --tags --long --match *.*.* | Select-String -pattern '(?<major>[0-9]+)\.(?<minor>[0-9]+).(?<patch>[0-9]+)-(?<commitCount>[0-9]+)-(?<hash>[a-z0-9]+)').Matches[0].Groups | |
$majorVersion = $git_version['major'] | |
$minorVersion = $git_version['minor'] | |
$patchVersion = $git_version['patch'] | |
$commitCount = $git_version['commitCount'] | |
$commitCountWithLeadingZeros = "{0:D4}" -f [int]"$commitCount" | |
$version = [string]::Join('.', @( | |
$majorVersion, | |
$minorVersion, | |
$patchVersion | |
)) | |
$buildNumber = "$version-${{ parameters.Environment }}+$commitCountWithLeadingZeros" | |
Write-Host "##vso[build.updatebuildnumber]$buildNumber" | |
Write-Host "##vso[build.addbuildtag]${{ parameters.Environment }}" | |
Write-Host "##vso[task.setvariable variable=majorVersion]$majorVersion" | |
Write-Host "##vso[task.setvariable variable=minorVersion]$minorVersion" | |
Write-Host "##vso[task.setvariable variable=patchVersion]$patchVersion" | |
Write-Host "##vso[task.setvariable variable=commitCount]$commitCount" | |
- task: PowerShell@2 | |
name: "get_umbraco_deps" | |
displayName: Get umbraco dependencies | |
inputs: | |
targetType: 'inline' | |
ignoreLASTEXITCODE: true | |
script: | | |
Add-Type -AssemblyName System.Web | |
$UsernameEncoded = [System.Web.HttpUtility]::UrlEncode("$(gitUmbracoCloudLogin)") | |
$PasswordEncoded = [System.Web.HttpUtility]::UrlEncode("$(gitUmbracoCloudPassword)") | |
$currentRemoteUri = New-Object System.Uri $(gitUmbracoCloudRepoURL) | |
$DeploymentURL = New-Object System.UriBuilder($currentRemoteUri) | |
$DeploymentURL.UserName = $UsernameEncoded | |
$DeploymentURL.Password = $PasswordEncoded | |
New-Item -Type Directory "$(webProjectPath)Cloud" | |
Push-Location "$(webProjectPath)Cloud" | |
git clone $DeploymentURL.ToString() . | |
robocopy ..\$(webProjectPath) . /DCOPY:T /E /XD ".git" | |
if($LASTEXITCODE -gt 3){exit $LASTEXITCODE} | |
Push-Location ..\ | |
Remove-Item $(webProjectPath) -Recurse -Force | |
Move-Item "$(webProjectPath)Cloud" $(webProjectPath) | |
- task: PowerShell@2 | |
name: "update_assembly_version" | |
displayName: Update assembly version | |
inputs: | |
targetType: 'inline' | |
script: | | |
function Update-SourceVersion { | |
$assemblyVersion = 'AssemblyVersion("' + $(majorVersion) + "." + $(minorVersion) + "." + $(patchVersion) + "." + $(commitCount) + '")'; | |
$assemblyFileVersion = 'AssemblyFileVersion("' + $(majorVersion) + "." + $(minorVersion) + "." + $(patchVersion) + "." + $(commitCount) + '")'; | |
$assemblyInformationalVersion = 'AssemblyInformationalVersion("' + $(majorVersion) + "." + $(minorVersion) + "." + $(patchVersion) + '")'; | |
Write-Host $assemblyVersion | |
Write-Host $assemblyFileVersion | |
Write-Host $assemblyInformationalVersion | |
foreach ($o in $input) { | |
Write-Host "Updating '$($o.FullName)'" | |
$assemblyVersionPattern = 'AssemblyVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)' | |
$assemblyFileVersionPattern = 'AssemblyFileVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)' | |
$assemblyInformationalVersionPattern = 'AssemblyInformationalVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)' | |
(Get-Content $o.FullName) | ForEach-Object { | |
% {$_ -replace $assemblyVersionPattern, $assemblyVersion } | | |
% {$_ -replace $assemblyFileVersionPattern, $assemblyFileVersion } | | |
% {$_ -replace $assemblyInformationalVersionPattern, $assemblyInformationalVersion } | |
} | Out-File $o.FullName -encoding UTF8 -force | |
} | |
} | |
function Update-AllAssemblyInfoFiles { | |
Write-Host "Searching '$path'" | |
foreach ($file in "AssemblyInfo.cs") { | |
Get-ChildItem $path -recurse |? {$_.Name -eq $file} | Update-SourceVersion; | |
} | |
} | |
Update-AllAssemblyInfoFiles | |
- task: NuGetCommand@2 | |
name: "nuget_restore" | |
displayName: Restore NuGet packages | |
inputs: | |
command: 'restore' | |
restoreSolution: '$(solution)' | |
- task: MSBuild@1 | |
name: "build_soluton" | |
displayName: Build solution | |
inputs: | |
solution: $(solution) | |
configuration: 'Release' | |
msbuildArchitecture: x64 | |
- task: PublishBuildArtifacts@1 | |
name: "upload_artifacts" | |
displayName: Upload artifacts | |
inputs: | |
PathtoPublish: '$(webProjectPath)' | |
ArtifactName: "$(artifactName)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment