From e10292e51a34d2699abdb92b06a9d409a3098726 Mon Sep 17 00:00:00 2001 From: Nikita Ezzhev Date: Wed, 21 Apr 2021 13:24:26 +0300 Subject: [PATCH] Create PR in OneLocBuild task only on third week of sprint (#755) * Fix localization pipeline * Add missed change * Added option to disable PR creation --- Localize/localize-pipeline.yml | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/Localize/localize-pipeline.yml b/Localize/localize-pipeline.yml index d92279650..cef451c3a 100644 --- a/Localize/localize-pipeline.yml +++ b/Localize/localize-pipeline.yml @@ -23,8 +23,16 @@ stages: - powershell: | $sprintInfo = Invoke-WebRequest https://whatsprintis.it -Headers @{"Accept"= "application/json"} | ConvertFrom-Json - Write-Host "##vso[task.setvariable variable=week]$($sprintInfo.week)" - Write-Host "##vso[task.setvariable variable=sprint]$($sprintInfo.sprint)" + if (($env:PR_CREATION_ENABLED -eq 'True') -and (($sprintInfo.week -eq 3) -or ($env:BUILD_REASON -eq 'Manual'))) + { + Write-Host "shouldCreatePR was set to true" + Write-Host "##vso[task.setvariable variable=shouldCreatePR]$($true)" + } + else + { + Write-Host "shouldCreatePR was set to false" + Write-Host "##vso[task.setvariable variable=shouldCreatePR]$($false)" + } displayName: "Determine the number of the week in the sprint and sprint number" - powershell: | @@ -34,7 +42,7 @@ stages: git merge origin/master git push origin Localization displayName: "Sync with master branch" - condition: and(succeeded(), or(and(eq(variables['WEEK'], '3'), eq(variables['build.reason'], 'Schedule')), eq(variables['build.reason'], 'Manual'))) + condition: and(succeeded(), in(variables['build.reason'], 'Schedule', 'Manual')) - task: OneLocBuild@2 inputs: @@ -42,7 +50,7 @@ stages: outDir: '$(Build.ArtifactStagingDirectory)' packageSourceAuth: 'patAuth' patVariable: '$(OneLocBuildPAT)' - isCreatePrSelected: true + isCreatePrSelected: $(shouldCreatePR) repoType: 'gitHub' prSourceBranchPrefix: 'Localize' gitHubPatVariable: '$(GitHubPAT)' @@ -50,10 +58,10 @@ stages: gitHubPrMergeMethod: 'squash' env: SYSTEM_ACCESSTOKEN: $(System.AccessToken) - condition: and(succeeded(), or(and(eq(variables['WEEK'], '3'), eq(variables['build.reason'], 'Schedule')), eq(variables['build.reason'], 'Manual'))) + condition: and(succeeded(), in(variables['build.reason'], 'Schedule', 'Manual')) - task: PublishBuildArtifacts@1 - condition: and(succeeded(), or(and(eq(variables['WEEK'], '3'), eq(variables['build.reason'], 'Schedule')), eq(variables['build.reason'], 'Manual'))) + condition: and(succeeded(), in(variables['build.reason'], 'Schedule', 'Manual')) displayName: 'Publish an artifact' - powershell: | @@ -69,7 +77,7 @@ stages: git commit -m "Removing Localize folder" git push origin $updateBranch displayName: Create and push localization update branch - condition: and(succeeded(), or(and(eq(variables['WEEK'], '3'), eq(variables['build.reason'], 'Schedule')), eq(variables['build.reason'], 'Manual'))) + condition: and(succeeded(), or(and(eq(variables['SHOULDCREATEPR'], 'True'), eq(variables['build.reason'], 'Schedule')), eq(variables['build.reason'], 'Manual'))) - task: PowerShell@2 inputs: @@ -79,7 +87,7 @@ stages: env: GH_TOKEN: '$(GitHubPAT)' displayName: Open a PR - condition: and(succeeded(), or(and(eq(variables['WEEK'], '3'), eq(variables['build.reason'], 'Schedule')), eq(variables['build.reason'], 'Manual'))) + condition: and(succeeded(), or(and(eq(variables['SHOULDCREATEPR'], 'True'), eq(variables['build.reason'], 'Schedule')), eq(variables['build.reason'], 'Manual'))) - powershell: | $message="Created task-lib localization update PR. Someone please approve/merge it. :please-puss-in-boots: $env:PR_LINK" @@ -89,7 +97,7 @@ stages: Invoke-RestMethod -Uri $(slackUri) -Method Post -Body $body -ContentType 'application/json' displayName: 'Send Slack notification about PR opened' - condition: and(succeeded(), eq(variables['WEEK'], '3'), eq(variables['build.reason'], 'Schedule')) + condition: and(succeeded(), eq(variables['SHOULDCREATEPR'], 'True'), eq(variables['build.reason'], 'Schedule')) - powershell: | $buildUrl = "$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_build/results?buildId=$(Build.BuildId)&_a=summary" @@ -100,4 +108,4 @@ stages: Invoke-RestMethod -Uri $(slackUri) -Method Post -Body $body -ContentType 'application/json' displayName: 'Send Slack notification about error' - condition: and(failed(), eq(variables['WEEK'], '3'), eq(variables['build.reason'], 'Schedule')) + condition: and(failed(), eq(variables['SHOULDCREATEPR'], 'True'), eq(variables['build.reason'], 'Schedule'))