From 2a00ec90aa78f8fe792ed8377879342743ab344e Mon Sep 17 00:00:00 2001 From: Allan Targino Date: Thu, 8 Jul 2021 15:18:50 +0000 Subject: [PATCH] Merged PR 173: Replacing tokens after CD is created and creating qa/main branches Former-commit-id: fc715cccde950445bd4b1b807c4e5586fef05e4c --- quickstart/.gitignore | 1 + .../scripts/dataops/Deploy-AzureDevOps.ps1 | 4 +- .../scripts/modules/RepoOperations.psm1 | 42 +++++++++---------- 3 files changed, 25 insertions(+), 22 deletions(-) create mode 100644 quickstart/.gitignore diff --git a/quickstart/.gitignore b/quickstart/.gitignore new file mode 100644 index 0000000..015c7c1 --- /dev/null +++ b/quickstart/.gitignore @@ -0,0 +1 @@ +config.dev.json \ No newline at end of file diff --git a/quickstart/scripts/dataops/Deploy-AzureDevOps.ps1 b/quickstart/scripts/dataops/Deploy-AzureDevOps.ps1 index 6dee7e1..97a12f1 100644 --- a/quickstart/scripts/dataops/Deploy-AzureDevOps.ps1 +++ b/quickstart/scripts/dataops/Deploy-AzureDevOps.ps1 @@ -24,10 +24,12 @@ $repoInfo = CreateAzureDevopsRepository -RepoConfiguration $config.RepoConfigura $directory = CloneRepo -RepoInfo $repoInfo -UseSSH $UseSSH -UsePAT $UsePAT -Verbose:$VerbosePreference ImportTemplateRepoToDomainRepo -RepoConfiguration $config.RepoConfiguration -UsePAT $UsePAT -Directory $directory[0] -Verbose:$VerbosePreference + +CreateAzDevOpsYamlPipelines -RepoConfiguration $config.RepoConfiguration -Verbose:$VerbosePreference + UpdateIaCParameters -Configuration $config -Directory $directory[0] -Verbose:$VerbosePreference CreateAzDevOpsRepoApprovalPolicy -RepoInfo $repoInfo -RepoConfiguration $config.RepoConfiguration -Verbose:$VerbosePreference CreateAzDevOpsRepoCommentPolicy -RepoInfo $repoInfo -RepoConfiguration $config.RepoConfiguration -Verbose:$VerbosePreference -CreateAzDevOpsYamlPipelines -RepoConfiguration $config.RepoConfiguration -Verbose:$VerbosePreference CreateAzDevOpsRepoBuildPolicy -RepoInfo $repoInfo -RepoConfiguration $config.RepoConfiguration -Verbose:$VerbosePreference CreateAzDevOpsVariableGroups -RepoConfiguration $config.RepoConfiguration -Verbose:$VerbosePreference diff --git a/quickstart/scripts/modules/RepoOperations.psm1 b/quickstart/scripts/modules/RepoOperations.psm1 index f9f10e2..708c238 100644 --- a/quickstart/scripts/modules/RepoOperations.psm1 +++ b/quickstart/scripts/modules/RepoOperations.psm1 @@ -21,8 +21,12 @@ function ImportTemplateRepoToDomainRepo { git remote add template $templateGitUrl git fetch template git merge remotes/template/main - git branch -M $RepoConfiguration.DefaultBranchName - git push -u origin $RepoConfiguration.DefaultBranchName + + git push -u origin HEAD:main + git push -u origin HEAD:qa + + git branch -M $RepoConfiguration.DefaultBranchName + git push origin HEAD Set-Location - } @@ -38,45 +42,36 @@ function UpdateIaCParameters { Set-Location $Directory + git checkout $Configuration.RepoConfiguration.DefaultBranchName + BeginScope -Scope "IaC parameters" - ReplaceTemplateTokens ` - -Configuration $Configuration ` + ReplaceTemplateTokens -Configuration $Configuration -RemoveInput ` -InputFile infrastructure-as-code/infrastructure/parameters/parameters.dev.template.json ` -OutputFile infrastructure-as-code/infrastructure/parameters/parameters.dev.json - ReplaceTemplateTokens ` - -Configuration $Configuration ` + ReplaceTemplateTokens -Configuration $Configuration -RemoveInput ` -InputFile infrastructure-as-code/infrastructure/parameters/parameters.qa.template.json ` -OutputFile infrastructure-as-code/infrastructure/parameters/parameters.qa.json - ReplaceTemplateTokens ` - -Configuration $Configuration ` + ReplaceTemplateTokens -Configuration $Configuration -RemoveInput ` -InputFile infrastructure-as-code/infrastructure/parameters/parameters.prod.template.json ` -OutputFile infrastructure-as-code/infrastructure/parameters/parameters.prod.json - ReplaceTemplateTokens ` - -Configuration $Configuration ` + ReplaceTemplateTokens -Configuration $Configuration -RemoveInput ` -InputFile azure-pipelines/databricks/databricks-lib-cd.template.yml ` -OutputFile azure-pipelines/databricks/databricks-lib-cd.yml - ReplaceTemplateTokens ` - -Configuration $Configuration ` + ReplaceTemplateTokens -Configuration $Configuration -RemoveInput ` -InputFile azure-pipelines/variable.environment.template.yml ` -OutputFile azure-pipelines/variable.environment.yml EndScope - git add infrastructure-as-code/infrastructure/parameters/parameters.dev.json - git add infrastructure-as-code/infrastructure/parameters/parameters.qa.json - git add infrastructure-as-code/infrastructure/parameters/parameters.prod.json - git add azure-pipelines/databricks/databricks-lib-cd.yml - git add azure-pipelines/variable.environment.yml - + git add . git commit -m "Update IaC paramaters." + git push -u origin HEAD:$($Configuration.RepoConfiguration.DefaultBranchName) - git push -u origin $RepoConfiguration.DefaultBranchName - Set-Location - } @@ -102,7 +97,8 @@ function ReplaceTemplateTokens { [Parameter(Mandatory)] [string] $InputFile, [Parameter(Mandatory)] [string] $OutputFile, [string] $StartTokenPattern = '<', - [string] $EndTokenPattern = '>' + [string] $EndTokenPattern = '>', + [switch] $RemoveInput ) CleanFileIfExists -File $OutputFile @@ -125,6 +121,10 @@ function ReplaceTemplateTokens { $line | Out-File -Append -FilePath $OutputFile } + if ($RemoveInput) { + Remove-Item $InputFile + } + Write-Host "Done! ($totalTokens tokens replaced successfully)" }