Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync eng/common directory with azure-sdk-tools for PR 1477 #17589

Merged
merged 10 commits into from
Mar 27, 2021
54 changes: 11 additions & 43 deletions eng/common/pipelines/templates/steps/create-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,49 +23,17 @@ parameters:
OpenAsDraft: false

steps:

- pwsh: |
echo "git add -A"
git add -A

echo "git diff --name-status --cached --exit-code"
git diff --name-status --cached --exit-code

if ($LastExitCode -ne 0) {
echo "##vso[task.setvariable variable=HasChanges]$true"
echo "Changes detected so setting HasChanges=true"
}
else {
echo "##vso[task.setvariable variable=HasChanges]$false"
echo "No changes so skipping code push"
}
displayName: Check for changes
condition: and(succeeded(), eq(${{ parameters.SkipCheckingForChanges }}, false))
workingDirectory: ${{ parameters.WorkingDirectory }}
ignoreLASTEXITCODE: true

- pwsh: |
# Remove the repo owner from the front of the repo name if it exists there
$repoName = "${{ parameters.RepoName }}" -replace "^${{ parameters.RepoOwner }}/", ""
echo "##vso[task.setvariable variable=RepoNameWithoutOwner]$repoName"
echo "RepoName = $repoName"
displayName: Remove Repo Owner from Repo Name
condition: succeeded()
workingDirectory: ${{ parameters.WorkingDirectory }}

- task: PowerShell@2
displayName: Push changes
condition: and(succeeded(), eq(variables['HasChanges'], 'true'))
inputs:
pwsh: true
workingDirectory: ${{ parameters.WorkingDirectory }}
filePath: ${{ parameters.ScriptDirectory }}/git-branch-push.ps1
arguments: >
-PRBranchName "${{ parameters.PRBranchName }}"
-CommitMsg "${{ parameters.CommitMsg }}"
-GitUrl "https://$(azuresdk-github-pat)@github.com/${{ parameters.PROwner }}/$(RepoNameWithoutOwner).git"
-PushArgs "${{ parameters.PushArgs }}"
-SkipCommit $${{ parameters.SkipCheckingForChanges }}
- template: /eng/common/pipelines/templates/steps/git-push-changes.yml
parameters:
BaseRepoBranch: ${{ parameters.PRBranchName }}
BaseRepoOwner: ${{ parameters.PROwner }}
CommitMsg: ${{ parameters.CommitMsg }}
TargetRepoOwner: ${{ parameters.RepoOwner }}
TargetRepoName: ${{ parameters.RepoName }}
PushArgs: ${{ parameters.PushArgs }}
WorkingDirectory: ${{ parameters.WorkingDirectory }}
ScriptDirectory: ${{ parameters.ScriptDirectory }}
SkipCheckingForChanges: ${{ parameters.SkipCheckingForChanges }}

- task: PowerShell@2
displayName: Create pull request
Expand Down
47 changes: 14 additions & 33 deletions eng/common/pipelines/templates/steps/docs-metadata-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ parameters:
TargetDocRepoName: ''
TargetDocRepoOwner: ''
PRBranchName: 'master-rdme'
SourceBranchName: 'master'
PRLabels: 'auto-merge'
ArtifactName: ''
Language: ''
Expand All @@ -34,18 +33,11 @@ steps:

- pwsh: |
git clone https://github.com/${{ parameters.TargetDocRepoOwner }}/${{ parameters.TargetDocRepoName }} ${{ parameters.WorkingDirectory }}/repo

try {
Push-Location ${{ parameters.WorkingDirectory }}/repo

Write-Host "git checkout ${{ parameters.SourceBranchName }}"
git checkout ${{ parameters.SourceBranchName }}
} finally {
Pop-Location
}
displayName: Clone Documentation Repository
ignoreLASTEXITCODE: false

- template: /eng/common/pipelines/templates/steps/set-default-branch.yml
parameters:
WorkingDirectory: ${{ parameters.WorkingDirectory }}/repo
- task: PowerShell@2
displayName: 'Apply Documentation Updates From Artifact'
inputs:
Expand Down Expand Up @@ -82,25 +74,19 @@ steps:
env:
GH_TOKEN: $(azuresdk-github-pat)

- template: /eng/common/pipelines/templates/steps/create-pull-request.yml
- template: /eng/common/pipelines/templates/steps/git-push-changes.yml
parameters:
RepoName: ${{ parameters.TargetDocRepoName }}
RepoOwner: ${{ parameters.TargetDocRepoOwner }}
PRBranchName: ${{ parameters.PRBranchName }}
BaseRepoBranch: $(DefaultBranch)
BaseRepoOwner: ${{ parameters.TargetDocRepoOwner }}
CommitMsg: "Update docs metadata and targeting for release of ${{ parameters.ArtifactName }}"
PRTitle: "Docs.MS Release Updates for ${{ parameters.ArtifactName }}"
BaseBranchName: ${{ parameters.SourceBranchName }}
TargetRepoName: ${{ parameters.TargetDocRepoName }}
TargetRepoOwner: ${{ parameters.TargetDocRepoOwner }}
WorkingDirectory: ${{ parameters.WorkingDirectory }}/repo
ScriptDirectory: ${{ parameters.WorkingDirectory }}/${{ parameters.ScriptDirectory }}
GHReviewersVariable: ${{ parameters.GHReviewersVariable }}
GHTeamReviewersVariable: ${{ parameters.GHTeamReviewersVariable }}
PRLabels: ${{ parameters.PRLabels }}
CloseAfterOpenForTesting: ${{ parameters.CloseAfterOpenForTesting }}

- ${{if ne( parameters['OnboardingBranch'], '')}}:
- pwsh: |
Push-Location ${{ parameters.WorkingDirectory }}/repo

git reset --hard HEAD
git remote rm azure-sdk-fork
git checkout ${{ parameters.OnboardingBranch}}
Expand All @@ -123,17 +109,12 @@ steps:
pwsh: true
env:
GH_TOKEN: $(azuresdk-github-pat)

- template: /eng/common/pipelines/templates/steps/create-pull-request.yml
- template: /eng/common/pipelines/templates/steps/git-push-changes.yml
parameters:
RepoName: ${{ parameters.TargetDocRepoName }}
RepoOwner: ${{ parameters.TargetDocRepoOwner }}
PRBranchName: ${{ parameters.PRBranchName }}-ci
CommitMsg: "CI Update for release of ${{ parameters.ArtifactName }}"
PRTitle: "Docs.MS CI Updates for ${{ parameters.ArtifactName }}"
BaseBranchName: ${{ parameters.OnboardingBranch }}
BaseRepoBranch: ${{ parameters.OnboardingBranch}}
BaseRepoOwner: ${{ parameters.TargetDocRepoOwner }}
CommitMsg: "Update docs metadata and targeting for release of ${{ parameters.ArtifactName }}"
TargetRepoName: ${{ parameters.TargetDocRepoName }}
TargetRepoOwner: ${{ parameters.TargetDocRepoOwner }}
WorkingDirectory: ${{ parameters.WorkingDirectory }}/repo
ScriptDirectory: ${{ parameters.WorkingDirectory }}/${{ parameters.ScriptDirectory }}
GHReviewersVariable: ${{ parameters.GHReviewersVariable }}
GHTeamReviewersVariable: ${{ parameters.GHTeamReviewersVariable }}
CloseAfterOpenForTesting: ${{ parameters.CloseAfterOpenForTesting }}
54 changes: 54 additions & 0 deletions eng/common/pipelines/templates/steps/git-push-changes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
parameters:
BaseRepoBranch: not-specified
BaseRepoOwner: azure-sdk
CommitMsg: not-specified
TargetRepoOwner: Azure
TargetRepoName: $(Build.Repository.Name)
PushArgs:
WorkingDirectory: $(System.DefaultWorkingDirectory)'
ScriptDirectory: eng/common/scripts
SkipCheckingForChanges: false

steps:
- pwsh: |
echo "git add -A"
git add -A

echo "git diff --name-status --cached --exit-code"
git diff --name-status --cached --exit-code

if ($LastExitCode -ne 0) {
echo "##vso[task.setvariable variable=HasChanges]$true"
echo "Changes detected so setting HasChanges=true"
}
else {
echo "##vso[task.setvariable variable=HasChanges]$false"
echo "No changes so skipping code push"
}
displayName: Check for changes
condition: and(succeeded(), eq(${{ parameters.SkipCheckingForChanges }}, false))
workingDirectory: ${{ parameters.WorkingDirectory }}
ignoreLASTEXITCODE: true

- pwsh: |
# Remove the repo owner from the front of the repo name if it exists there
$repoName = "${{ parameters.TargetRepoName }}" -replace "^${{ parameters.TargetRepoOwner }}/", ""
echo "##vso[task.setvariable variable=RepoNameWithoutOwner]$repoName"
echo "RepoName = $repoName"
displayName: Remove Repo Owner from Repo Name
condition: succeeded()
workingDirectory: ${{ parameters.WorkingDirectory }}

- task: PowerShell@2
displayName: Push changes
condition: and(succeeded(), eq(variables['HasChanges'], 'true'))
inputs:
pwsh: true
workingDirectory: ${{ parameters.WorkingDirectory }}
filePath: ${{ parameters.ScriptDirectory }}/git-branch-push.ps1
arguments: >
-PRBranchName "${{ parameters.BaseRepoBranch }}"
-CommitMsg "${{ parameters.CommitMsg }}"
-GitUrl "https://$(azuresdk-github-pat)@github.com/${{ parameters.BaseRepoOwner }}/$(RepoNameWithoutOwner).git"
-PushArgs "${{ parameters.PushArgs }}"
-SkipCommit $${{ parameters.SkipCheckingForChanges }}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ steps:
echo "##vso[task.setvariable variable=DefaultBranch]$setDefaultBranch"
displayName: "Setup Default Branch"
workingDirectory: ${{ parameters.workingDirectory }}
condition: eq(variables['DefaultBranch'], '')
49 changes: 32 additions & 17 deletions eng/common/scripts/git-branch-push.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ param(
[Parameter(Mandatory = $false)]
[string] $PushArgs = "",

[Parameter(Mandatory = $false)]
[string] $RemoteName = "azure-sdk-fork",

[Parameter(Mandatory = $false)]
Expand All @@ -41,27 +42,36 @@ param(
# would fail the first time git wrote command output.
$ErrorActionPreference = "Continue"

if (!(git remote | ? {$_ -eq $RemoteName}))
if ((git remote) -contains $RemoteName)
{
Write-Host "git remote add $RemoteName $GitUrl"
git remote add $RemoteName $GitUrl
if ($LASTEXITCODE -ne 0)
{
Write-Error "Unable to add remote LASTEXITCODE=$($LASTEXITCODE), see command output above."
exit $LASTEXITCODE
}
Write-Host "git remote get-url $RemoteName"
$remoteUrl = git remote get-url $RemoteName
if ($remoteUrl -ne $GitUrl)
{
Write-Error "Remote with name $RemoteName already exists with an incompatible url [$remoteUrl] which should be [$GitUrl]."
exit 1
}
}

Write-Host "git fetch $RemoteName"
git fetch $RemoteName
if ($LASTEXITCODE -ne 0)
else
{
Write-Error "Unable to fetch remote LASTEXITCODE=$($LASTEXITCODE), see command output above."
Write-Host "git remote add $RemoteName $GitUrl"
git remote add $RemoteName $GitUrl
if ($LASTEXITCODE -ne 0)
{
Write-Error "Unable to add remote LASTEXITCODE=$($LASTEXITCODE), see command output above."
exit $LASTEXITCODE
}
}
# Checkout to $PRBranch, create new one if not exists.
git show-ref --verify --quiet refs/heads/$PRBranchName
if ($LASTEXITCODE -eq 0) {
Write-Host "git checkout $PRBranchName."
git checkout $PRBranchName
}
else {
Write-Host "git checkout -b $PRBranchName."
git checkout -b $PRBranchName
}

Write-Host "git checkout -b $PRBranchName"
git checkout -b $PRBranchName
if ($LASTEXITCODE -ne 0)
{
Write-Error "Unable to create branch LASTEXITCODE=$($LASTEXITCODE), see command output above."
Expand Down Expand Up @@ -105,6 +115,7 @@ do
{
$needsRetry = $true
Write-Host "Git push failed with LASTEXITCODE=$($LASTEXITCODE) Need to fetch and rebase: attempt number=$($tryNumber)"

Write-Host "git fetch $RemoteName"
git fetch $RemoteName
if ($LASTEXITCODE -ne 0)
Expand Down Expand Up @@ -168,8 +179,12 @@ do
}
} while($needsRetry -and $tryNumber -le $numberOfRetries)

if ($LASTEXITCODE -ne 0)
if ($LASTEXITCODE -ne 0 -or $tryNumber -gt $numberOfRetries)
{
Write-Error "Unable to push commit after $($tryNumber) retries LASTEXITCODE=$($LASTEXITCODE), see command output above."
if (0 -eq $LASTEXITCODE)
{
exit 1
}
exit $LASTEXITCODE
}