Created
September 23, 2019 17:50
-
-
Save abock/af01cfec8c6ed7627660b1767ba5ef8b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env pwsh | |
$ErrorActionPreference = "stop" | |
$targetBranch = "$(Insertion.TargetBranch)" | |
if (-not $targetBranch) { | |
$targetBranch = $env:BUILD_SOURCEBRANCHNAME | |
} | |
Function _Git | |
{ | |
& git @Args | |
if ($LASTEXITCODE -ne 0) { | |
Write-Error "'git $Args' exited $LASTEXITCODE" | |
} | |
} | |
$addinName = $env:BUILD_REPOSITORY_NAME.ToLower() | |
$pullRequestBranch = "insertions/$addinName/$($env:BUILD_SOURCEVERSION.Substring(0, 8))-$env:BUILD_SOURCEBRANCHNAME" | |
$mpackFile = @(Get-ChildItem -Recurse *.mpack)[0] | |
$mpackUrl = "https://bosstoragemirror.blob.core.windows.net/vsmac/$addinName/$($mpackFile.Name)" | |
Write-Host "Found mpack: $($mpackFile.FullName)" | |
Write-Host " To be available at: $mpackUrl" | |
Write-Host "##vso[task.setvariable variable=InsertionFileToUpload]$($mpackFile.FullName)" | |
_Git clone "https://$(Github.Token)@github.com/xamarin/md-addins" -b $targetBranch | |
Set-Location -Path md-addins | |
_Git checkout -b $pullRequestBranch | |
_Git config user.name $env:RELEASE_DEPLOYMENT_REQUESTEDFOR | |
_Git config user.email $env:RELEASE_DEPLOYMENT_REQUESTEDFOREMAIL | |
$mpackUrl | Out-File -FilePath external-addins/$addinName/source.txt -Encoding ASCII | |
_Git status | |
_Git diff | |
_Git commit -a -m "Bump to $($mpackFile.Name)" | |
_Git show | |
_Git push origin $pullRequestBranch | |
$pullRequestBody = @{ | |
"title" = "Bump to $($mpackFile.Name)" | |
"maintainer_can_modify" = $true | |
"base" = $targetBranch | |
"head" = $pullRequestBranch | |
} | ConvertTo-Json | |
Write-Host "Creating pull request:" | |
Write-Host $pullRequestBody | |
Invoke-WebRequest ` | |
-Uri "https://api.github.com/repos/xamarin/md-addins/pulls" ` | |
-Headers @{ | |
"Accept" = "application/vnd.github.v3+json" | |
"Content-Type" = "application/json; charset=utf-8" | |
"Authorization" = "token $(Github.Token)" | |
} ` | |
-Method POST ` | |
-Body $pullRequestBody |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment