From 988ea4220359b978e7fcfed3df6c100d0138fd76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Fri, 5 Oct 2018 10:00:19 +0100 Subject: [PATCH] Work on CI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Update gitversion definitions - Update AppVeyor - Add change log generator - Add PS to update interpreter when there is a new version Signed-off-by: José Simões --- .github_changelog_generator | 14 +++++ GitVersion.yml | 20 ++++-- appveyor.yml | 105 ++++++++++++++++++++------------ commit-assemblyinfo-changes.ps1 | 82 +++++++++++++++++++++++++ generate-change-log.ps1 | 20 ++++++ 5 files changed, 197 insertions(+), 44 deletions(-) create mode 100644 .github_changelog_generator create mode 100644 commit-assemblyinfo-changes.ps1 create mode 100644 generate-change-log.ps1 diff --git a/.github_changelog_generator b/.github_changelog_generator new file mode 100644 index 0000000..11a1421 --- /dev/null +++ b/.github_changelog_generator @@ -0,0 +1,14 @@ +user=nanoframework +project=lib-nanoFramework.Networking.Sntp +issues=true +add_issues_wo_labels=false +add_pr_wo_labels=false +add_issues_wo_labels=false +filter_issues_by_milestone=false +exclude_labels=Area: Config-and-Build,Area: Infrastructure-and-Organization,reverted +enhancement_labels=Type: enhancement +bug_labels=Type: bug +merge_prefix=**Documentation and other chores:** +unreleased_label=**Changes available only in 'Preview' NuGet packages:** +issue_line_labels=Breaking-Change,documentation +author=false diff --git a/GitVersion.yml b/GitVersion.yml index 156e8c4..a9712f5 100644 --- a/GitVersion.yml +++ b/GitVersion.yml @@ -1,12 +1,12 @@ next-version: 1.0.0 assembly-versioning-scheme: MajorMinorPatch +assembly-file-versioning-scheme: MajorMinorPatch +assembly-informational-format: '{LegacySemVerPadded}' build-metadata-padding: 3 legacy-semver-padding: 3 -assembly-informational-format: '{LegacySemVerPadded}' major-version-bump-message: '\+semver:\s?(breaking|major)' minor-version-bump-message: '\+semver:\s?(feature|minor)' patch-version-bump-message: '\+semver:\s?(fix|patch)' -commit-message-incrementing: MergeMessageOnly branches: master: mode: ContinuousDelivery @@ -15,12 +15,24 @@ branches: prevent-increment-of-merged-branch-version: true track-merge-target: false develop: + regex: dev(elop)?(ment)?$ mode: ContinuousDeployment tag: preview - increment: Minor + increment: Patch prevent-increment-of-merged-branch-version: false track-merge-target: true + tracks-release-branches: true + is-release-branch: false release: tag: rc - (pull|pull\-requests|pr)[/-]: + pull-request: + regex: (pull|pull\-requests|pr)[/-] tag: alpha + mode: ContinuousDelivery + increment: Inherit + prevent-increment-of-merged-branch-version: false + track-merge-target: false + tracks-release-branches: false + is-release-branch: false +ignore: + sha: [] diff --git a/appveyor.yml b/appveyor.yml index 499384a..0c482f1 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -29,9 +29,11 @@ GitHubUserName: secure: 7OBtVAMTodMWK20wg6pGnQ== GitHubUserEmail: - secure: HeABB68Sn/Lhbd69C2cUcfWv0ab/rMDEcOLvcxf8gGw= + secure: /NpmL1KqwHyHFnF0GlUovA586wDIt8Hg/Q8Dro6kUpk= GitHubToken: - secure: WOqlCsnwTzfDPJFoNV/h8mEESIpG/9uFn1u6oE8hGZtXwIQQlsY+NyyLt9Y5xoFn + secure: i/2hGsqVMwzdM5yIS4rxOIeG3ftx7su7klWYN80s/fHvgk7A5H2fF3oUTNLcyTbw + GitRestAuth: + secure: E3bCMe4LtDdAhHSYRcLp0N6DixJe1m8TNxhYeJW/GnqM3WXdRqsgkHSbwootPjJQtOQJrps4twmzTVzofLSVgPgbzU8PxU0AkJV7zwkyVOE= init: - git config --global core.autocrlf true @@ -42,8 +44,9 @@ 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 - # - bundle install - choco install gitversion.portable -pre -y - ps: .\install-vsix-appveyor.ps1 @@ -54,7 +57,7 @@ nuget restore source\nanoFramework.Networking.Sntp.sln - gitversion /l console /output buildserver /updateAssemblyInfo /ensureassemblyinfo + C:\ProgramData\chocolatey\lib\GitVersion.Portable\tools\GitVersion.exe /l console /output buildserver /updateAssemblyInfo "source\nanoFramework.Runtime.Events\Properties\AssemblyInfo.cs" build_script: - ps: >- @@ -62,12 +65,10 @@ msbuild source\nanoFramework.Networking.Sntp.sln /p:Configuration=Release /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" before_deploy: - # need this to keep ruby happy - - ps: md c:\tmp - - bundle exec github_changelog_generator --token %GitHubToken% - # add here the updated changelog and the updated assembly info files - - git add . - - git commit --amend --no-edit + - ps: >- + .\commit-assemblyinfo-changes.ps1 + + .\generate-change-log.ps1 artifacts: - path: '**\bin\Release\*.nupkg' @@ -83,7 +84,7 @@ - provider: GitHub tag: v$(GitVersion_NuGetVersionV2) release: nanoFramework.Networking.Sntp Library v$(gitversion_semver) - description: '[CHANGELOG.md](https://github.com/nanoframework/lib-nanoFramework.Networking.Sntp/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.Networking.Sntp/$(GitVersion_NuGetVersionV2)) v$(GitVersion_NuGetVersionV2)' + description: 'Check the [changelog](https://github.com/nanoframework/lib-nanoFramework.Runtime.Events/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.Runtime.Events/$(GitVersion_NuGetVersionV2)) v$(GitVersion_NuGetVersionV2)' auth_token: secure: DNixoFFE+pGlwyhj7McfZoln42vOmj0iY1iNV9zXEr3y0NpXlOIgL8k5ehzlFM1S artifact: Nuget_Packages @@ -95,7 +96,7 @@ on_failure: - ps: | - cd .. + cd $env:APPVEYOR_BUILD_FOLDER .\appveyor-discord.ps1 failure $env:APPVEYOR_DISCORD_WEBHOOK_URL @@ -116,7 +117,6 @@ skip_branch_with_pr: true - # Do not build on tags skip_tags: false test: off @@ -136,7 +136,31 @@ build: verbosity: minimal + environment: + 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 - choco install gitversion.portable -pre -y - ps: .\install-vsix-appveyor.ps1 @@ -147,7 +171,7 @@ nuget restore source\nanoFramework.Networking.Sntp.sln - gitversion /l console /output buildserver /updateAssemblyInfo /ensureassemblyinfo + C:\ProgramData\chocolatey\lib\GitVersion.Portable\tools\GitVersion.exe /l console /output buildserver /updateAssemblyInfo "source\nanoFramework.Runtime.Events\Properties\AssemblyInfo.cs" build_script: - ps: >- @@ -164,16 +188,10 @@ name: Nuget_Packages deploy: - # the provider is actually MyGet but works the same as NuGet - - provider: NuGet - server: https://www.myget.org/F/nanoframework-dev/api/v2/package - api_key: - secure: 0drE56FivPFYI3oVZWcVFTpjOXSqyjT6kGangIxFRcRLqMhV3lQHqUButuuiPM+N - skip_symbols: true - provider: GitHub tag: v$(GitVersion_NuGetVersionV2) release: nanoFramework.Networking.Sntp Library v$(gitversion_semver) - description: '[CHANGELOG.md](https://github.com/nanoframework/lib-nanoFramework.Networking.Sntp/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.Networking.Sntp/$(GitVersion_NuGetVersionV2)) v$(GitVersion_NuGetVersionV2)' + description: 'Check the [changelog](https://github.com/nanoframework/lib-nanoFramework.Runtime.Events/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\npackage: [.NET](https://www.myget.org/feed/nanoframework-dev/package/nuget/nanoFramework.Runtime.Events/$(GitVersion_NuGetVersionV2)) v$(GitVersion_NuGetVersionV2)' auth_token: secure: DNixoFFE+pGlwyhj7McfZoln42vOmj0iY1iNV9zXEr3y0NpXlOIgL8k5ehzlFM1S artifact: Nuget_Packages @@ -181,11 +199,17 @@ prerelease: true force_update: true + before_deploy: + - ps: >- + .\commit-assemblyinfo-changes.ps1 + + .\generate-change-log.ps1 + # requires APPVEYOR_DISCORD_WEBHOOK_URL enviroment variable set with Discord webhook URL on_failure: - ps: | - cd .. + cd $env:APPVEYOR_BUILD_FOLDER .\appveyor-discord.ps1 failure $env:APPVEYOR_DISCORD_WEBHOOK_URL @@ -223,14 +247,17 @@ test: off environment: + APPVEYOR_SAVE_CACHE_ON_ERROR: true matrix: - RUBY_VERSION: 24 GitHubUserName: secure: 7OBtVAMTodMWK20wg6pGnQ== GitHubUserEmail: - secure: HeABB68Sn/Lhbd69C2cUcfWv0ab/rMDEcOLvcxf8gGw= + secure: /NpmL1KqwHyHFnF0GlUovA586wDIt8Hg/Q8Dro6kUpk= GitHubToken: - secure: WOqlCsnwTzfDPJFoNV/h8mEESIpG/9uFn1u6oE8hGZtXwIQQlsY+NyyLt9Y5xoFn + secure: i/2hGsqVMwzdM5yIS4rxOIeG3ftx7su7klWYN80s/fHvgk7A5H2fF3oUTNLcyTbw + GitRestAuth: + secure: E3bCMe4LtDdAhHSYRcLp0N6DixJe1m8TNxhYeJW/GnqM3WXdRqsgkHSbwootPjJQtOQJrps4twmzTVzofLSVgPgbzU8PxU0AkJV7zwkyVOE= init: - git config --global core.autocrlf true @@ -244,7 +271,6 @@ - bundle config --local path vendor/bundle - gem install bundler --quiet --no-ri --no-rdoc - gem install github_changelog_generator --quiet --no-ri --no-rdoc - # - bundle install - choco install gitversion.portable -pre -y - ps: .\install-vsix-appveyor.ps1 @@ -255,46 +281,45 @@ nuget restore source\nanoFramework.Networking.Sntp.sln - gitversion /l console /output buildserver /updateAssemblyInfo /ensureassemblyinfo + C:\ProgramData\chocolatey\lib\GitVersion.Portable\tools\GitVersion.exe /l console /output buildserver /updateAssemblyInfo "source\nanoFramework.Runtime.Events\Properties\AssemblyInfo.cs" build_script: - ps: >- msbuild source\nanoFramework.Networking.Sntp.sln /p:Configuration=Release /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" - before_deploy: - # need this to keep ruby happy - - ps: md c:\tmp - - bundle exec github_changelog_generator --token %GitHubToken% - # add here the updated changelog and the updated assembly info files - - git add . - - git commit --amend --no-edit + on_success: + # for this environment variable to work here it has to be set in AppVeyor UI + - nuget push source\Nuget.nanoFramework.Runtime.Events\bin\Release\nanoFramework.Runtime.Events.%GitVersion_NuGetVersionV2%.nupkg %MyGetToken% -Source https://www.myget.org/F/nanoframework-dev/api/v2/package + - nuget push source\Nuget.nanoFramework.Runtime.Events.DELIVERABLES\bin\Release\nanoFramework.Runtime.Events.DELIVERABLES.%GitVersion_NuGetVersionV2%.nupkg %MyGetToken% -Source https://www.myget.org/F/nanoframework-dev/api/v2/package artifacts: - path: '**\bin\Release\*.nupkg' name: Nuget_Packages deploy: - - provider: NuGet - api_key: - secure: NSRDXbS8tmzOy4wStGuO3yQMKI8Sk10vF8iQtz9ZDXEnHfwnuDdnXbr/Kno3MMvY - skip_symbols: true - - provider: GitHub tag: v$(GitVersion_NuGetVersionV2) release: nanoFramework.Networking.Sntp Library v$(gitversion_semver) - description: '[CHANGELOG.md](https://github.com/nanoframework/lib-nanoFramework.Networking.Sntp/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.Networking.Sntp/$(GitVersion_NuGetVersionV2)) v$(GitVersion_NuGetVersionV2)' + description: 'Check the [changelog](https://github.com/nanoframework/lib-nanoFramework.Runtime.Events/blob/$(appveyor_repo_branch)/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.Runtime.Events/$(GitVersion_NuGetVersionV2)) v$(GitVersion_NuGetVersionV2)' auth_token: secure: DNixoFFE+pGlwyhj7McfZoln42vOmj0iY1iNV9zXEr3y0NpXlOIgL8k5ehzlFM1S artifact: Nuget_Packages draft: true prerelease: true force_update: true + + before_deploy: + - ps: >- + .\commit-assemblyinfo-changes.ps1 + + .\generate-change-log.ps1 + # requires APPVEYOR_DISCORD_WEBHOOK_URL enviroment variable set with Discord webhook URL on_failure: - ps: | - cd .. + cd $env:APPVEYOR_BUILD_FOLDER .\appveyor-discord.ps1 failure $env:APPVEYOR_DISCORD_WEBHOOK_URL diff --git a/commit-assemblyinfo-changes.ps1 b/commit-assemblyinfo-changes.ps1 new file mode 100644 index 0000000..5457374 --- /dev/null +++ b/commit-assemblyinfo-changes.ps1 @@ -0,0 +1,82 @@ +# only need to commit assembly info changes when build is NOT for a pull-request +if ($env:appveyor_pull_request_number) +{ + 'Skip committing assembly info changes as this is a PR build...' | Write-Host -ForegroundColor White +} +else +{ + # updated assembly info files + git add "source\nanoFramework.Networking.Sntp\Properties\AssemblyInfo.cs" + git commit -m "Update assembly info file for v$env:GitVersion_NuGetVersionV2" + git push origin --porcelain -q > $null + + 'Updated assembly info...' | Write-Host -ForegroundColor White -NoNewline + 'OK' | Write-Host -ForegroundColor Green + + # 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 + + # new branch name + $newBranch = "$env:APPVEYOR_REPO_BRANCH-nfbot/update-version/nanoFramework.Networking.Sntp/$env:GitVersion_NuGetVersionV2" + + # create branch to perform updates + git checkout -b "$newBranch" develop -q + + # replace version in assembly declaration + $newVersion = $env:GitVersion_AssemblySemFileVer -replace "\." , ", " + $newVersion = "{ $newVersion }" + + $versionRegex = "\{\s*\d+\,\s*\d+\,\s*\d+\,\s*\d+\s*}" + $assemblyFiles = (Get-ChildItem -Path ".\*" -Include "nf_networking_sntp.cpp" -Recurse) + + foreach($file in $assemblyFiles) + { + $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 .. + } + else + { + $commitMessage = "Update nanoFramework.Networking.Sntp version to $env:GitVersion_AssemblySemFileVer" + + # commit changes + git add -A 2>&1 + git commit -m"$commitMessage" -m"[version update]" -q + git push --set-upstream origin "$newBranch" --porcelain -q > $null + + # start PR + $prRequestBody = @{title="$commitMessage";body="$commitMessage`nStarted with https://github.com/$env:APPVEYOR_REPO_NAME/commit/$env:APPVEYOR_REPO_COMMIT`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 new file mode 100644 index 0000000..0211a72 --- /dev/null +++ b/generate-change-log.ps1 @@ -0,0 +1,20 @@ +# generate change log when build is NOT for a pull-request +if ($env:appveyor_pull_request_number) +{ + 'Skip change log processing as this is a PR build...' | Write-Host -ForegroundColor White +} +else +{ + # need this to keep ruby happy + md c:\tmp + + # generate change log + # version includes commits + bundle exec github_changelog_generator --token $env:GitHubToken + + # updated changelog and the updated assembly info files + git add CHANGELOG.md + git commit -m "Update CHANGELOG for v$env:GitVersion_NuGetVersionV2" + # need to wrap the git command bellow so it doesn't throw an error because of redirecting the output to stderr + git push origin --porcelain | Write-Host +}