Skip to content

Commit 26083d9

Browse files
YanaXuazure-powershell-bot
authored andcommitted
[CI] remove github pat usage (#25605)
1 parent 968fb55 commit 26083d9

File tree

5 files changed

+17
-144
lines changed

5 files changed

+17
-144
lines changed

.azure-pipelines/code-gen.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ jobs:
2121
pool: pool-windows-2019
2222
steps:
2323
- checkout: self
24-
- template: util/get-github-pat-steps.yml
24+
persistCredentials: true
25+
- template: util/get-github-token-steps.yml
2526
- task: NodeTool@0
2627
displayName: Use Node 14.15.5
2728
inputs:

.azure-pipelines/util/analyze-steps.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ parameters:
55
IsGenerateBased: ''
66

77
steps:
8-
- template: get-github-pat-steps.yml
98
- template: download-build-steps.yml
109
parameters:
1110
artifactName: build-${{ parameters.testFramework }}
@@ -50,7 +49,6 @@ steps:
5049
custom: msbuild
5150
arguments: 'build.proj /t:GenerateHelp /p:Configuration=${{ parameters.configuration }};PullRequestNumber=$(System.PullRequest.PullRequestNumber)'
5251
env:
53-
OCTOKITPAT: $(GithubToken)
5452
PowerShellPlatform: ${{ parameters.powerShellPlatform }}
5553

5654
- task: DotNetCoreCLI@2
@@ -60,7 +58,6 @@ steps:
6058
custom: msbuild
6159
arguments: 'build.proj /t:StaticAnalysis /p:Configuration=${{ parameters.configuration }};PullRequestNumber=$(System.PullRequest.PullRequestNumber)'
6260
env:
63-
OCTOKITPAT: $(GithubToken)
6461
IsGenerateBased: ${{ parameters.IsGenerateBased }}
6562

6663
- template: publish-artifacts-steps.yml

.azure-pipelines/util/build-steps.yml

Lines changed: 3 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -6,144 +6,9 @@ parameters:
66
ForceRegenerate: false
77

88
steps:
9-
- template: get-github-pat-steps.yml
10-
- task: PowerShell@2
11-
displayName: 'Check Ignored File'
12-
inputs:
13-
filePath: tools/CheckIgnoredFile.ps1
14-
- task: UseDotNet@2
15-
displayName: 'Use .NET Core sdk 6.0.x'
16-
inputs:
17-
packageType: sdk
18-
version: 6.0.x
19-
- task: PowerShell@2
20-
displayName: 'Set files changed trigger'
21-
inputs:
22-
targetType: inline
23-
pwsh: true
24-
script: |
25-
$subTasksFilePath = Join-Path "$(Build.SourcesDirectory)" 'artifacts' 'SubTasksFile.txt'
26-
Write-Host "##vso[task.setvariable variable=SubTasksFilePath]$subTasksFilePath"
27-
28-
$filesChangedOutputPath = Join-Path "$(Build.SourcesDirectory)" 'artifacts' 'FilesChanged.txt'
29-
Write-Host "##vso[task.setvariable variable=FilesChangedOutputPath]$filesChangedOutputPath"
30-
31-
$reason = "$(Build.Reason)"
32-
switch ($reason) {
33-
{ $reason -in @('IndividualCI', 'BatchedCI') } {
34-
$trigger = "$(Build.SourceVersion)"
35-
$triggerType = 'Commit'
36-
break
37-
}
38-
'PullRequest' {
39-
$trigger = "$(System.PullRequest.PullRequestNumber)"
40-
$triggerType = 'PullRequest'
41-
break
42-
}
43-
{ $reason -in @('Manual', 'Schedule') } {
44-
$targetModule = "${{ parameters.TargetModule }}"
45-
if ('' -eq $targetModule) {
46-
$notModules = @('lib', 'shared')
47-
$src = Join-Path "$(Build.SourcesDirectory)" 'src'
48-
$trigger = Get-Childitem -Path $src -Directory | ForEach-Object {
49-
if ($_.Name -in $notModules) {
50-
return
51-
}
52-
return Join-Path $_.Parent.Name $_.Name
53-
} | Join-String -Separator ','
54-
} else {
55-
$trigger = $targetModule.Split(',') | ForEach-Object { Join-Path 'src' $_ } | Join-String -Separator ','
56-
}
57-
$triggerType = 'TargetModule'
58-
break
59-
}
60-
default {
61-
$triggerType = Null
62-
break
63-
}
64-
}
65-
Write-Host "##vso[task.setvariable variable=TriggerType]$triggerType"
66-
Write-Host "##vso[task.setvariable variable=Trigger]$trigger"
67-
Write-Host "##[section]Filter files triggered by ${reason}: ${trigger}" -ForegroundColor DarkYellow
68-
- task: PowerShell@2
69-
displayName: 'Create branch for CI/Manual/Schedule triggered pipeline'
70-
condition: or(eq(variables.TriggerType, 'Commit'), eq(variables.TriggerType, 'TargetModule'))
71-
inputs:
72-
targetType: inline
73-
pwsh: true
74-
script: |
75-
$baseBranchName = "origin/$(Build.SourceBranchName)"
76-
$tmpBranchName = "archive/$(Build.SourceBranchName)/$(Build.Reason)"
77-
if ('Commit' -eq "$(TriggerType)") {
78-
$tmpBranchName += "/$(Trigger)"
79-
}
80-
Write-Host "##vso[task.setvariable variable=TmpBranchName]$tmpBranchName"
81-
Write-Host "##vso[task.setvariable variable=BaseBranchName]$baseBranchName"
82-
Write-Host "##[section]Switch from $baseBranchName to $tmpBranchName"
83-
git fetch origin $(Build.SourceBranchName)
84-
git checkout -b $tmpBranchName $baseBranchName
85-
- task: DotNetCoreCLI@2
86-
displayName: Filter changed files
87-
inputs:
88-
command: custom
89-
custom: msbuild
90-
arguments: 'build.proj /t:FilterBuild /p:TriggerType=$(TriggerType);Trigger=$(Trigger);FilesChangedOutputPath=$(FilesChangedOutputPath);SubTasksFilePath=$(SubTasksFilePath)'
91-
env:
92-
OCTOKITPAT: $(GithubToken)
93-
PowerShellPlatform: ${{ parameters.PowerShellPlatform }}
94-
- task: PowerShell@2
95-
displayName: 'Set subtasks if any'
96-
inputs:
97-
targetType: inline
98-
pwsh: true
99-
script: |
100-
if (Test-Path $(SubTasksFilePath)) {
101-
Get-Content $(SubTasksFilePath) | ForEach-Object {
102-
if ($_ && 'Predictor' -eq $_) {
103-
Write-Host "##vso[task.setvariable variable=SubTaskPredictor]true"
104-
} elseif ($_ && 'Installer' -eq $_) {
105-
Write-Host "##vso[task.setvariable variable=SubTaskInstaller]true"
106-
} elseif ($_ && 'all' -eq $_) {
107-
Write-Host "##vso[task.setvariable variable=SubTaskAll]true"
108-
}
109-
}
110-
}
111-
- task: PowerShell@2
112-
displayName: 'Analyze Pull Request'
113-
condition: eq(variables.TriggerType, 'PullRequest')
114-
inputs:
115-
targetType: inline
116-
pwsh: true
117-
script: |
118-
Write-Host "##[group]#1. Check generate-info.json for autorest generated modules"
119-
$noGenerateInfo = @()
120-
$modules=Get-Content $(FilesChangedOutputPath) -OutVariable paths | Foreach-Object { if($_ -match "^src.*\.Autorest"){ Write-Output $Matches[0] } } | Select-Object -Unique
121-
foreach ($module in $modules) {
122-
$hasGenerateInfo = $false
123-
$pattern = "^$module/generate-info.json"
124-
foreach ($path in $paths) {
125-
if ($path -match $pattern) {
126-
$hasGenerateInfo = $true
127-
}
128-
}
129-
if (-not $hasGenerateInfo) {
130-
$noGenerateInfo += $module
131-
}
132-
}
133-
if ($noGenerateInfo -and $noGenerateInfo.Count -gt 0) {
134-
$noGenerateInfo | Foreach-Object { Write-Error "No generate-info.json detected for $_" }
135-
exit 1
136-
}
137-
Write-Host "##[endgroup]"
138-
139-
Write-Host "##[group]#2. PR should contain changes from either /src or /generated only"
140-
$srcFiles = Get-Content $(FilesChangedOutputPath) | Where-Object { $_ -match "^src.*" }
141-
$generatedFiles = Get-Content $(FilesChangedOutputPath) | Where-Object { $_ -match "^generated.*" }
142-
if ($srcFiles -and $srcFiles.Count -gt 0 -and $generatedFiles -and $generatedFiles.Count -gt 0) {
143-
Write-Error "PR should contain changes from either /src or /generated only"
144-
exit 1
145-
}
146-
Write-Host "##[endgroup]"
9+
- checkout: self
10+
persistCredentials: true
11+
- template: get-github-token-steps.yml
14712
- task: NodeTool@0
14813
displayName: Install Autorest
14914
inputs:
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
steps:
2+
- task: PowerShell@2
3+
displayName: Get GitHub Token
4+
inputs:
5+
targetType: 'inline'
6+
script: |
7+
$httpConfigs = (git config --get-regexp "http" )
8+
$authConfig = $httpConfigs | Where-Object {$_ -like "*AUTHORIZATION*"}
9+
$token = ($authConfig -split ' ')[-1]
10+
$ghToken = ([System.Text.Encoding]::ASCII.GetString([System.Convert]::FromBase64String($token)) -split ':')[1]
11+
Write-Host "##vso[task.setvariable variable=GithubToken;issecret=true]$ghToken"
12+

.azure-pipelines/util/test-steps.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ parameters:
66
powerShellPlatform: ''
77

88
steps:
9-
- template: get-github-pat-steps.yml
109
- template: download-build-steps.yml
1110
parameters:
1211
artifactName: build-${{ parameters.testFramework }}
@@ -31,7 +30,6 @@ steps:
3130
custom: msbuild
3231
arguments: 'build.proj /t:${{ parameters.testTarget }} /p:Configuration=${{ parameters.configuration }};TestFramework=${{ parameters.testFramework }};PullRequestNumber=$(System.PullRequest.PullRequestNumber)'
3332
env:
34-
OCTOKITPAT: $(GithubToken)
3533
PowerShellPlatform: ${{ parameters.powerShellPlatform }}
3634
continueOnError: true
3735

0 commit comments

Comments
 (0)