1
+ name : $(Date:MMddyy)$(Rev:.rrrr)
2
+
3
+ trigger : none
4
+
5
+ schedules :
6
+ - cron : 0 8 * * Mon # mm HH DD MM DW
7
+ displayName : Localization update
8
+ branches :
9
+ include :
10
+ - Localization
11
+ always : true
12
+
13
+ stages :
14
+ - stage : __default
15
+ jobs :
16
+ - job : LocalizationUpdate
17
+ pool :
18
+ vmImage : windows-latest
19
+ steps :
20
+
21
+ - checkout : self
22
+ persistCredentials : true
23
+
24
+ - powershell : |
25
+ $sprintInfo = Invoke-WebRequest https://whatsprintis.it -Headers @{"Accept"= "application/json"} | ConvertFrom-Json
26
+ if (($env:PR_CREATION_ENABLED -eq 'True') -and (($sprintInfo.week -eq 3) -or ($env:BUILD_REASON -eq 'Manual')))
27
+ {
28
+ Write-Host "shouldCreatePR was set to true"
29
+ Write-Host "##vso[task.setvariable variable=shouldCreatePR]$($true)"
30
+ }
31
+ else
32
+ {
33
+ Write-Host "shouldCreatePR was set to false"
34
+ Write-Host "##vso[task.setvariable variable=shouldCreatePR]$($false)"
35
+ }
36
+ displayName: "Determine the number of the week in the sprint and sprint number"
37
+ - powershell : |
38
+ git config --global user.email "$(github_email)"
39
+ git config --global user.name "$(username)"
40
+ git checkout -b Localization origin/Localization
41
+ git merge origin/master
42
+ git push origin Localization
43
+ displayName: "Sync with master branch"
44
+ condition: and(succeeded(), in(variables['build.reason'], 'Schedule', 'Manual'))
45
+ - task : OneLocBuild@2
46
+ condition : and(succeeded(), in(variables['build.reason'], 'Schedule', 'Manual'))
47
+ inputs :
48
+ locProj : ' Localize/LocProject.json'
49
+ outDir : ' $(Build.ArtifactStagingDirectory)'
50
+ packageSourceAuth : ' patAuth'
51
+ patVariable : ' $(OneLocBuildPAT)'
52
+ isCreatePrSelected : $(shouldCreatePR)
53
+ repoType : ' gitHub'
54
+ prSourceBranchPrefix : ' Localize'
55
+ gitHubPatVariable : ' $(GitHubPAT)'
56
+ isAutoCompletePrSelected : true
57
+ env :
58
+ SYSTEM_ACCESSTOKEN : $(System.AccessToken)
59
+
60
+ - task : PublishBuildArtifacts@1
61
+ condition : and(succeeded(), in(variables['build.reason'], 'Schedule', 'Manual'))
62
+ displayName : ' Publish an artifact'
63
+
64
+ - powershell : |
65
+ $date= Get-Date -Format "MMddyyyy"
66
+ $updateBranch="Localization-update_$date"
67
+ echo "##vso[task.setvariable variable=updateBranch]$updateBranch"
68
+ git checkout -b $updateBranch
69
+ Remove-Item -Recurse -Force Localize
70
+ git add -A
71
+ git commit -m "Removing Localize folder"
72
+ git push origin $updateBranch
73
+ displayName: Create and push localization update branch
74
+ condition: and(succeeded(), or(and(eq(variables['SHOULDCREATEPR'], 'True'), eq(variables['build.reason'], 'Schedule')), eq(variables['build.reason'], 'Manual')))
75
+
76
+ - task : PowerShell@2
77
+ inputs :
78
+ filePath : ' open-pullrequest.ps1'
79
+ arguments : " -SourceBranch $(updateBranch)"
80
+ failOnStderr : true
81
+ env :
82
+ GH_TOKEN : ' $(GitHubPAT)'
83
+ displayName : Open a PR
84
+ condition : and(succeeded(), or(and(eq(variables['SHOULDCREATEPR'], 'True'), eq(variables['build.reason'], 'Schedule')), eq(variables['build.reason'], 'Manual')))
85
+
86
+ - powershell : |
87
+ $message="Created tool-lib localization update PR. Someone please approve/merge it. :please-puss-in-boots: $env:PR_LINK"
88
+ $body = [PSCustomObject]@{
89
+ text = $message
90
+ } | ConvertTo-Json
91
+ Invoke-RestMethod -Uri $(slackUri) -Method Post -Body $body -ContentType 'application/json'
92
+ displayName: 'Send Slack notification about PR opened'
93
+ condition: and(succeeded(), eq(variables['SHOULDCREATEPR'], 'True'), eq(variables['build.reason'], 'Schedule'))
94
+ - powershell : |
95
+ $buildUrl = "$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_build/results?buildId=$(Build.BuildId)&_a=summary"
96
+ $message="Something went wrong while creating tool-lib localization update PR. Build: $buildUrl"
97
+ $body = [PSCustomObject]@{
98
+ text = $message
99
+ } | ConvertTo-Json
100
+ Invoke-RestMethod -Uri $(slackUri) -Method Post -Body $body -ContentType 'application/json'
101
+ displayName: 'Send Slack notification about error'
102
+ condition: and(failed(), eq(variables['SHOULDCREATEPR'], 'True'), eq(variables['build.reason'], 'Schedule'))
0 commit comments