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

Checked in code to some branch directly #1477

Merged
13 commits merged 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
41 changes: 11 additions & 30 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'
sima-zhu marked this conversation as resolved.
Show resolved Hide resolved
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 }}"
sima-zhu marked this conversation as resolved.
Show resolved Hide resolved
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:
BaseRepoBranch: $(DefaultBranch)
CommitMsg: "Update docs metadata and targeting for release of ${{ parameters.ArtifactName }}"
RepoName: ${{ parameters.TargetDocRepoName }}
RepoOwner: ${{ parameters.TargetDocRepoOwner }}
PRBranchName: ${{ parameters.PRBranchName }}
CommitMsg: "Update docs metadata and targeting for release of ${{ parameters.ArtifactName }}"
PRTitle: "Docs.MS Release Updates for ${{ parameters.ArtifactName }}"
BaseBranchName: ${{ parameters.SourceBranchName }}
WorkingDirectory: ${{ parameters.WorkingDirectory }}/repo
ScriptDirectory: ${{ parameters.WorkingDirectory }}/${{ parameters.ScriptDirectory }}
GHReviewersVariable: ${{ parameters.GHReviewersVariable }}
sima-zhu marked this conversation as resolved.
Show resolved Hide resolved
GHTeamReviewersVariable: ${{ parameters.GHTeamReviewersVariable }}
PRLabels: ${{ parameters.PRLabels }}
CloseAfterOpenForTesting: ${{ parameters.CloseAfterOpenForTesting }}
PROwner: ${{ parameters.TargetDocRepoOwner }}

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

git reset --hard HEAD
git remote rm azure-sdk-fork
sima-zhu marked this conversation as resolved.
Show resolved Hide resolved
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:
BaseRepoBranch: ${{ parameters.OnboardingBranch}}
CommitMsg: "Update docs metadata and targeting for release of ${{ parameters.ArtifactName }}"
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 }}
WorkingDirectory: ${{ parameters.WorkingDirectory }}/repo
ScriptDirectory: ${{ parameters.WorkingDirectory }}/${{ parameters.ScriptDirectory }}
GHReviewersVariable: ${{ parameters.GHReviewersVariable }}
GHTeamReviewersVariable: ${{ parameters.GHTeamReviewersVariable }}
CloseAfterOpenForTesting: ${{ parameters.CloseAfterOpenForTesting }}
PROwner: ${{ parameters.TargetDocRepoOwner }}
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:
sima-zhu marked this conversation as resolved.
Show resolved Hide resolved
- 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.RepoTargetRepoNameName }}" -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'], '')
sima-zhu marked this conversation as resolved.
Show resolved Hide resolved
50 changes: 31 additions & 19 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,33 +42,40 @@ param(
# would fail the first time git wrote command output.
$ErrorActionPreference = "Continue"

if (!(git remote | ? {$_ -eq $RemoteName}))
sima-zhu marked this conversation as resolved.
Show resolved Hide resolved
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.
weshaggard marked this conversation as resolved.
Show resolved Hide resolved
Write-Host "git checkout $PRBranchName."
sima-zhu marked this conversation as resolved.
Show resolved Hide resolved
git show-ref --verify --quiet refs/heads/$PRBranchName
if ($LASTEXITCODE -eq 0) {
git checkout $PRBranchName
}
else {
git checkout -b $PRBranchName
sima-zhu marked this conversation as resolved.
Show resolved Hide resolved
}

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."
sima-zhu marked this conversation as resolved.
Show resolved Hide resolved
exit $LASTEXITCODE
}

sima-zhu marked this conversation as resolved.
Show resolved Hide resolved
if (!$SkipCommit) {
if ($AmendCommit) {
$amendOption = "--amend"
Expand Down Expand Up @@ -105,6 +113,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 All @@ -123,7 +132,6 @@ do
Write-Error "Unable to create diff file LASTEXITCODE=$($LASTEXITCODE), see command output above."
continue
}

sima-zhu marked this conversation as resolved.
Show resolved Hide resolved
Write-Host "git reset --hard $RemoteName/${PRBranchName}"
git reset --hard $RemoteName/${PRBranchName}
if ($LASTEXITCODE -ne 0)
Expand Down Expand Up @@ -168,8 +176,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
weshaggard marked this conversation as resolved.
Show resolved Hide resolved
}