diff --git a/README.md b/README.md index 53bf6343..07e1b2eb 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ | Component | Build Status | NuGet Package | |:-|---|---| | Core Library | [![Build status](https://ci.appveyor.com/api/projects/status/5b37qa4h0o2ci3db/branch/master?svg=true)](https://ci.appveyor.com/project/nfbot/lib-corelibrary/branch/master) | [![NuGet](https://img.shields.io/nuget/v/nanoFramework.CoreLibrary.svg)](https://www.nuget.org/packages/nanoFramework.CoreLibrary/) | -| Core Library (preview) | [![Build status](https://ci.appveyor.com/api/projects/status/5b37qa4h0o2ci3db/branch/develop?svg=true)](https://ci.appveyor.com/project/nfbot/lib-corelibrary/branch/develop) | [![MyGet Pre Release](https://img.shields.io/myget/nanoframework-dev/vpre/nanoFramework.CoreLibrary.svg)](https://www.myget.org/feed/nanoframework-dev/package/nuget/nanoFramework.CoreLibrary) | +| Core Library (preview) | [![Build Status](https://dev.azure.com/nanoframework/CoreLibrary/_apis/build/status/nanoframework.lib-CoreLibrary)](https://dev.azure.com/nanoframework/CoreLibrary/_build/latest?definitionId=24) | [![MyGet Pre Release](https://img.shields.io/myget/nanoframework-dev/vpre/nanoFramework.CoreLibrary.svg)](https://www.myget.org/feed/nanoframework-dev/package/nuget/nanoFramework.CoreLibrary) | ## Feedback and documentation diff --git a/appveyor-discord.ps1 b/appveyor-discord.ps1 deleted file mode 100644 index a1ce8b91..00000000 --- a/appveyor-discord.ps1 +++ /dev/null @@ -1,82 +0,0 @@ -# Copyright (c) 2017 The nanoFramework project contributors -# Portions Copyright (c) Sankarsan Kampa (a.k.a. k3rn31p4nic). All rights reserved. -# See LICENSE file in the project root for full license information. - -$STATUS=$args[0] -$WEBHOOK_URL=$args[1] - -Write-Output "[Webhook]: Sending webhook to Discord..." - -Switch ($STATUS) { - "success" { - $EMBED_COLOR=3066993 - $STATUS_MESSAGE="Passed" - Break - } - "failure" { - $EMBED_COLOR=15158332 - $STATUS_MESSAGE="Failed" - Break - } - default { - Write-Output "Default!" - Break - } -} - -if (!$env:APPVEYOR_REPO_COMMIT) { - $env:APPVEYOR_REPO_COMMIT="$(git log -1 --pretty="%H")" -} - -$AUTHOR_NAME="$(git log -1 "$env:APPVEYOR_REPO_COMMIT" --pretty="%aN")" -$COMMITTER_NAME="$(git log -1 "$env:APPVEYOR_REPO_COMMIT" --pretty="%cN")" -$COMMIT_SUBJECT="$(git log -1 "$env:APPVEYOR_REPO_COMMIT" --pretty="%s")" -$COMMIT_MESSAGE="$(git log -1 "$env:APPVEYOR_REPO_COMMIT" --pretty="%b")" - -if ($AUTHOR_NAME -eq $COMMITTER_NAME) { - $CREDITS = "$AUTHOR_NAME authored & committed" -} -else { - $CREDITS = "$AUTHOR_NAME authored & $COMMITTER_NAME committed" -} - -if ($env:APPVEYOR_PULL_REQUEST_NUMBER) { - $URL="https://github.com/$env:APPVEYOR_REPO_NAME/pull/$env:APPVEYOR_PULL_REQUEST_NUMBER" -} -else { - $URL="" -} - -$BUILD_VERSION = [uri]::EscapeDataString($env:APPVEYOR_BUILD_VERSION) - -$WEBHOOK_DATA="{ - ""embeds"": [ { - ""color"": $EMBED_COLOR, - ""author"": { - ""name"": ""Job #$env:APPVEYOR_JOB_NUMBER (Build #$env:APPVEYOR_BUILD_NUMBER) $STATUS_MESSAGE - $env:APPVEYOR_REPO_NAME"", - ""url"": ""https://ci.appveyor.com/project/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/build/$BUILD_VERSION"", - ""icon_url"": ""$AVATAR"" - }, - ""title"": ""$COMMIT_SUBJECT"", - ""url"": ""$URL"", - ""description"": ""$COMMIT_MESSAGE $CREDITS"", - ""fields"": [ - { - ""name"": ""Commit"", - ""value"": ""[``$($env:APPVEYOR_REPO_COMMIT.substring(0, 7))``](https://github.com/$env:APPVEYOR_REPO_NAME/commit/$env:APPVEYOR_REPO_COMMIT)"", - ""inline"": true - }, - { - ""name"": ""Branch/Tag"", - ""value"": ""[``$env:APPVEYOR_REPO_BRANCH``](https://github.com/$env:APPVEYOR_REPO_NAME/tree/$env:APPVEYOR_REPO_BRANCH)"", - ""inline"": true - } - ] - } ], - ""content"" : """", - ""file"": """" -}" - -Invoke-RestMethod -Uri $WEBHOOK_URL -Method POST -UserAgent AppVeyor-Webhook -ContentType 'application/json' -Body $WEBHOOK_DATA - -Write-Output "[Webhook]: Successfully sent the webhook." diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index e46a2f11..00000000 --- a/appveyor.yml +++ /dev/null @@ -1,170 +0,0 @@ -# configuration for all branches - -image: Visual Studio 2017 - -skip_tags: false - -skip_branch_with_pr: true - -test: off - -# Skipping commits affecting specific files -skip_commits: - files: - - '**\AssemblyInfo*.*' - - '**/*.md' - - 'LICENSE' - - dir/* - - '.gitignore' - - 'azure-pipelines.yml' - -build: - verbosity: minimal - -environment: - APPVEYOR_IGNORE_COMMIT_FILTERING_ON_TAG: true - APPVEYOR_SAVE_CACHE_ON_ERROR: true - matrix: - - RUBY_VERSION: 24 - GitHubUserName: - secure: 7OBtVAMTodMWK20wg6pGnQ== - GitHubUserEmail: - secure: /NpmL1KqwHyHFnF0GlUovA586wDIt8Hg/Q8Dro6kUpk= - GitHubToken: - secure: i/2hGsqVMwzdM5yIS4rxOIeG3ftx7su7klWYN80s/fHvgk7A5H2fF3oUTNLcyTbw - GitRestAuth: - secure: E3bCMe4LtDdAhHSYRcLp0N6DixJe1m8TNxhYeJW/GnqM3WXdRqsgkHSbwootPjJQtOQJrps4twmzTVzofLSVgPgbzU8PxU0AkJV7zwkyVOE= - -init: -- git config --global core.autocrlf true -- git config --global credential.helper store -- ps: Add-Content "$env:USERPROFILE\.git-credentials" "https://$($env:GitHubToken):x-oauth-basic@github.com`n" -- git config --global user.email "%GitHubUserEmail%" -- git config --global user.name "%GitHubUserName%" - -install: -- set PATH=C:\Ruby%RUBY_VERSION%\bin;%PATH% -- bundle config --local path vendor/bundle -- gem install bundler --quiet --no-ri --no-rdoc -- gem install github_changelog_generator --quiet --no-ri --no-rdoc -- dotnet tool install --tool-path . nbgv -- ps: | - .\install-vsix-appveyor.ps1 - - if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) } - -before_build: -- ps: >- - - nuget restore source\nanoFramework.CoreLibrary.sln - - .\nbgv cloud -p source -a -c - -build_script: -- ps: msbuild source\nanoFramework.CoreLibrary.sln /p:PublicRelease=true /p:Configuration=Release /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" - -before_deploy: - - ps: >- - .\nbgv cloud --version=$env:NBGV_SemVer1 - - $env:MyNuGetVersion = $env:NBGV_NuGetPackageVersion -replace "\-g$env:NBGV_GitCommitIdShort", "" - - .\generate-change-log.ps1 - - - nuget pack source\nanoFramework.CoreLibrary.nuspec -Version %MyNuGetVersion% - - nuget pack source\nanoFramework.CoreLibrary.DELIVERABLES.nuspec -Version %MyNuGetVersion% - - ps: >- - .\commit-assemblyinfo-changes.ps1 - - .\generate-change-log.ps1 - - Push-AppveyorArtifact $env:APPVEYOR_BUILD_FOLDER\nanoFramework.CoreLibrary.$env:MyNuGetVersion.nupkg - -after_deploy: -# for this environment variable to work here it has to be set in AppVeyor UI -- nuget push nanoFramework.CoreLibrary.%MyNuGetVersion%.nupkg %MyGetToken% -Source https://www.myget.org/F/nanoframework-dev/api/v2/package -- nuget push nanoFramework.CoreLibrary.DELIVERABLES.%MyNuGetVersion%.nupkg %MyGetToken% -Source https://www.myget.org/F/nanoframework-dev/api/v2/package - -# requires APPVEYOR_DISCORD_WEBHOOK_URL enviroment variable set with Discord webhook URL -on_failure: - - ps: | - - & $env:APPVEYOR_BUILD_FOLDER\appveyor-discord.ps1 failure $env:APPVEYOR_DISCORD_WEBHOOK_URL - -on_success: - - ps: .\update-dependencies.ps1 - -cache: - - source\packages -> **source\packages.config - -################################################ -# override configuration for specific branches -for: - -- - branches: - only: - - master - - /v\d.*/ - - deploy: - - provider: NuGet - api_key: $(NuGetToken) - skip_symbols: true - on: - appveyor_repo_tag: true - - provider: GitHub - tag: v$(MyNuGetVersion) - release: nanoFramework Base Class Library v$(MyNuGetVersion) - description: 'Check the [changelog](https://github.com/nanoframework/lib-CoreLibrary/blob/master/CHANGELOG.md)\n\n## Install from NuGet\n\nThe following NuGet packages are available for download from this release\n\n:package: [.NET](https://www.nuget.org/packages/nanoFramework.CoreLibrary/$(MyNuGetVersion)) v$(MyNuGetVersion)' - auth_token: - secure: DNixoFFE+pGlwyhj7McfZoln42vOmj0iY1iNV9zXEr3y0NpXlOIgL8k5ehzlFM1S - artifact: - draft: true - prerelease: false - force_update: true - on: - appveyor_repo_tag: false - -- - branches: - only: - - /dev(elop)?$/ - - deploy: - - provider: GitHub - tag: v$(MyNuGetVersion) - release: nanoFramework Core Library v$(MyNuGetVersion) - description: 'Check the [changelog](https://github.com/nanoframework/lib-CoreLibrary/blob/develop/CHANGELOG.md)\n\n## Install from nanoFramework MyGet development feed\n\nThe following NuGet packages are available for download from this release\n\n:package: [.NET](https://www.myget.org/feed/nanoframework-dev/package/nuget/nanoFramework.CoreLibrary/$(MyNuGetVersion)) v$(MyNuGetVersion)' - auth_token: - secure: DNixoFFE+pGlwyhj7McfZoln42vOmj0iY1iNV9zXEr3y0NpXlOIgL8k5ehzlFM1S - artifact: source\Nuget.CoreLibrary\bin\Release\nanoFramework.CoreLibrary.$(MyNuGetVersion).nupkg - draft: true - prerelease: true - force_update: true - on: - appveyor_repo_tag: false - -- - branches: - only: - - /release.*/ - - deploy: - - provider: NuGet - api_key: $(NuGetToken) - skip_symbols: true - on: - appveyor_repo_tag: true - - provider: GitHub - tag: v$(MyNuGetVersion) - release: nanoFramework Core Library v$(MyNuGetVersion) - description: 'Check the [changelog](https://github.com/nanoframework/lib-CoreLibrary/blob/$(appveyor_repo_branch)/CHANGELOG.md)\n\n## Install from NuGet\n\nThe following NuGet packages are available for download from this release\n\n:package: [.NET](https://www.nuget.org/packages/nanoFramework.CoreLibrary/$(MyNuGetVersion)) v$(MyNuGetVersion)' - auth_token: - secure: DNixoFFE+pGlwyhj7McfZoln42vOmj0iY1iNV9zXEr3y0NpXlOIgL8k5ehzlFM1S - artifact: - draft: true - prerelease: true - force_update: true - on: - appveyor_repo_tag: false diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 00000000..18759c68 --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,80 @@ +trigger: + branches: + include: + - master + - develop + - release/* + - refs/tags/* + paths: + exclude: + - /*.md + - .gitignore + - appveyor.yml + # waiting for feature to become available + # tags: + # include: + # - v/* + +pr: + branches: + include: + - master + - develop + - release/* + autoCancel: true + +# add nf-tools repo to resources (for Azure Pipelines templates) +resources: + repositories: + - repository: templates + type: github + name: nanoframework/nf-tools + endpoint: nfbot + +pool: + vmImage: 'VS2017-Win2016' + +variables: + solution: '**/source/*.sln' + buildPlatform: 'Any CPU' + buildConfiguration: 'Release' + nugetPackageName: 'nanoFramework.CoreLibrary' + repoName: 'lib-CoreLibrary' + +steps: + +# step from template @ nf-tools repo +# all build, update and publish steps +- template: azure-pipelines-templates/class-lib-build.yml@templates + parameters: + sourceFileName: 'corlib_native.cpp' + classLibName: 'CoreLibrary' + skipNuGetRestore: true + +# update dependencies +- task: UpdatenFDependencies@1 + inputs: + gitHubToken: $(GitHubToken) + repositoriesToUpdate: | + lib-nanoFramework.Devices.OneWire + lib-nanoFramework.Runtime.Events + lib-nanoFramework.Runtime.Native + lib-Windows.Storage.Streams + lib-Windows.Devices.Adc + lib-Windows.Devices.I2c + lib-Windows.Devices.Pwm + lib-Windows.Devices.Spi + lib-nanoFramework.Devices.OneWire + lib-nanoFramework.Networking.Sntp + lib-nanoFramework.Hardware.Stm32 + lib-nanoFramework.System.Math + condition: and( succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/v') ) + displayName: Update dependent class libs + +# step from template @ nf-tools repo +# report error +- template: azure-pipelines-templates/discord-webhook-task.yml@templates + parameters: + status: 'failure' + webhookUrl: '$(DiscordWebhook)' + message: '' diff --git a/commit-assemblyinfo-changes.ps1 b/commit-assemblyinfo-changes.ps1 deleted file mode 100644 index 52867824..00000000 --- a/commit-assemblyinfo-changes.ps1 +++ /dev/null @@ -1,91 +0,0 @@ -# Copyright (c) 2018 The nanoFramework project contributors -# See LICENSE file in the project root for full license information. - -# update assembly info in nf-interpreter if this is tag -if ($env:APPVEYOR_REPO_TAG -eq "true") -{ - 'Updating assembly version in nf-interpreter...' | Write-Host -ForegroundColor White -NoNewline - - # name of source file with the native declaration - $nativeFile = "corlib_native.cpp" - - # find assembly declaration - $assemblyDeclarationPath = (Get-ChildItem -Path ".\*" -Include $nativeFile -Recurse) - $filecontent = Get-Content($assemblyDeclarationPath) - $assemblyChecksum = $filecontent -match '(0x.{8})' - $assemblyChecksum = $assemblyChecksum -replace "," , "" - $assemblyChecksum = $assemblyChecksum -replace " " , "" - - # clone nf-interpreter repo (only a shallow clone with last commit) - git clone https://github.com/nanoframework/nf-interpreter -b develop --depth 1 -q - cd nf-interpreter > $null - - # new branch name - $newBranch = "$env:APPVEYOR_REPO_BRANCH-nfbot/update-version/nanoFramework.CorLib/$env:MyNuGetVersion" - - # create branch to perform updates - git checkout -b "$newBranch" develop -q - - # replace version in assembly declaration - $newVersion = $env:NBGV_AssemblyFileVersion -replace "\." , ", " - $newVersion = "{ $newVersion }" - - $versionRegex = "\{\s*\d+\,\s*\d+\,\s*\d+\,\s*\d+\s*}" - $assemblyFiles = (Get-ChildItem ".\src\CLR\CorLib\corlib_native.cpp" -Recurse) - - foreach($file in $assemblyFiles) - { - # replace checksum - $filecontent = Get-Content($file) - attrib $file -r - $filecontent -replace "0x.{8}", $assemblyChecksum | Out-File $file -Encoding utf8 - - # replace version - $filecontent = Get-Content($file) - attrib $file -r - $filecontent -replace $versionRegex, $newVersion | Out-File $file -Encoding utf8 - } - - # check if anything was changed - $repoStatus = "$(git status --short --porcelain)" - - if ($repoStatus -eq "") - { - # nothing changed - & cd .. > $null - } - else - { - $commitMessage = "Update nanoFramework.CorLib version to $env:MyNuGetVersion" - - # commit changes - git add -A 2>&1 - git commit -m"$commitMessage" -q - git push --set-upstream origin "$newBranch" --porcelain -q > $null - - # start PR - $prRequestBody = @{title="$commitMessage";body="$commitMessage`n`nStarted from https://github.com/$env:APPVEYOR_REPO_NAME/commit/$env:APPVEYOR_REPO_COMMIT`n`n[version update]";head="$newBranch";base="develop"} | ConvertTo-Json - $githubApiEndpoint = "https://api.github.com/repos/nanoframework/nf-interpreter/pulls" - [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 - - try - { - $result = Invoke-RestMethod -Method Post -UserAgent [Microsoft.PowerShell.Commands.PSUserAgent]::InternetExplorer -Uri $githubApiEndpoint -Header @{"Authorization"="Basic $env:GitRestAuth"} -ContentType "application/json" -Body $prRequestBody - 'Started PR with version update...' | Write-Host -ForegroundColor White -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 - } - - # move back to home folder - & cd .. > $null - } -} diff --git a/generate-change-log.ps1 b/generate-change-log.ps1 deleted file mode 100644 index 17c2bc9a..00000000 --- a/generate-change-log.ps1 +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright (c) 2018 The nanoFramework project contributors -# See LICENSE file in the project root for full license information. - -# skip generating the change log when build is a pull-request or not a tag (can't commit when repo is in a tag) -if ($env:appveyor_pull_request_number -or $env:APPVEYOR_REPO_TAG -eq "true") -{ - 'Skip change log processing...' | Write-Host -ForegroundColor White -} -else -{ - # need this to keep ruby happy - md c:\tmp > $null - - if ($env:APPVEYOR_REPO_BRANCH -eq "master" -or $env:APPVEYOR_REPO_BRANCH -match "^release*") - { - # generate change log including future version - bundle exec github_changelog_generator --token $env:GitHubToken --future-release "v$env:NBGV_Version" - } - else - { - # generate change log - # version includes commits - bundle exec github_changelog_generator --token $env:GitHubToken - } - - # updated changelog, if there are any differences - $logDif = git diff CHANGELOG.md - - if($logDif -ne $null) - { - git add CHANGELOG.md - git commit -m "Update CHANGELOG for v$env:MyNuGetVersion" - # need to wrap the git command bellow so it doesn't throw an error because of redirecting the output to stderr - git push origin "HEAD:$env:APPVEYOR_REPO_BRANCH" --porcelain | Write-Host - } -} diff --git a/install-vsix-appveyor.ps1 b/install-vsix-appveyor.ps1 deleted file mode 100644 index b4f6f3e3..00000000 --- a/install-vsix-appveyor.ps1 +++ /dev/null @@ -1,25 +0,0 @@ -# Copyright (c) 2018 The nanoFramework project contributors -# See LICENSE file in the project root for full license information. - -$vsixPath = "" - -# try downloading from VS marketplace -try -{ - $vsixPath = "$($env:USERPROFILE)\nanoFramework.Tools.VS2017.Extension.vsix" - (New-Object Net.WebClient).DownloadFile('https://marketplace.visualstudio.com/_apis/public/gallery/publishers/vs-publisher-1470366/vsextensions/nanoFrameworkVS2017Extension/0/vspackage', $vsixPath) -} -catch -{ - # download failed, try fron MyGet feed - $vsixPath = "$($env:USERPROFILE)\47973986-ed3c-4b64-ba40-a9da73b44ef7-1.0.1.0.vsix" - (New-Object Net.WebClient).DownloadFile('https://www.myget.org/F/nanoframework-dev/vsix/47973986-ed3c-4b64-ba40-a9da73b44ef7-1.0.1.0.vsix', $vsixPath) -} - -"`"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VSIXInstaller.exe`" /q /a $vsixPath" | out-file ".\install-vsix.cmd" -Encoding ASCII - -'Installing nanoFramework VS extension ...' | Write-Host -ForegroundColor White -NoNewline - -& .\install-vsix.cmd > $null - -'OK' | Write-Host -ForegroundColor Green diff --git a/source/version.json b/source/version.json index e07545a7..a2029e38 100644 --- a/source/version.json +++ b/source/version.json @@ -14,13 +14,6 @@ ], "cloudBuild": { "setVersionVariables": true, - "setAllVariables": true, - "buildNumber": { - "enabled": true, - "includeCommitId": { - "when": "nonPublicReleaseOnly", - "where": "buildMetadata" - } - } + "setAllVariables": true } } \ No newline at end of file diff --git a/update-dependencies.ps1 b/update-dependencies.ps1 deleted file mode 100644 index f9aac58c..00000000 --- a/update-dependencies.ps1 +++ /dev/null @@ -1,262 +0,0 @@ -# Copyright (c) 2018 The nanoFramework project contributors -# See LICENSE file in the project root for full license information. - -# only need to update dependencies when build is a tag -if ($env:appveyor_pull_request_number -or $env:APPVEYOR_REPO_TAG -eq "false") -{ - 'Skip updating dependencies...' | Write-Host -ForegroundColor White -} -else -{ - # update dependencies for class libraries that depend ONLY on mscorlib - - # because it can take sometime for the package to become available on the NuGet providers - # need to hang here for 5 minutes (5 * 60) - "Waiting 5 minutes to let package process flow in NuGet providers..." | Write-Host -ForegroundColor White - - For ($i=300; $i -gt 0; $i--) - { - Write-Host "`r$i seconds remaining " -NoNewLine - Start-Sleep -Seconds 1 - } - Write-Host "`r " - - $librariesToUpdate = ("lib-nanoFramework.Devices.OneWire", - "lib-nanoFramework.Runtime.Events", - "lib-nanoFramework.Runtime.Native", - "lib-Windows.Storage.Streams", - "lib-Windows.Devices.Adc", - "lib-Windows.Devices.I2c", - "lib-Windows.Devices.Pwm", - "lib-Windows.Devices.Spi", - "lib-nanoFramework.Devices.OneWire", - "lib-nanoFramework.Networking.Sntp", - "lib-nanoFramework.Hardware.Stm32", - "lib-nanoFramework.System.Math") - - ForEach($library in $librariesToUpdate) - { - # init/reset these - $commitMessage = "" - $prTitle = "" - $projectPath = "" - $newBranchName = "$env:APPVEYOR_REPO_BRANCH-nfbot/update-dependencies" - - "Updating $library" | Write-Host -ForegroundColor White - - # make sure we are in the projects directory - & cd "C:\projects" > $null - - # clone library repo and checkout develop branch - "Cloning $library" | Write-Host -ForegroundColor White - git clone "https://github.com/nanoframework/$library" -b develop --depth 1 -q - cd $library - cd source - - # find solution file in repository - $solutionFile = (Get-ChildItem -Path ".\" -Include "*.sln" -Recurse) - - # find packages.config - $packagesConfig = (Get-ChildItem -Path ".\" -Include "packages.config" -Recurse) - - # load packages.config as XML doc - [xml]$packagesDoc = Get-Content $packagesConfig - - $nodes = $packagesDoc.SelectNodes("*").SelectNodes("*") - - $packageList = @(,@()) - - foreach ($node in $nodes) - { - # filter out Nerdbank.GitVersioning package - if($node.id -notlike "Nerdbank.GitVersioning*") - { - if($packageList) - { - $packageList += , ($node.id, $node.version) - } - else - { - $packageList = , ($node.id, $node.version) - } - } - } - - if ($packageList.length -gt 0) - { - "NuGet packages to update:" | Write-Host -ForegroundColor White - $packageList | Write-Host -ForegroundColor White - - # restore NuGet packages, need to do this before anything else - nuget restore $solutionFile[0] -Source https://www.myget.org/F/nanoframework-dev/api/v3/index.json -Source https://api.nuget.org/v3/index.json - - # rename nfproj files to csproj - Get-ChildItem -Path ".\" -Include "*.nfproj" -Recurse | - Foreach-object { - $OldName = $_.name; - $NewName = $_.name -replace 'nfproj','csproj'; - Rename-Item -Path $_.fullname -Newname $NewName; - } - - # update all packages - foreach ($package in $packageList) - { - # get package name and target version - $packageName = $package[0] - $packageOriginVersion = $package[1] - - # update package - if ($env:APPVEYOR_REPO_BRANCH -like '*release*' -or $env:APPVEYOR_REPO_BRANCH -like '*master*') - { - # don't allow prerelease for release and master branches - $updatePackage = nuget update $solutionFile[0].FullName -Source https://api.nuget.org/v3/index.json -Source https://api.nuget.org/v3/index.json - } - else - { - # allow prerelease for all others - $updatePackage = nuget update $solutionFile[0].FullName -Source https://www.myget.org/F/nanoframework-dev/api/v3/index.json -Source https://api.nuget.org/v3/index.json -PreRelease - } - - # need to get target version - # load packages.config as XML doc - [xml]$packagesDoc = Get-Content $packagesConfig - - $nodes = $packagesDoc.SelectNodes("*").SelectNodes("*") - - foreach ($node in $nodes) - { - # find this package - if($node.id -match $packageName) - { - $packageTargetVersion = $node.version - } - } - - # find csproj - $projectPath = (Get-ChildItem -Path ".\" -Include "*.csproj" -Recurse) - - # replace NFMDP_PE_LoadHints - $filecontent = Get-Content($projectPath) - attrib $projectPath -r - $filecontent -replace "($packageName.$packageOriginVersion)", "$packageName.$packageTargetVersion" | Out-File $projectPath -Encoding utf8 - - # update nuspec files, if any - $nuspecFiles = (Get-ChildItem -Path ".\" -Include "*.nuspec" -Recurse) - - foreach ($nuspec in $nuspecFiles) - { - [xml]$nuspecDoc = Get-Content $nuspec - - $nodes = $nuspecDoc.SelectNodes("*").SelectNodes("*") - - foreach ($node in $nodes) - { - if($node.Name -eq "metadata") - { - foreach ($metadataItem in $node.ChildNodes) - { - if($metadataItem.Name -eq "dependencies") - { - foreach ($dependency in $metadataItem.ChildNodes) - { - if($dependency.Attributes["id"].value -eq $packageName) - { - $dependency.Attributes["version"].value = "[$packageTargetVersion]" - } - } - } - } - } - } - - $nuspecDoc.Save($nuspec[0].FullName) - } - - # update branch name - $tempPackageName = $packageName -replace "(nanoFramework.)", "" - $newBranchName += "/$tempPackageName.$packageTargetVersion" - - # build commit message - $commitMessage += "Bumps $packageName from $packageOriginVersion to $packageTargetVersion.`n" - - # build PR title - $prTitle = "Bumps $packageName from $packageOriginVersion to $packageTargetVersion" - } - - # rename csproj files back to nfproj - Get-ChildItem -Path ".\" -Include "*.csproj" -Recurse | - Foreach-object { - $OldName = $_.name; - $NewName = $_.name -replace 'csproj','nfproj'; - Rename-Item -Path $_.fullname -Newname $NewName; - } - - # need this line so nfbot flags the PR appropriately - $commitMessage += "`n[version update]`n`n" - - # better add this warning line - $commitMessage += "### :warning: This is an automated update. Merge only after all tests pass. :warning:`n" - - # create branch to perform updates - git branch $newBranchName -q - - # checkout branch - git checkout $newBranchName -q - - # commit changes - git add -A 2>&1 - - # commit message with a different title if one or more dependencies are updated - if ($packageList.length -gt 1) - { - git commit -m "Update $packageList.length NuGet dependencies" -m"$commitMessage" -q - - # fix PR title - $prTitle = "Update $packageList.length NuGet dependencies" - } - else - { - git commit -m "$prTitle" -m "$commitMessage" -q - } - - git push --set-upstream origin $newBranchName --porcelain -q - - # start PR - # we are hardcoding to develop branch to have a fixed one - # this is very important for tags (which don't have branch information) - # considering that the base branch can be changed at the PR ther is no big deal about this - $prRequestBody = @{title="$prTitle";body="$commitMessage";head="$newBranchName";base="develop"} | ConvertTo-Json - $githubApiEndpoint = "https://api.github.com/repos/nanoframework/$library/pulls" - [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 - - $headers = @{} - $headers.Add("Authorization","Basic $env:GitRestAuth") - $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 with dependencies update...' | Write-Host -ForegroundColor White -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 - } - } - else - { - # nothing to update??? - "Couldn't find anything to update..." | Write-Host -ForegroundColor Black -BackgroundColor Yellow - } - } - - # get back to the original build folder - cd $env:APPVEYOR_BUILD_FOLDER -}