From ecc61e08d0d1cc28a0b69bfd465c217b86735f96 Mon Sep 17 00:00:00 2001 From: Egor Bryzgalov Date: Fri, 12 Mar 2021 10:24:43 +0300 Subject: [PATCH] Applied enhancements for the localization pipeline (#733) [skip ci] --- Localize/localize-pipeline.yml | 80 ++++++++++++++++++++++++++++++++-- open-pullrequest.ps1 | 3 +- 2 files changed, 78 insertions(+), 5 deletions(-) diff --git a/Localize/localize-pipeline.yml b/Localize/localize-pipeline.yml index fa2b7b930..c74beff31 100644 --- a/Localize/localize-pipeline.yml +++ b/Localize/localize-pipeline.yml @@ -2,13 +2,40 @@ name: $(Date:MMddyy)$(Rev:.rrrr) trigger: none +schedules: +- cron: 0 8 * * Mon # mm HH DD MM DW + displayName: Localization update + branches: + include: + - Localization + always: true + stages: - stage: __default jobs: - - job: Job1 + - job: LocalizationUpdate + displayName: 'Update localization' pool: vmImage: windows-latest steps: + - checkout: self + persistCredentials: true + + - 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)" + displayName: "Determine the number of the week in the sprint and sprint number" + + - powershell: | + git config --global user.email "$(github_email)" + git config --global user.name "$(username)" + git checkout -b Localization origin/Localization + 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'))) + - task: OneLocBuild@2 inputs: locProj: 'Localize/LocProject.json' @@ -19,10 +46,55 @@ stages: repoType: 'gitHub' prSourceBranchPrefix: 'Localize' gitHubPatVariable: '$(GitHubPAT)' - isAutoCompletePrSelected: false + isAutoCompletePrSelected: true + 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'))) + + - powershell: | + $date= Get-Date -Format "MMddyyyy" + $updateBranch="Localization-update_$date" + echo "##vso[task.setvariable variable=updateBranch]$updateBranch" + + git checkout -b $updateBranch + + Remove-Item -Recurse -Force Localize + + git add -A + 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'))) + + - task: PowerShell@2 + inputs: + filePath: 'open-pullrequest.ps1' + arguments: "-SourceBranch $(updateBranch)" + failOnStderr: true + 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'))) + + - powershell: | + $message="Created task-lib localization update PR. Someone please approve/merge it. :please-puss-in-boots: $env:PR_LINK" + $body = [PSCustomObject]@{ + text = $message + } | ConvertTo-Json + + 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')) + + - powershell: | + $buildUrl = "$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_build/results?buildId=$(Build.BuildId)&_a=summary" + $message="Something went wrong while creating task-lib localization update PR. Build: $buildUrl" + $body = [PSCustomObject]@{ + text = $message + } | ConvertTo-Json - - task: PublishBuildArtifacts@1 - displayName: 'Publish Artifact: drop' + 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')) diff --git a/open-pullrequest.ps1 b/open-pullrequest.ps1 index 25afaa84d..0ddbb4440 100644 --- a/open-pullrequest.ps1 +++ b/open-pullrequest.ps1 @@ -21,4 +21,5 @@ $body = "This PR was auto-generated with [the localization pipeline build]($buil gh pr create --head $SourceBranch --title 'Localization update' --body $body # Getting a link to the opened PR -$env:PR_LINK = Get-PullRequest +$PR_LINK = Get-PullRequest +Write-Host "##vso[task.setvariable variable=PR_LINK]$PR_LINK"