Skip to content

Commit 3d75db1

Browse files
authored
Remove GitHub Token From CI Pipeline (Azure#26602)
Remove GitHub Token From CI Pipeline
1 parent 3413229 commit 3d75db1

File tree

5 files changed

+37
-17
lines changed

5 files changed

+37
-17
lines changed

.azure-pipelines/security-tools.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
steps:
2020
- checkout: self
2121
fetchTags: false
22-
- template: util/get-github-pat-steps.yml
22+
- template: util/get-pr-changed-files.yml
2323
- task: PowerShell@2
2424
displayName: Install platyPS
2525
inputs:
@@ -43,8 +43,6 @@ jobs:
4343
inputs:
4444
targetType: inline
4545
script: dotnet msbuild build.proj /t:"Build;GenerateHelp" /p:"PullRequestNumber=$(System.PullRequest.PullRequestNumber);IsSecurityCheck=true"
46-
env:
47-
OCTOKITPAT: $(GithubToken)
4846
- task: securedevelopmentteam.vss-secure-development-tools.build-task-credscan.CredScan@3
4947
displayName: Run CredScan
5048
inputs:

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ parameters:
55

66
steps:
77
- checkout: self
8-
persistCredentials: true
9-
- template: get-github-token-steps.yml
8+
- template: get-pr-changed-files.yml
109
- task: NodeTool@0
1110
condition: eq(variables.IsGenerateBased, true)
1211
displayName: Install Autorest
@@ -39,7 +38,6 @@ steps:
3938
custom: msbuild
4039
arguments: 'build.proj /t:Build /p:Configuration=${{ parameters.configuration }};TestFramework=${{ parameters.testFramework }};PullRequestNumber=$(System.PullRequest.PullRequestNumber)'
4140
env:
42-
OCTOKITPAT: $(GithubToken)
4341
PowerShellPlatform: ${{ parameters.powerShellPlatform }}
4442

4543
- task: PowerShell@2
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
steps:
2+
- task: PowerShell@2
3+
displayName: List PR Changed Files
4+
inputs:
5+
targetType: inline
6+
pwsh: true
7+
script: |
8+
# refer to https://learn.microsoft.com/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml#system-variables-devops-services
9+
# get the target branch name
10+
$targetBranch = $(System.PullRequest.TargetBranch)
11+
# fetch the targetBranch from origin to local branch and rename the branch to 'origin/base'
12+
git fetch --no-tags origin "${targetBranch}:origin/base"
13+
# refer to https://git-scm.com/docs/git-diff
14+
# compare the pr and targetBranch branch, get the changed file list
15+
# diff-filter options are ACMRT, which are: Added, Copied, Modified, Renamed , Changed
16+
$changedFiles = git --no-pager diff --name-only --diff-filter=ACMRT origin/base -- .
17+
Write-Host "Total updated files:" $changedFiles.Count
18+
Write-Host "All Updated files:"
19+
$changedFiles | Foreach-Object {Write-Host $_}
20+
$RepoArtifacts = 'artifacts'
21+
if(-not (Test-Path $RepoArtifacts)){
22+
New-Item -ItemType Directory -Name $RepoArtifacts
23+
}
24+
$changedFiles | Out-File $RepoArtifacts/FilesChanged.txt

build.proj

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@
106106
<UsingTask Condition="$(OnPremiseBuild)" TaskName="CorporateValidation" AssemblyFile="$(CIToolsPath)/Microsoft.WindowsAzure.Tools.Build.Tasks.OnPremise.dll" />
107107
<Import Condition="$(OnPremiseBuild)" Project="$(CIToolsPath)/Microsoft.WindowsAzure.Build.OnPremise.msbuild" />
108108
<UsingTask TaskName="ESRPSignTask" AssemblyFile="$(CISignRepoPath)/tools/sdkbuildtools/tasks/MS.Az.Sdk.OnPremise.Build.Tasks.dll" />
109-
<UsingTask TaskName="FilesChangedTask" AssemblyFile="$(RepoArtifacts)Microsoft.Azure.Build.Tasks/Microsoft.Azure.Build.Tasks.dll" />
110109
<UsingTask TaskName="CIFilterTask" AssemblyFile="$(RepoArtifacts)Microsoft.Azure.Build.Tasks/Microsoft.Azure.Build.Tasks.dll" />
111110

112111
<Target Name="Clean">
@@ -131,16 +130,11 @@
131130
<!-- Build the Microsoft.Azure.Build.Tasks project -->
132131
<Exec Command="dotnet publish $(RepoTools)BuildPackagesTask/Microsoft.Azure.Build.Tasks/Microsoft.Azure.Build.Tasks.csproj -c $(Configuration)" />
133132

134-
<!-- Get all of the files changed in the given pull request -->
135-
<FilesChangedTask RepositoryOwner="Azure" RepositoryName="azure-powershell" PullRequestNumber="$(PullRequestNumber)" OutputFile="$(RepoArtifacts)FilesChanged.txt">
136-
<Output TaskParameter="FilesChanged" ItemName="FilesChanged" />
137-
</FilesChangedTask>
138-
139133
<Exec Command="$(PowerShellCoreCommandPrefix) &quot;$(RepoTools)PrepareAutorestModule.ps1&quot;" Condition="'$(IsGenerateBased)' == 'true'"/>
140134
<Exec Command="$(PowerShellCoreCommandPrefix) &quot;$(RepoTools)CreateFilterMappings.ps1&quot;" />
141135
<Exec Command="$(PowerShellCoreCommandPrefix) &quot;$(RepoTools)PrepareForSecurityCheck.ps1&quot;" Condition="'$(IsSecurityCheck)' == 'true'"/>
142136

143-
<CIFilterTask FilesChanged="@(FilesChanged)" Mode="$(Configuration)" CsprojMapFilePath="./CsprojMappings.json">
137+
<CIFilterTask FilesChangedFile="$(RepoArtifacts)FilesChanged.txt" Mode="$(Configuration)" CsprojMapFilePath="./CsprojMappings.json">
144138
<Output TaskParameter="BuildCsprojList" ItemName="BuildCsprojList" />
145139
<Output TaskParameter="TestCsprojList" ItemName="TestCsprojList" />
146140
<Output TaskParameter="SubTasks" PropertyName="SubTasks" />
@@ -341,4 +335,4 @@ $(RepoArtifacts)$(Configuration)/**/Microsoft.Azure.PowerShell.Authenticators.dl
341335
<SetEnvVar EnvName="SignedMsiDir" EnvValue="$(SignedOutputRootDir)" />
342336
</Target>
343337

344-
</Project>
338+
</Project>

tools/BuildPackagesTask/Microsoft.Azure.Build.Tasks/CIFilterTask.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,15 @@ namespace Microsoft.WindowsAzure.Build.Tasks
3232
public class CIFilterTask : Task
3333
{
3434
/// <summary>
35-
/// Gets or sets the files changed in a given pull request.
35+
/// Gets or set the OutputFile, store FilesChanged.txt in 'artifacts' folder
3636
/// </summary>
3737
[Required]
38-
public string[] FilesChanged { get; set; }
38+
public string FilesChangedFile { get; set; }
39+
40+
/// <summary>
41+
/// Changed File List
42+
/// </summary>
43+
private string[] FilesChanged { get; set; }
3944

4045
/// <summary>
4146
/// Gets or set the Mode, e.g. Release
@@ -186,7 +191,7 @@ private string ProcessSinglePattern(string pattern)
186191
private Dictionary<string, HashSet<string>> CalculateInfluencedModuleInfoForEachPhase(List<(Regex, List<string>)> ruleList, Dictionary<string, string[]> csprojMap)
187192
{
188193
Dictionary<string, HashSet<string>> influencedModuleInfo = new Dictionary<string, HashSet<string>>();
189-
194+
190195
foreach (string filePath in FilesChanged)
191196
{
192197
List<string> phaseList = new List<string>();
@@ -422,6 +427,7 @@ public override bool Execute()
422427
SubTasks = "";
423428
var csprojMap = ReadMapFile(CsprojMapFilePath, "CsprojMapFilePath");
424429

430+
FilesChanged = File.ReadAllLines(FilesChangedFile);
425431
Console.WriteLine(string.Format("FilesChanged: {0}", FilesChanged.Length));
426432
if (FilesChanged != null)
427433
{

0 commit comments

Comments
 (0)