From 1f36b5093a1fc0bc31531b81f229659e097865d8 Mon Sep 17 00:00:00 2001 From: Egor Bryzgalov Date: Wed, 17 Feb 2021 15:22:38 +0300 Subject: [PATCH 1/9] Adde schedule and slack notifications. (cherry picked from commit 12fe19a606fd7d5cfb07977ad3340d58b38590c5) --- Localize/localize-pipeline.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Localize/localize-pipeline.yml b/Localize/localize-pipeline.yml index fa2b7b930..5ac178e46 100644 --- a/Localize/localize-pipeline.yml +++ b/Localize/localize-pipeline.yml @@ -2,6 +2,14 @@ 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: @@ -9,6 +17,11 @@ stages: pool: vmImage: windows-latest steps: + - powershell: | + $week = (Invoke-WebRequest https://whatsprintis.it -Headers @{"Accept"= "application/json"} | ConvertFrom-Json).week + Write-Host "##vso[task.setvariable variable=week]$week" + displayName: "Determine the number of the week in the sprint" + - task: OneLocBuild@2 inputs: locProj: 'Localize/LocProject.json' @@ -22,6 +35,19 @@ stages: isAutoCompletePrSelected: false env: SYSTEM_ACCESSTOKEN: $(System.AccessToken) + + - powershell: | + $body = '{"text": "Created agent localization update PR. Someone please approve/merge it. :please-puss-in-boots:"}' + Invoke-RestMethod -Uri $(slackUri) -Method Post -Body $body -ContentType 'application/json' + displayName: 'Send Slack notification' + 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" + $body = '{"text": "Something went wrong while creating agent localization update PR. Build: ' + $buildUrl + '"}' + Invoke-RestMethod -Uri $(slackUri) -Method Post -Body $body -ContentType 'application/json' + displayName: 'Send Slack notification' + condition: and(failed(), eq(variables['WEEK'], '3'), eq(variables['build.reason'], 'Schedule')) - task: PublishBuildArtifacts@1 displayName: 'Publish Artifact: drop' From 5607d27533891f952a1b6231cd5440a787d4dd44 Mon Sep 17 00:00:00 2001 From: Egor Bryzgalov Date: Wed, 17 Feb 2021 17:26:03 +0300 Subject: [PATCH 2/9] Fixed notification (cherry picked from commit 95b242a5a146cdbffb5af433d197d9bc0a23c764) --- Localize/localize-pipeline.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Localize/localize-pipeline.yml b/Localize/localize-pipeline.yml index 5ac178e46..dd5bb0715 100644 --- a/Localize/localize-pipeline.yml +++ b/Localize/localize-pipeline.yml @@ -37,14 +37,14 @@ stages: SYSTEM_ACCESSTOKEN: $(System.AccessToken) - powershell: | - $body = '{"text": "Created agent localization update PR. Someone please approve/merge it. :please-puss-in-boots:"}' + $body = '{"text": "Created task-lib localization update PR. Someone please approve/merge it. :please-puss-in-boots:"}' Invoke-RestMethod -Uri $(slackUri) -Method Post -Body $body -ContentType 'application/json' displayName: 'Send Slack notification' 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" - $body = '{"text": "Something went wrong while creating agent localization update PR. Build: ' + $buildUrl + '"}' + $body = '{"text": "Something went wrong while creating task-lib localization update PR. Build: ' + $buildUrl + '"}' Invoke-RestMethod -Uri $(slackUri) -Method Post -Body $body -ContentType 'application/json' displayName: 'Send Slack notification' condition: and(failed(), eq(variables['WEEK'], '3'), eq(variables['build.reason'], 'Schedule')) From 9900642f42cfb9934eaa17e73768023290d61fed Mon Sep 17 00:00:00 2001 From: Egor Bryzgalov Date: Thu, 18 Feb 2021 14:45:33 +0300 Subject: [PATCH 3/9] Update localize-pipeline.yml (cherry picked from commit 31bd6ae520ecb4b0e723a5f30549ac05ee7534fd) --- Localize/localize-pipeline.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Localize/localize-pipeline.yml b/Localize/localize-pipeline.yml index dd5bb0715..ff20df763 100644 --- a/Localize/localize-pipeline.yml +++ b/Localize/localize-pipeline.yml @@ -39,14 +39,14 @@ stages: - powershell: | $body = '{"text": "Created task-lib localization update PR. Someone please approve/merge it. :please-puss-in-boots:"}' Invoke-RestMethod -Uri $(slackUri) -Method Post -Body $body -ContentType 'application/json' - displayName: 'Send Slack notification' + 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" $body = '{"text": "Something went wrong while creating task-lib localization update PR. Build: ' + $buildUrl + '"}' Invoke-RestMethod -Uri $(slackUri) -Method Post -Body $body -ContentType 'application/json' - displayName: 'Send Slack notification' + displayName: 'Send Slack notification about error' condition: and(failed(), eq(variables['WEEK'], '3'), eq(variables['build.reason'], 'Schedule')) - task: PublishBuildArtifacts@1 From e8456c2b353fa940574e5f3f2df35ba68ce4d7f8 Mon Sep 17 00:00:00 2001 From: Egor Bryzgalov Date: Wed, 3 Mar 2021 21:51:57 +0300 Subject: [PATCH 4/9] Created PR opening script --- open-pullrequest.ps1 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/open-pullrequest.ps1 b/open-pullrequest.ps1 index 25afaa84d..cb7049e6f 100644 --- a/open-pullrequest.ps1 +++ b/open-pullrequest.ps1 @@ -9,7 +9,11 @@ function Get-PullRequest() { return $prInfo.html_url } +<<<<<<< HEAD $openedPR = Get-PullRequest +======= +$openedPR=Get-PullRequest +>>>>>>> 01e2015 (Create open-pullrequest.ps1) if ($openedPR.length -ne 0) { throw "A PR from $SourceBranch to master already exists." From 1761e4e0c7c772866d1c4af64da39eb1c5d531a7 Mon Sep 17 00:00:00 2001 From: Egor Bryzgalov Date: Wed, 3 Mar 2021 21:53:27 +0300 Subject: [PATCH 5/9] Applied anhancements (cherry picked from commit 319211d9fb08f8c79ce2cf90f1131a58dbeb044c) --- Localize/localize-pipeline.yml | 64 ++++++++++++++++++++++++++++------ 1 file changed, 54 insertions(+), 10 deletions(-) diff --git a/Localize/localize-pipeline.yml b/Localize/localize-pipeline.yml index ff20df763..b290aa50a 100644 --- a/Localize/localize-pipeline.yml +++ b/Localize/localize-pipeline.yml @@ -17,10 +17,23 @@ stages: pool: vmImage: windows-latest steps: + - checkout: self + persistCredentials: true + - powershell: | - $week = (Invoke-WebRequest https://whatsprintis.it -Headers @{"Accept"= "application/json"} | ConvertFrom-Json).week - Write-Host "##vso[task.setvariable variable=week]$week" - displayName: "Determine the number of the week in the sprint" + $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: @@ -32,23 +45,54 @@ stages: repoType: 'gitHub' prSourceBranchPrefix: 'Localize' gitHubPatVariable: '$(GitHubPAT)' - isAutoCompletePrSelected: false + isAutoCompletePrSelected: true 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: | - $body = '{"text": "Created task-lib localization update PR. Someone please approve/merge it. :please-puss-in-boots:"}' + $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')) + condition: and(failed(), eq(variables['WEEK'], '3'), eq(variables['build.reason'], 'Schedule')) - powershell: | $buildUrl = "$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_build/results?buildId=$(Build.BuildId)&_a=summary" - $body = '{"text": "Something went wrong while creating task-lib localization update PR. Build: ' + $buildUrl + '"}' + $message="Something went wrong while creating task-lib localization update PR. Build: $buildUrl" + $body = [PSCustomObject]@{ + text = $message + } | ConvertTo-Json + 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')) - - task: PublishBuildArtifacts@1 - displayName: 'Publish Artifact: drop' - From e1361fb2c7752e2f6845cc11322b7bf1431ed62a Mon Sep 17 00:00:00 2001 From: Egor Bryzgalov Date: Thu, 4 Mar 2021 09:34:38 +0300 Subject: [PATCH 6/9] Changed job name (cherry picked from commit 50f462fe6178a9e6f09e448c57cf2a777777563b) --- Localize/localize-pipeline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Localize/localize-pipeline.yml b/Localize/localize-pipeline.yml index b290aa50a..d4572b5f3 100644 --- a/Localize/localize-pipeline.yml +++ b/Localize/localize-pipeline.yml @@ -13,7 +13,7 @@ schedules: stages: - stage: __default jobs: - - job: Job1 + - job: LocalizationUpdate pool: vmImage: windows-latest steps: From 693bf29cd685473d465bca0bfa0af5e84bba72eb Mon Sep 17 00:00:00 2001 From: Egor Bryzgalov Date: Wed, 10 Mar 2021 13:30:57 +0300 Subject: [PATCH 7/9] Update localize-pipeline.yml (cherry picked from commit db1afe15b2feca810f21a746c5b50301b43a90a2) --- Localize/localize-pipeline.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Localize/localize-pipeline.yml b/Localize/localize-pipeline.yml index d4572b5f3..c74beff31 100644 --- a/Localize/localize-pipeline.yml +++ b/Localize/localize-pipeline.yml @@ -14,6 +14,7 @@ stages: - stage: __default jobs: - job: LocalizationUpdate + displayName: 'Update localization' pool: vmImage: windows-latest steps: @@ -46,6 +47,7 @@ stages: prSourceBranchPrefix: 'Localize' gitHubPatVariable: '$(GitHubPAT)' 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'))) @@ -83,7 +85,7 @@ stages: Invoke-RestMethod -Uri $(slackUri) -Method Post -Body $body -ContentType 'application/json' displayName: 'Send Slack notification about PR opened' - condition: and(failed(), eq(variables['WEEK'], '3'), eq(variables['build.reason'], 'Schedule')) + 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" From 5e521f8b454f48327b9207e5c27fdd29ef9c2164 Mon Sep 17 00:00:00 2001 From: Egor Bryzgalov Date: Thu, 11 Mar 2021 11:20:48 +0300 Subject: [PATCH 8/9] Fixed conflicts --- open-pullrequest.ps1 | 4 ---- 1 file changed, 4 deletions(-) diff --git a/open-pullrequest.ps1 b/open-pullrequest.ps1 index cb7049e6f..25afaa84d 100644 --- a/open-pullrequest.ps1 +++ b/open-pullrequest.ps1 @@ -9,11 +9,7 @@ function Get-PullRequest() { return $prInfo.html_url } -<<<<<<< HEAD $openedPR = Get-PullRequest -======= -$openedPR=Get-PullRequest ->>>>>>> 01e2015 (Create open-pullrequest.ps1) if ($openedPR.length -ne 0) { throw "A PR from $SourceBranch to master already exists." From e0ada7f01ea8be4e15bfdcdd4028e2564feda57e Mon Sep 17 00:00:00 2001 From: Egor Bryzgalov Date: Thu, 11 Mar 2021 17:34:53 +0300 Subject: [PATCH 9/9] Fixed notification --- open-pullrequest.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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"