| 1 |
Param( |
| 2 |
[string] $Repository, |
| 3 |
[string] $BranchName='master', |
| 4 |
[string] $GdnFolder, |
| 5 |
[string] $AzureDevOpsAccessToken, |
| 6 |
[string] $PushReason |
| 7 |
) |
| 8 |
|
| 9 |
$ErrorActionPreference = 'Stop' |
| 10 |
Set-StrictMode -Version 2.0 |
| 11 |
$disableConfigureToolsetImport = $true |
| 12 |
$LASTEXITCODE = 0 |
| 13 |
|
| 14 |
try { |
| 15 |
. $PSScriptRoot\..\tools.ps1 |
| 16 |
|
| 17 |
# We create the temp directory where we'll store the sdl-config repository |
| 18 |
$sdlDir = Join-Path $env:TEMP 'sdl' |
| 19 |
if (Test-Path $sdlDir) { |
| 20 |
Remove-Item -Force -Recurse $sdlDir |
| 21 |
} |
| 22 |
|
| 23 |
Write-Host "git clone https://dnceng:`[email protected]/dnceng/internal/_git/sdl-tool-cfg $sdlDir" |
| 24 |
git clone https://dnceng:[email protected]/dnceng/internal/_git/sdl-tool-cfg $sdlDir |
| 25 |
if ($LASTEXITCODE -ne 0) { |
| 26 |
Write-PipelineTelemetryError -Force -Category 'Sdl' -Message "Git clone failed with exit code $LASTEXITCODE." |
| 27 |
ExitWithExitCode $LASTEXITCODE |
| 28 |
} |
| 29 |
# We copy the .gdn folder from our local run into the git repository so it can be committed |
| 30 |
$sdlRepositoryFolder = Join-Path (Join-Path (Join-Path $sdlDir $Repository) $BranchName) '.gdn' |
| 31 |
if (Get-Command Robocopy) { |
| 32 |
Robocopy /S $GdnFolder $sdlRepositoryFolder |
| 33 |
} else { |
| 34 |
rsync -r $GdnFolder $sdlRepositoryFolder |
| 35 |
} |
| 36 |
# cd to the sdl-config directory so we can run git there |
| 37 |
Push-Location $sdlDir |
| 38 |
# git add . --> git commit --> git push |
| 39 |
Write-Host 'git add .' |
| 40 |
git add . |
| 41 |
if ($LASTEXITCODE -ne 0) { |
| 42 |
Write-PipelineTelemetryError -Force -Category 'Sdl' -Message "Git add failed with exit code $LASTEXITCODE." |
| 43 |
ExitWithExitCode $LASTEXITCODE |
| 44 |
} |
| 45 |
Write-Host "git -c user.email=`"[email protected]`" -c user.name=`"Dotnet Bot`" commit -m `"$PushReason for $Repository/$BranchName`"" |
| 46 |
git -c user.email="[email protected]" -c user.name="Dotnet Bot" commit -m "$PushReason for $Repository/$BranchName" |
| 47 |
if ($LASTEXITCODE -ne 0) { |
| 48 |
Write-PipelineTelemetryError -Force -Category 'Sdl' -Message "Git commit failed with exit code $LASTEXITCODE." |
| 49 |
ExitWithExitCode $LASTEXITCODE |
| 50 |
} |
| 51 |
Write-Host 'git push' |
| 52 |
git push |
| 53 |
if ($LASTEXITCODE -ne 0) { |
| 54 |
Write-PipelineTelemetryError -Force -Category 'Sdl' -Message "Git push failed with exit code $LASTEXITCODE." |
| 55 |
ExitWithExitCode $LASTEXITCODE |
| 56 |
} |
| 57 |
|
| 58 |
# Return to the original directory |
| 59 |
Pop-Location |
| 60 |
} |
| 61 |
catch { |
| 62 |
Write-Host $_.ScriptStackTrace |
| 63 |
Write-PipelineTelemetryError -Category 'Sdl' -Message $_ |
| 64 |
ExitWithExitCode 1 |
| 65 |
} |