Skip to content

Commit

Permalink
Update patch application logic
Browse files Browse the repository at this point in the history
  • Loading branch information
chidozieononiwu committed Sep 26, 2020
1 parent 4869aa7 commit b470244
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 24 deletions.
14 changes: 1 addition & 13 deletions eng/pipelines/eng-common-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,14 @@ stages:

steps:
- ${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
- task: PowerShell@2
displayName: 'Get alias of the Tools PR Creator'
inputs:
targetType: filePath
filePath: $(Build.SourcesDirectory)/eng/common/scripts/get-pr-creator.ps1
arguments: >
-RepoOwner "Azure"
-RepoName "azure-sdk-tools"
-PullRequestNumber "$(System.PullRequest.PullRequestNumber)"
-VsoPRCreatorVariable "System.PullRequest.Creator"
-AuthToken "$(azuresdk-github-pat)"
pwsh: true

- pwsh: |
Set-PsDebug -Trace 1
$patchDir = "$(Build.ArtifactStagingDirectory)/patchfiles"
$patchfiles = git format-patch --output-directory $patchDir HEAD...origin/$(system.pullRequest.targetBranch) -- "${{ parameters.DirectoryToSync }}"
if ($patchfiles -and ($LASTEXITCODE -eq 0)) {
echo "##vso[task.setvariable variable=PatchFilesLocation]$patchDir"
echo "Setting PatchFilesLocation"
ls $patchDir
}
else {
Write-Host "Failed to Create PatchFiles from Pull Request [https://github.com/Azure/azure-sdk-tools/pull/$(System.PullRequest.PullRequestNumber)]"
Expand Down
25 changes: 14 additions & 11 deletions eng/pipelines/templates/steps/sync-directory.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,22 @@ steps:
pushd ${{ repo }}
$results = @()
echo "##vso[task.setvariable variable=HasChanges]$false"
foreach ($file in (Get-ChildItem $(PatchFilesLocation)))
$shaBeforePatches = git rev-parse --short HEAD
Write-Host $shaBeforePatches
foreach ($file in (Get-ChildItem $(PatchFilesLocation)*.patch))
{
$results += git -c user.name="azure-sdk" -c user.email="azuresdk@microsoft.com" am $file.FullName
}
if (($results.Count -eq (Get-ChildItem $(PatchFilesLocation))) -and ($LASTEXITCODE -eq 0))
{
echo "##vso[task.setvariable variable=HasChanges]$true"
}
else
{
Write-Output "Failed to properly apply patch files to [https://github.com/azure/${{ repo }}]"
echo "##vso[task.setvariable variable=HasChanges]$false"
Write-Host $file.FullName
git -c user.name="azure-sdk" -c user.email="azuresdk@microsoft.com" am -3 $file.FullName
if ($lastExitCode -ne 0) {
git am --show-current-patch=diff
Write-Error "##vso[task.LogIssue type=warning;]Failed to properly apply patch files to [https://github.com/azure/${{ repo }}]"
exit 1
}
}
$shaAfterPatches = git rev-parse --short HEAD
Write-Host $shaAfterPatches
$hasChanges = $shaBeforePatches -ne $shaAfterPatches
echo "##vso[task.setvariable variable=HasChanges]$hasChanges"
}
else
{
Expand Down

0 comments on commit b470244

Please sign in to comment.