forked from nanoframework/nf-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepare-release.yml
75 lines (60 loc) · 2.98 KB
/
prepare-release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Copyright (c) .NET Foundation and Contributors
# See LICENSE file in the project root for full license information.
steps:
- task: PowerShell@2
condition: eq( variables['StartReleaseCandidate'], true )
displayName: NBGV prepare release
inputs:
targetType: 'inline'
script: |
# compute authorization header in format "AUTHORIZATION: basic 'encoded token'"
# 'encoded token' is the Base64 of the string "nfbot:personal-token"
$auth = "basic $([System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("nfbot:$(GitHubToken)")))"
cd "$env:Agent_TempDirectory" > $null
Write-Host "Cloning from: $env:BUILD_REPOSITORY_URI"
git clone $env:BUILD_REPOSITORY_URI repo
cd repo > $null
git config --global gc.auto 0
git config --global user.name nfbot
git config --global user.email [email protected]
git config --global core.autocrlf true
Write-Host "Checkout develop branch..."
git checkout --quiet develop > $null
# prepare release and capture output
Write-Host "Prepare release with NBGV..."
$release = nbgv prepare-release
Write-Host "Prepare commit..."
# get commit message for the merge
$commitMessage = git log -1 --pretty=%B
# amend commit message to skip build
git commit --amend -m "$commitMessage" -m "***NO_CI***" > $null
Write-Host "Pushing changes to GitHub..."
# push all changes to github
git -c http.extraheader="AUTHORIZATION: $auth" push --quiet --all origin
# get release branch name
$branch = $release.Split(' ')[0]
Write-Host "Prepare PR..."
# start PR for release
$prRequestBody = @{title="$branch";body="[release candidate]";head="$branch";base="main"} | ConvertTo-Json
$githubApiEndpoint = "https://api.github.com/repos/$env:BUILD_REPOSITORY_NAME/pulls"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$headers = @{}
$headers.Add("Authorization","$auth")
$headers.Add("Accept","application/vnd.github.symmetra-preview+json")
try
{
$result = Invoke-RestMethod -Method Post -UserAgent [Microsoft.PowerShell.Commands.PSUserAgent]::InternetExplorer -Uri $githubApiEndpoint -Header $headers -ContentType "application/json" -Body $prRequestBody
'Started PR for new release...' | Write-Host -NoNewline
'OK' | Write-Host -ForegroundColor Green
}
catch
{
$result = $_.Exception.Response.GetResponseStream()
$reader = New-Object System.IO.StreamReader($result)
$reader.BaseStream.Position = 0
$reader.DiscardBufferedData()
$responseBody = $reader.ReadToEnd();
"Error starting PR: $responseBody" | Write-Host -ForegroundColor Red
}
workingDirectory: $(Agent.TempDirectory)
ignoreLASTEXITCODE: true