Skip to content

Commit 114c9f3

Browse files
committed
Work CI-CD
- Update PS1 script to update VS Code extension repo. ***NO_CI***
1 parent 1304b50 commit 114c9f3

File tree

1 file changed

+48
-43
lines changed

1 file changed

+48
-43
lines changed

azure-pipelines/update-dependencies.ps1

Lines changed: 48 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,9 @@ git checkout --quiet develop | Out-Null
4040

4141
Write-Host "Updating nanoFramework.Tools.FirmwareFlasher version in VS Code extension..."
4242

43-
$versionRegex = "nanoFlasherVersion\s=\s\""v\d+.\d+.\d+\"""
44-
$newVersion = "nanoFlasherVersion = ""v$packageTargetVersion"""
43+
Set-Location nanoFirmwareFlasher | Out-Null
4544

46-
$buildFileName = 'scripts/build.ps1'
47-
$buildFileContent = Get-Content $buildFileName -Encoding UTF8
48-
49-
attrib $buildFileName -r
50-
$buildFileContent -replace $versionRegex, $newVersion | Out-File $buildFileName -Encoding utf8
45+
git checkout tags/v$packageTargetVersion
5146

5247
#####################
5348

@@ -74,44 +69,54 @@ Write-Debug "Checkout branch"
7469
# checkout branch
7570
git checkout $newBranchName
7671

77-
Write-Debug "Add changes"
78-
79-
# commit changes
80-
git add -A > $null
81-
82-
Write-Debug "Commit changed files"
83-
84-
git commit -m "$prTitle ***NO_CI***" -m "$commitMessage" > $null
85-
86-
Write-Debug "Push changes"
72+
# check if anything was changed
73+
$repoStatus = "$(git status --short --porcelain)"
8774

88-
git -c http.extraheader="AUTHORIZATION: $auth" push --set-upstream origin $newBranchName > $null
89-
90-
# start PR
91-
# we are hardcoding to 'develop' branch to have a fixed one
92-
# this is very important for tags (which don't have branch information)
93-
# considering that the base branch can be changed at the PR there is no big deal about this
94-
$prRequestBody = @{title="$prTitle";body="$commitMessage";head="$newBranchName";base="develop"} | ConvertTo-Json
95-
$githubApiEndpoint = "https://api.github.com/repos/nanoframework/$repoName/pulls"
96-
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
97-
98-
$headers = @{}
99-
$headers.Add("Authorization","$auth")
100-
$headers.Add("Accept","application/vnd.github.symmetra-preview+json")
101-
102-
try
75+
if ($repoStatus -ne "")
10376
{
104-
$result = Invoke-RestMethod -Method Post -UserAgent [Microsoft.PowerShell.Commands.PSUserAgent]::InternetExplorer -Uri $githubApiEndpoint -Header $headers -ContentType "application/json" -Body $prRequestBody
105-
'Started PR with dependencies update...' | Write-Host -NoNewline
106-
'OK' | Write-Host -ForegroundColor Green
77+
Write-Debug "Add changes"
78+
79+
# commit changes
80+
git add -A > $null
81+
82+
Write-Debug "Commit changed files"
83+
84+
git commit -m "$prTitle ***NO_CI***" -m "$commitMessage" > $null
85+
86+
Write-Debug "Push changes"
87+
88+
git -c http.extraheader="AUTHORIZATION: $auth" push --set-upstream origin $newBranchName > $null
89+
90+
# start PR
91+
# we are hardcoding to 'develop' branch to have a fixed one
92+
# this is very important for tags (which don't have branch information)
93+
# considering that the base branch can be changed at the PR there is no big deal about this
94+
$prRequestBody = @{title="$prTitle";body="$commitMessage";head="$newBranchName";base="develop"} | ConvertTo-Json
95+
$githubApiEndpoint = "https://api.github.com/repos/nanoframework/$repoName/pulls"
96+
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
97+
98+
$headers = @{}
99+
$headers.Add("Authorization","$auth")
100+
$headers.Add("Accept","application/vnd.github.symmetra-preview+json")
101+
102+
try
103+
{
104+
$result = Invoke-RestMethod -Method Post -UserAgent [Microsoft.PowerShell.Commands.PSUserAgent]::InternetExplorer -Uri $githubApiEndpoint -Header $headers -ContentType "application/json" -Body $prRequestBody
105+
'Started PR with dependencies update...' | Write-Host -NoNewline
106+
'OK' | Write-Host -ForegroundColor Green
107+
}
108+
catch
109+
{
110+
$result = $_.Exception.Response.GetResponseStream()
111+
$reader = New-Object System.IO.StreamReader($result)
112+
$reader.BaseStream.Position = 0
113+
$reader.DiscardBufferedData()
114+
$responseBody = $reader.ReadToEnd();
115+
116+
throw "Error creating PR: $responseBody"
117+
}
107118
}
108-
catch
119+
else
109120
{
110-
$result = $_.Exception.Response.GetResponseStream()
111-
$reader = New-Object System.IO.StreamReader($result)
112-
$reader.BaseStream.Position = 0
113-
$reader.DiscardBufferedData()
114-
$responseBody = $reader.ReadToEnd();
115-
116-
throw "Error creating PR: $responseBody"
121+
Write-Host "Nothing udpate at nanoFramework Deployer."
117122
}

0 commit comments

Comments
 (0)