From aaf37c5738c6952ef7ef2c472d2df7587fdea089 Mon Sep 17 00:00:00 2001 From: Gary Ewan Park Date: Thu, 9 Jun 2016 13:44:36 +0100 Subject: [PATCH 01/22] Initial Cake Build Script - Lets see how well this works - Thrown together over lunch - Opening this as a point of discussion --- .gitattributes | 3 + .gitignore | 8 +- .travis.yml | 26 ++---- appveyor.yml | 32 +------ build.cake | 242 +++++++++++++++++++++++++++++++++++++++++++++++++ build.ps1 | 145 +++++++++++++++++++++++++++++ build.sh | 82 +++++++++++++++++ 7 files changed, 487 insertions(+), 51 deletions(-) create mode 100644 build.cake create mode 100644 build.ps1 create mode 100755 build.sh diff --git a/.gitattributes b/.gitattributes index d23fda4b9d..5891e81525 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,6 +1,9 @@ # Auto detect text files and perform LF normalization * text=auto eol=crlf +# Declare files that will always have LF line endings on checkout. +*.sh text eol=lf + # Don't check these into the repo as LF to work around TeamCity bug *.xml -text *.targets -text diff --git a/.gitignore b/.gitignore index fa9646b36e..a615c13e66 100644 --- a/.gitignore +++ b/.gitignore @@ -101,4 +101,10 @@ site/ # Visual Studio Code #################### -.vscode \ No newline at end of file +.vscode + +#################### +# Cake +#################### +/tools +/*.zip \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 7601be96ac..2f95b12cf3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,29 +1,15 @@ language: csharp -solution: src/GitVersion.sln sudo: false mono: - latest os: - linux - osx -before_install: # We need to download nuget.exe due to: https://github.com/travis-ci/travis-ci/issues/5932 +before_install: - git fetch --unshallow # Travis always does a shallow clone, but GitVersion needs the full history including branches and tags - - mkdir -p .nuget - - wget -O .nuget/nuget.exe https://dist.nuget.org/win-x86-commandline/latest/nuget.exe - - mono .nuget/nuget.exe -install: - - mono .nuget/nuget.exe restore src/GitVersion.sln -Verbosity detailed - - mono .nuget/nuget.exe install NUnit.Runners -Version 3.2.1 -OutputDirectory ./src/packages script: - - xbuild ./src/GitVersion.sln /property:Configuration="Debug" /verbosity:detailed - - mono ./build/NuGetCommandLineBuild/tools/GitVersion.exe -l console -output buildserver -updateAssemblyInfo - - xbuild ./src/GitVersion.sln /property:Configuration="Debug" /verbosity:detailed - - mono ./src/packages/NUnit.ConsoleRunner.3.2.1/tools/nunit3-console.exe ./src/GitVersionTask.Tests/bin/Debug/GitVersionTask.Tests.dll ./src/GitVersionCore.Tests/bin/Debug/GitVersionCore.Tests.dll ./src/GitVersionTask.Tests/bin/Debug/GitVersionTask.Tests.dll ./src/GitVersionExe.Tests/bin/Debug/GitVersionExe.Tests.dll --where "cat != NoMono" --noresult - -# -# To run a clean build with Mono, executing just one test, do: -# xbuild ./src/GitVersion.sln /t:Clean /verbosity:quiet && xbuild ./src/GitVersion.sln /property:Configuration="Debug" /verbosity:quiet && mono ./src/packages/NUnit.ConsoleRunner.3.2.1/tools/nunit3-console.exe ./src/GitVersionTask.Tests/bin/Debug/GitVersionTask.Tests.dll ./src/GitVersionCore.Tests/bin/Debug/GitVersionCore.Tests.dll ./src/GitVersionTask.Tests/bin/Debug/GitVersionTask.Tests.dll ./src/GitVersionExe.Tests/bin/Debug/GitVersionExe.Tests.dll --noresult --where "test =~ /TheNameOfTheTest/" -# -# To run a clean build with Mono, executing all tests, do: -# xbuild ./src/GitVersion.sln /t:Clean /verbosity:quiet && xbuild ./src/GitVersion.sln /property:Configuration="Debug" /verbosity:quiet && mono ./src/packages/NUnit.ConsoleRunner.3.2.1/tools/nunit3-console.exe ./src/GitVersionTask.Tests/bin/Debug/GitVersionTask.Tests.dll ./src/GitVersionCore.Tests/bin/Debug/GitVersionCore.Tests.dll ./src/GitVersionTask.Tests/bin/Debug/GitVersionTask.Tests.dll ./src/GitVersionExe.Tests/bin/Debug/GitVersionExe.Tests.dll --noresult --where "cat != NoMono" --noresult -# + - ./build.sh +cache: + directories: + - src/packages + - tools diff --git a/appveyor.yml b/appveyor.yml index 46018c2de1..36c91ac796 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,36 +1,8 @@ -assembly_info: - patch: false - -platform: - - Any CPU - configuration: - Debug build_script: - - cmd: nuget restore src/GitVersion.sln - - cmd: npm i -g tfx-cli - - - cmd: msbuild src/GitVersion.sln "/p:Configuration=%CONFIGURATION%;Platform=%PLATFORM%" - - ps: .\build\NuGetCommandLineBuild\tools\GitVersion.exe /l console /output buildserver /updateAssemblyInfo - - cmd: msbuild src/GitVersion.sln "/p:Configuration=%CONFIGURATION%;Platform=%PLATFORM%" - - - cmd: appveyor PushArtifact "build\NuGetExeBuild\GitVersion.Portable.%GitVersion_NuGetVersion%.nupkg" - - - cmd: appveyor PushArtifact "build\NuGetCommandLineBuild\GitVersion.CommandLine.%GitVersion_NuGetVersion%.nupkg" - - cmd: appveyor PushArtifact "build\NuGetRefBuild\GitVersion.%GitVersion_NuGetVersion%.nupkg" - - cmd: appveyor PushArtifact "build\NuGetTaskBuild\GitVersionTask.%GitVersion_NuGetVersion%.nupkg" - - ps: appveyor PushArtifact ("build\GemBuild\gitversion-$env:GitVersion_MajorMinorPatch" + (&{If($env:GitVersion_PreReleaseTag -eq '' -or $env:GitVersion_PreReleaseTag -eq $null) {""} Else {"."+$env:GitVersion_PreReleaseTag}}) + ".gem") - - - cmd: 7z a "GitVersion_%GitVersion_NuGetVersion%.zip" -r .\build\NuGetCommandLineBuild\Tools\*.* - - cmd: appveyor PushArtifact "GitVersion_%GitVersion_NuGetVersion%.zip" - - - cmd: 7z a "GitVersionTfsBuildTask_%GitVersion_NuGetVersion%.zip" -r .\build\GitVersionTfsTaskBuild\GitVersionTask\*.* - - cmd: appveyor PushArtifact "GitVersionTfsBuildTask_%GitVersion_NuGetVersion%.zip" - - cmd: appveyor PushArtifact "build\GitVersionTfsTaskBuild\gittools.gitversion-%GitVersion_SemVer%.vsix" - -test_script: - - nunit3-console "src\GitVersionTask.Tests\bin\%CONFIGURATION%\GitVersionTask.Tests.dll" "src\GitVersionExe.Tests\bin\%CONFIGURATION%\GitVersionExe.Tests.dll" "src\GitVersionCore.Tests\bin\%CONFIGURATION%\GitVersionCore.Tests.dll" + - ps: .\build.ps1 -Target "AppVeyor" cache: - - src\packages -> **\packages.config # preserve "packages" directory in the root of build folder but will reset it if packages.config is modified + - src\packages -> **\packages.config # preserve "packages" directory in the root of build folder but will reset it if packages.config is modified \ No newline at end of file diff --git a/build.cake b/build.cake new file mode 100644 index 0000000000..970a93a82c --- /dev/null +++ b/build.cake @@ -0,0 +1,242 @@ +#tool "nuget:?package=GitVersion.CommandLine" +#tool "nuget:?package=NUnit.ConsoleRunner" + +var target = Argument("target", "Default"); +var configuration = Argument("configuration", "Release"); + +string version = null; +string nugetVersion = null; +string preReleaseTag = null; +string semVersion = null; +string milestone = null; +bool publishingError = false; +bool IsTagged = (BuildSystem.AppVeyor.Environment.Repository.Tag.IsTag && + !string.IsNullOrWhiteSpace(BuildSystem.AppVeyor.Environment.Repository.Tag.Name)); +bool IsMainGitVersionRepo = StringComparer.OrdinalIgnoreCase.Equals("gittools/gitversion", BuildSystem.AppVeyor.Environment.Repository.Name); +bool IsPullRequest = BuildSystem.AppVeyor.Environment.PullRequest.IsPullRequest; + +Setup(context => +{ + if(!BuildSystem.IsLocalBuild) + { + GitVersion(new GitVersionSettings{ + UpdateAssemblyInfo = true, + LogFilePath = "console", + OutputType = GitVersionOutput.BuildServer + }); + + version = context.EnvironmentVariable("GitVersion_MajorMinorPatch"); + nugetVersion = context.EnvironmentVariable("GitVersion_NuGetVersion"); + preReleaseTag = context.EnvironmentVariable("GitVersion_PreReleaseTag"); + semVersion = context.EnvironmentVariable("GitVersion_LegacySemVerPadded"); + milestone = string.Concat("v", version); + } + + GitVersion assertedVersions = GitVersion(new GitVersionSettings + { + OutputType = GitVersionOutput.Json + }); + + version = assertedVersions.MajorMinorPatch; + nugetVersion = assertedVersions.NuGetVersion; + preReleaseTag = assertedVersions.PreReleaseTag; + semVersion = assertedVersions.LegacySemVerPadded; + milestone = string.Concat("v", version); +}); + +Task("NuGet-Package-Restore") + .Does(() => +{ + NuGetRestore("./src/GitVersion.sln"); +}); + +Task("Build") + .IsDependentOn("NuGet-Package-Restore") + .Does(() => +{ + if(IsRunningOnUnix()) + { + XBuild("./Source/Gep13.Cake.Sample.WebApplication.sln", new XBuildSettings() + .SetConfiguration(configuration) + .WithProperty("POSIX", "True") + .SetVerbosity(Verbosity.Verbose) + ); + } + else + { + MSBuild("./src/GitVersion.sln", new MSBuildSettings() + .SetConfiguration(configuration) + .SetPlatformTarget(PlatformTarget.MSIL) + .WithProperty("Windows", "True") + .UseToolVersion(MSBuildToolVersion.VS2015) + .SetVerbosity(Verbosity.Minimal) + .SetNodeReuse(false)); + } +}); + +Task("Run-NUnit-Tests") + .IsDependentOn("Build") + .Does(() => +{ + NUnit3("src/*.Tests/bin/" + configuration + "/*.Tests.dll"); +}); + +Task("Zip-Files") + .IsDependentOn("Run-NUnit-Tests") + .Does(() => +{ + var files = GetFiles("./build/NuGetCommandLineBuild/Tools/*.*"); + + Zip("./", "GitVersion_" + nugetVersion + ".zip", files); + + files = GetFiles("./build/GitVersionTfsTaskBuild/GitVersionTask/*.*"); + + Zip("./", "GitVersionTfsBuildTask_" + nugetVersion + ".zip", files); +}); + +Task("Create-NuGet-Packages") + .Does(() => +{ + +}); + +Task("Create-Chocolatey-Packages") + .Does(() => +{ + +}); + +Task("Create-Release-Notes") + .Does(() => +{ + //GitReleaseManagerCreate(parameters.GitHub.UserName, parameters.GitHub.Password, "cake-build", "cake", new GitReleaseManagerCreateSettings { + // Milestone = parameters.Version.Milestone, + // Name = parameters.Version.Milestone, + // Prerelease = true, + // TargetCommitish = "main" + //}); +}); + +Task("Package") + .IsDependentOn("Zip-Files") + .IsDependentOn("Create-NuGet-Packages") + .IsDependentOn("Create-Chocolatey-Packages"); + +Task("Upload-AppVeyor-Artifacts") + .IsDependentOn("Package") + .WithCriteria(() => BuildSystem.AppVeyor.IsRunningOnAppVeyor) + .Does(() => +{ + AppVeyor.UploadArtifact("build/NuGetExeBuild/GitVersion.Portable." + nugetVersion +".nupkg"); + AppVeyor.UploadArtifact("build/NuGetCommandLineBuild/GitVersion.CommandLine." + nugetVersion +".nupkg"); + AppVeyor.UploadArtifact("build/NuGetRefBuild/GitVersion." + nugetVersion +".nupkg"); + AppVeyor.UploadArtifact("build/NuGetTaskBuild/GitVersionTask." + nugetVersion +".nupkg"); + AppVeyor.UploadArtifact("build/GitVersionTfsTaskBuild/gittools.gitversion-" + semVersion + ".vsix"); + AppVeyor.UploadArtifact("GitVersion_" + nugetVersion + ".zip"); + AppVeyor.UploadArtifact("GitVersionTfsBuildTask_" + nugetVersion + ".zip"); +}); + +Task("Publish-MyGet") + .IsDependentOn("Package") + .WithCriteria(() => !BuildSystem.IsLocalBuild) + .WithCriteria(() => !IsPullRequest) + .WithCriteria(() => IsMainGitVersionRepo) + .Does(() => +{ + +}) +.OnError(exception => +{ + Information("Publish-MyGet Task failed, but continuing with next Task..."); + publishingError = true; +}); + +Task("Publish-NuGet") + .IsDependentOn("Package") + .WithCriteria(() => !BuildSystem.IsLocalBuild) + .WithCriteria(() => !IsPullRequest) + .WithCriteria(() => IsMainGitVersionRepo) + .WithCriteria(() => IsTagged) + .Does(() => +{ + +}) +.OnError(exception => +{ + Information("Publish-NuGet Task failed, but continuing with next Task..."); + publishingError = true; +}); + +Task("Publish-Chocolatey") + .IsDependentOn("Package") + .WithCriteria(() => !BuildSystem.IsLocalBuild) + .WithCriteria(() => !IsPullRequest) + .WithCriteria(() => IsMainGitVersionRepo) + .WithCriteria(() => IsTagged) + .Does(() => +{ + +}) +.OnError(exception => +{ + Information("Publish-Chocolatey Task failed, but continuing with next Task..."); + publishingError = true; +}); + +Task("Publish-Gem") + .IsDependentOn("Package") + .WithCriteria(() => !BuildSystem.IsLocalBuild) + .WithCriteria(() => !IsPullRequest) + .WithCriteria(() => IsMainGitVersionRepo) + .WithCriteria(() => IsTagged) + .Does(() => +{ + +}) +.OnError(exception => +{ + Information("Publish-Gem Task failed, but continuing with next Task..."); + publishingError = true; +}); + +Task("Publish-GitHub-Release") + .IsDependentOn("Package") + .WithCriteria(() => !BuildSystem.IsLocalBuild) + .WithCriteria(() => !IsPullRequest) + .WithCriteria(() => IsMainGitVersionRepo) + .WithCriteria(() => IsTagged) + .Does(() => +{ + +}) +.OnError(exception => +{ + Information("Publish-GitHub-Release Task failed, but continuing with next Task..."); + publishingError = true; +}); + +Task("AppVeyor") + .IsDependentOn("Upload-AppVeyor-Artifacts") + .IsDependentOn("Publish-MyGet") + .IsDependentOn("Publish-NuGet") + .IsDependentOn("Publish-Chocolatey") + .IsDependentOn("Publish-Gem") + .IsDependentOn("Publish-GitHub-Release") + .Finally(() => +{ + if(publishingError) + { + throw new Exception("An error occurred during the publishing of Cake. All publishing tasks have been attempted."); + } +}); + +Task("Travis") + .IsDependentOn("Run-NUnit-Tests"); + +Task("ReleaseNotes") + .IsDependentOn("Create-Release-Notes"); + +Task("Default") + .IsDependentOn("Package"); + +RunTarget(target); \ No newline at end of file diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 0000000000..18b8560520 --- /dev/null +++ b/build.ps1 @@ -0,0 +1,145 @@ +########################################################################## +# This is the Cake bootstrapper script for PowerShell. +# This file was downloaded from https://github.com/cake-build/resources +# Feel free to change this file to fit your needs. +########################################################################## + +<# + +.SYNOPSIS +This is a Powershell script to bootstrap a Cake build. + +.DESCRIPTION +This Powershell script will download NuGet if missing, restore NuGet tools (including Cake) +and execute your Cake build script with the parameters you provide. + +.PARAMETER Script +The build script to execute. +.PARAMETER Target +The build script target to run. +.PARAMETER Configuration +The build configuration to use. +.PARAMETER Verbosity +Specifies the amount of information to be displayed. +.PARAMETER Experimental +Tells Cake to use the latest Roslyn release. +.PARAMETER WhatIf +Performs a dry run of the build script. +No tasks will be executed. +.PARAMETER Mono +Tells Cake to use the Mono scripting engine. +.PARAMETER SkipToolPackageRestore +Skips restoring of packages. +.PARAMETER ScriptArgs +Remaining arguments are added here. + +.LINK +http://cakebuild.net + +#> + +[CmdletBinding()] +Param( + [string]$Script = "build.cake", + [string]$Target = "Default", + [string]$Configuration = "Release", + [ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")] + [string]$Verbosity = "Verbose", + [switch]$Experimental, + [Alias("DryRun","Noop")] + [switch]$WhatIf, + [switch]$Mono, + [switch]$SkipToolPackageRestore, + [Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)] + [string[]]$ScriptArgs +) + +Write-Host "Preparing to run build script..." + +$PSScriptRoot = split-path -parent $MyInvocation.MyCommand.Definition; +$TOOLS_DIR = Join-Path $PSScriptRoot "tools" +$NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe" +$NUGET_URL = "http://dist.nuget.org/win-x86-commandline/latest/nuget.exe" +$CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe" +$PACKAGES_CONFIG = Join-Path $TOOLS_DIR "packages.config" + +# Should we use mono? +$UseMono = ""; +if($Mono.IsPresent) { + Write-Verbose -Message "Using the Mono based scripting engine." + $UseMono = "-mono" +} + +# Should we use the new Roslyn? +$UseExperimental = ""; +if($Experimental.IsPresent -and !($Mono.IsPresent)) { + Write-Verbose -Message "Using experimental version of Roslyn." + $UseExperimental = "-experimental" +} + +# Is this a dry run? +$UseDryRun = ""; +if($WhatIf.IsPresent) { + $UseDryRun = "-dryrun" +} + +# Make sure tools folder exists +if ((Test-Path $PSScriptRoot) -and !(Test-Path $TOOLS_DIR)) { + Write-Verbose -Message "Creating tools directory..." + New-Item -Path $TOOLS_DIR -Type directory | out-null +} + +# Make sure that packages.config exist. +if (!(Test-Path $PACKAGES_CONFIG)) { + Write-Verbose -Message "Downloading packages.config..." + try { Invoke-WebRequest -Uri http://cakebuild.net/download/bootstrapper/packages -OutFile $PACKAGES_CONFIG } catch { + Throw "Could not download packages.config." + } +} + +# Try find NuGet.exe in path if not exists +if (!(Test-Path $NUGET_EXE)) { + Write-Verbose -Message "Trying to find nuget.exe in PATH..." + $existingPaths = $Env:Path -Split ';' | Where-Object { (![string]::IsNullOrEmpty($_)) -and (Test-Path $_) } + $NUGET_EXE_IN_PATH = Get-ChildItem -Path $existingPaths -Filter "nuget.exe" | Select -First 1 + if ($NUGET_EXE_IN_PATH -ne $null -and (Test-Path $NUGET_EXE_IN_PATH.FullName)) { + Write-Verbose -Message "Found in PATH at $($NUGET_EXE_IN_PATH.FullName)." + $NUGET_EXE = $NUGET_EXE_IN_PATH.FullName + } +} + +# Try download NuGet.exe if not exists +if (!(Test-Path $NUGET_EXE)) { + Write-Verbose -Message "Downloading NuGet.exe..." + try { + (New-Object System.Net.WebClient).DownloadFile($NUGET_URL, $NUGET_EXE) + } catch { + Throw "Could not download NuGet.exe." + } +} + +# Save nuget.exe path to environment to be available to child processed +$ENV:NUGET_EXE = $NUGET_EXE + +# Restore tools from NuGet? +if(-Not $SkipToolPackageRestore.IsPresent) { + Push-Location + Set-Location $TOOLS_DIR + Write-Verbose -Message "Restoring tools from NuGet..." + $NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$TOOLS_DIR`"" + if ($LASTEXITCODE -ne 0) { + Throw "An error occured while restoring NuGet tools." + } + Write-Verbose -Message ($NuGetOutput | out-string) + Pop-Location +} + +# Make sure that Cake has been installed. +if (!(Test-Path $CAKE_EXE)) { + Throw "Could not find Cake.exe at $CAKE_EXE" +} + +# Start Cake +Write-Host "Running build script..." +Invoke-Expression "& `"$CAKE_EXE`" `"$Script`" -target=`"$Target`" -configuration=`"$Configuration`" -verbosity=`"$Verbosity`" $UseMono $UseDryRun $UseExperimental $ScriptArgs" +exit $LASTEXITCODE diff --git a/build.sh b/build.sh new file mode 100755 index 0000000000..3d74a70fb5 --- /dev/null +++ b/build.sh @@ -0,0 +1,82 @@ +#!/usr/bin/env bash +############################################################### +# This is the Cake bootstrapper script that is responsible for +# downloading Cake and all specified tools from NuGet. +############################################################### + +# Define directories. +SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +TOOLS_DIR=$SCRIPT_DIR/tools +NUGET_EXE=$TOOLS_DIR/nuget.exe +CAKE_EXE=$TOOLS_DIR/Cake/Cake.exe + +# Define default arguments. +SCRIPT="build.cake" +TARGET="Travis" +CONFIGURATION="Release" +VERBOSITY="verbose" +DRYRUN= +SHOW_VERSION=false +SCRIPT_ARGUMENTS=() + +# Parse arguments. +for i in "$@"; do + case $1 in + -s|--script) SCRIPT="$2"; shift ;; + -t|--target) TARGET="$2"; shift ;; + -c|--configuration) CONFIGURATION="$2"; shift ;; + -v|--verbosity) VERBOSITY="$2"; shift ;; + -d|--dryrun) DRYRUN="-dryrun" ;; + --version) SHOW_VERSION=true ;; + --) shift; SCRIPT_ARGUMENTS+=("$@"); break ;; + *) SCRIPT_ARGUMENTS+=("$1") ;; + esac + shift +done + +# Make sure the tools folder exist. +if [ ! -d $TOOLS_DIR ]; then + mkdir $TOOLS_DIR +fi + +# Make sure that packages.config exist. +if [ ! -f $TOOLS_DIR/packages.config ]; then + echo "Downloading packages.config..." + curl -Lsfo $TOOLS_DIR/packages.config http://cakebuild.net/download/bootstrapper/packages + if [ $? -ne 0 ]; then + echo "An error occured while downloading packages.config." + exit 1 + fi +fi + +# Download NuGet if it does not exist. +if [ ! -f $NUGET_EXE ]; then + echo "Downloading NuGet..." + curl -Lsfo $NUGET_EXE https://dist.nuget.org/win-x86-commandline/latest/nuget.exe + if [ $? -ne 0 ]; then + echo "An error occured while downloading nuget.exe." + exit 1 + fi +fi + +# Restore tools from NuGet. +pushd $TOOLS_DIR >/dev/null +mono $NUGET_EXE install -ExcludeVersion +if [ $? -ne 0 ]; then + echo "Could not restore NuGet packages." + exit 1 +fi +popd >/dev/null + +# Make sure that Cake has been installed. +if [ ! -f $CAKE_EXE ]; then + echo "Could not find Cake.exe at '$CAKE_EXE'." + exit 1 +fi + +# Start Cake +if $SHOW_VERSION; then + exec mono $CAKE_EXE -version +else + exec mono $CAKE_EXE $SCRIPT -verbosity=$VERBOSITY -configuration=$CONFIGURATION -target=$TARGET $DRYRUN "${SCRIPT_ARGUMENTS[@]}" +fi From c0ea9d9f06a233eeb1f3028a01df4445739c7f77 Mon Sep 17 00:00:00 2001 From: Jake Ginnivan Date: Fri, 1 Jul 2016 17:36:25 +0800 Subject: [PATCH 02/22] Dogfood in build and generate release notes --- build.cake | 219 ++++++++++++++++------------------------------------ deploy.cake | 93 ++++++++++++++++++++++ 2 files changed, 161 insertions(+), 151 deletions(-) create mode 100644 deploy.cake diff --git a/build.cake b/build.cake index 970a93a82c..9480d50fac 100644 --- a/build.cake +++ b/build.cake @@ -1,5 +1,5 @@ -#tool "nuget:?package=GitVersion.CommandLine" #tool "nuget:?package=NUnit.ConsoleRunner" +#tool "nuget:?package=GitReleaseNotes" var target = Argument("target", "Default"); var configuration = Argument("configuration", "Release"); @@ -15,26 +15,60 @@ bool IsTagged = (BuildSystem.AppVeyor.Environment.Repository.Tag.IsTag && bool IsMainGitVersionRepo = StringComparer.OrdinalIgnoreCase.Equals("gittools/gitversion", BuildSystem.AppVeyor.Environment.Repository.Name); bool IsPullRequest = BuildSystem.AppVeyor.Environment.PullRequest.IsPullRequest; -Setup(context => +void Build() +{ + if(IsRunningOnUnix()) + { + XBuild("./src/GitVersion.sln", new XBuildSettings() + .SetConfiguration(configuration) + .WithProperty("POSIX", "True") + .SetVerbosity(Verbosity.Verbose) + ); + } + else + { + MSBuild("./src/GitVersion.sln", new MSBuildSettings() + .SetConfiguration(configuration) + .SetPlatformTarget(PlatformTarget.MSIL) + .WithProperty("Windows", "True") + .UseToolVersion(MSBuildToolVersion.VS2015) + .SetVerbosity(Verbosity.Minimal) + .SetNodeReuse(false)); + } +} + +Task("DogfoodBuild") + .IsDependentOn("NuGet-Package-Restore") + .Does(() => +{ + Build(); +}); + +Task("Version") + .IsDependentOn("DogfoodBuild") + .Does(() => { if(!BuildSystem.IsLocalBuild) { - GitVersion(new GitVersionSettings{ + GitVersion(new GitVersionSettings + { UpdateAssemblyInfo = true, LogFilePath = "console", - OutputType = GitVersionOutput.BuildServer + OutputType = GitVersionOutput.BuildServer, + ToolPath = @"src\GitVersionExe\bin\Release\GitVersion.exe" }); - version = context.EnvironmentVariable("GitVersion_MajorMinorPatch"); - nugetVersion = context.EnvironmentVariable("GitVersion_NuGetVersion"); - preReleaseTag = context.EnvironmentVariable("GitVersion_PreReleaseTag"); - semVersion = context.EnvironmentVariable("GitVersion_LegacySemVerPadded"); + version = EnvironmentVariable("GitVersion_MajorMinorPatch"); + nugetVersion = EnvironmentVariable("GitVersion_NuGetVersion"); + preReleaseTag = EnvironmentVariable("GitVersion_PreReleaseTag"); + semVersion = EnvironmentVariable("GitVersion_LegacySemVerPadded"); milestone = string.Concat("v", version); } GitVersion assertedVersions = GitVersion(new GitVersionSettings { - OutputType = GitVersionOutput.Json + OutputType = GitVersionOutput.Json, + ToolPath = @"src\GitVersionExe\bin\Release\GitVersion.exe" }); version = assertedVersions.MajorMinorPatch; @@ -51,27 +85,11 @@ Task("NuGet-Package-Restore") }); Task("Build") + .IsDependentOn("Version") .IsDependentOn("NuGet-Package-Restore") .Does(() => { - if(IsRunningOnUnix()) - { - XBuild("./Source/Gep13.Cake.Sample.WebApplication.sln", new XBuildSettings() - .SetConfiguration(configuration) - .WithProperty("POSIX", "True") - .SetVerbosity(Verbosity.Verbose) - ); - } - else - { - MSBuild("./src/GitVersion.sln", new MSBuildSettings() - .SetConfiguration(configuration) - .SetPlatformTarget(PlatformTarget.MSIL) - .WithProperty("Windows", "True") - .UseToolVersion(MSBuildToolVersion.VS2015) - .SetVerbosity(Verbosity.Minimal) - .SetNodeReuse(false)); - } + Build(); }); Task("Run-NUnit-Tests") @@ -85,150 +103,48 @@ Task("Zip-Files") .IsDependentOn("Run-NUnit-Tests") .Does(() => { - var files = GetFiles("./build/NuGetCommandLineBuild/Tools/*.*"); - - Zip("./", "GitVersion_" + nugetVersion + ".zip", files); - - files = GetFiles("./build/GitVersionTfsTaskBuild/GitVersionTask/*.*"); - - Zip("./", "GitVersionTfsBuildTask_" + nugetVersion + ".zip", files); -}); - -Task("Create-NuGet-Packages") - .Does(() => -{ - -}); - -Task("Create-Chocolatey-Packages") - .Does(() => -{ - + Zip("./build/NuGetCommandLineBuild/Tools/", "GitVersion_" + nugetVersion + ".zip"); }); Task("Create-Release-Notes") .Does(() => { - //GitReleaseManagerCreate(parameters.GitHub.UserName, parameters.GitHub.Password, "cake-build", "cake", new GitReleaseManagerCreateSettings { - // Milestone = parameters.Version.Milestone, - // Name = parameters.Version.Milestone, - // Prerelease = true, - // TargetCommitish = "main" - //}); + var releaseNotesExitCode = StartProcess( + @"tools\GitReleaseNotes\tools\gitreleasenotes.exe", + new ProcessSettings { Arguments = ". /o artifacts/releasenotes.md" }); + if (string.IsNullOrEmpty(System.IO.File.ReadAllText("./artifacts/releasenotes.md"))) + System.IO.File.WriteAllText("./build/releasenotes.md", "No issues closed since last release"); + + if (releaseNotesExitCode != 0) throw new Exception("Failed to generate release notes"); }); Task("Package") - .IsDependentOn("Zip-Files") - .IsDependentOn("Create-NuGet-Packages") - .IsDependentOn("Create-Chocolatey-Packages"); + .IsDependentOn("Zip-Files"); Task("Upload-AppVeyor-Artifacts") .IsDependentOn("Package") .WithCriteria(() => BuildSystem.AppVeyor.IsRunningOnAppVeyor) .Does(() => { + System.IO.File.WriteAllLines(outputDir + "artifacts", new[]{ + "NuGetExeBuild:GitVersion.Portable." + nugetVersion +".nupkg", + "NuGetCommandLineBuild:GitVersion.CommandLine." + nugetVersion +".nupkg", + "NuGetRefBuild:GitVersion." + nugetVersion +".nupkg", + "NuGetTaskBuild:GitVersionTask." + nugetVersion +".nupkg", + "NuGetExeBuild:GitVersion.Portable." + nugetVersion +".nupkg", + "zip:GitVersion_" + nugetVersion + ".zip", + "releaseNotes:releasenotes.md" + }); + AppVeyor.UploadArtifact("build/NuGetExeBuild/GitVersion.Portable." + nugetVersion +".nupkg"); AppVeyor.UploadArtifact("build/NuGetCommandLineBuild/GitVersion.CommandLine." + nugetVersion +".nupkg"); AppVeyor.UploadArtifact("build/NuGetRefBuild/GitVersion." + nugetVersion +".nupkg"); AppVeyor.UploadArtifact("build/NuGetTaskBuild/GitVersionTask." + nugetVersion +".nupkg"); AppVeyor.UploadArtifact("build/GitVersionTfsTaskBuild/gittools.gitversion-" + semVersion + ".vsix"); - AppVeyor.UploadArtifact("GitVersion_" + nugetVersion + ".zip"); - AppVeyor.UploadArtifact("GitVersionTfsBuildTask_" + nugetVersion + ".zip"); -}); - -Task("Publish-MyGet") - .IsDependentOn("Package") - .WithCriteria(() => !BuildSystem.IsLocalBuild) - .WithCriteria(() => !IsPullRequest) - .WithCriteria(() => IsMainGitVersionRepo) - .Does(() => -{ - -}) -.OnError(exception => -{ - Information("Publish-MyGet Task failed, but continuing with next Task..."); - publishingError = true; -}); - -Task("Publish-NuGet") - .IsDependentOn("Package") - .WithCriteria(() => !BuildSystem.IsLocalBuild) - .WithCriteria(() => !IsPullRequest) - .WithCriteria(() => IsMainGitVersionRepo) - .WithCriteria(() => IsTagged) - .Does(() => -{ - -}) -.OnError(exception => -{ - Information("Publish-NuGet Task failed, but continuing with next Task..."); - publishingError = true; -}); - -Task("Publish-Chocolatey") - .IsDependentOn("Package") - .WithCriteria(() => !BuildSystem.IsLocalBuild) - .WithCriteria(() => !IsPullRequest) - .WithCriteria(() => IsMainGitVersionRepo) - .WithCriteria(() => IsTagged) - .Does(() => -{ - -}) -.OnError(exception => -{ - Information("Publish-Chocolatey Task failed, but continuing with next Task..."); - publishingError = true; -}); - -Task("Publish-Gem") - .IsDependentOn("Package") - .WithCriteria(() => !BuildSystem.IsLocalBuild) - .WithCriteria(() => !IsPullRequest) - .WithCriteria(() => IsMainGitVersionRepo) - .WithCriteria(() => IsTagged) - .Does(() => -{ - -}) -.OnError(exception => -{ - Information("Publish-Gem Task failed, but continuing with next Task..."); - publishingError = true; -}); - -Task("Publish-GitHub-Release") - .IsDependentOn("Package") - .WithCriteria(() => !BuildSystem.IsLocalBuild) - .WithCriteria(() => !IsPullRequest) - .WithCriteria(() => IsMainGitVersionRepo) - .WithCriteria(() => IsTagged) - .Does(() => -{ - -}) -.OnError(exception => -{ - Information("Publish-GitHub-Release Task failed, but continuing with next Task..."); - publishingError = true; + AppVeyor.UploadArtifact("build/GitVersion_" + nugetVersion + ".zip"); + AppVeyor.UploadArtifact("build/GitVersionTfsBuildTask_" + nugetVersion + ".zip"); }); -Task("AppVeyor") - .IsDependentOn("Upload-AppVeyor-Artifacts") - .IsDependentOn("Publish-MyGet") - .IsDependentOn("Publish-NuGet") - .IsDependentOn("Publish-Chocolatey") - .IsDependentOn("Publish-Gem") - .IsDependentOn("Publish-GitHub-Release") - .Finally(() => -{ - if(publishingError) - { - throw new Exception("An error occurred during the publishing of Cake. All publishing tasks have been attempted."); - } -}); Task("Travis") .IsDependentOn("Run-NUnit-Tests"); @@ -237,6 +153,7 @@ Task("ReleaseNotes") .IsDependentOn("Create-Release-Notes"); Task("Default") - .IsDependentOn("Package"); + .IsDependentOn("Package") + .IsDependentOn("Upload-AppVeyor-Artifacts"); RunTarget(target); \ No newline at end of file diff --git a/deploy.cake b/deploy.cake new file mode 100644 index 0000000000..1d42ad8ebf --- /dev/null +++ b/deploy.cake @@ -0,0 +1,93 @@ + +Task("Publish-MyGet") + .IsDependentOn("Package") + .WithCriteria(() => !BuildSystem.IsLocalBuild) + .WithCriteria(() => !IsPullRequest) + .WithCriteria(() => IsMainGitVersionRepo) + .Does(() => +{ + +}) +.OnError(exception => +{ + Information("Publish-MyGet Task failed, but continuing with next Task..."); + publishingError = true; +}); + +Task("Publish-NuGet") + .IsDependentOn("Package") + .WithCriteria(() => !BuildSystem.IsLocalBuild) + .WithCriteria(() => !IsPullRequest) + .WithCriteria(() => IsMainGitVersionRepo) + .WithCriteria(() => IsTagged) + .Does(() => +{ + +}) +.OnError(exception => +{ + Information("Publish-NuGet Task failed, but continuing with next Task..."); + publishingError = true; +}); + +Task("Publish-Chocolatey") + .IsDependentOn("Package") + .WithCriteria(() => !BuildSystem.IsLocalBuild) + .WithCriteria(() => !IsPullRequest) + .WithCriteria(() => IsMainGitVersionRepo) + .WithCriteria(() => IsTagged) + .Does(() => +{ + +}) +.OnError(exception => +{ + Information("Publish-Chocolatey Task failed, but continuing with next Task..."); + publishingError = true; +}); + +Task("Publish-Gem") + .IsDependentOn("Package") + .WithCriteria(() => !BuildSystem.IsLocalBuild) + .WithCriteria(() => !IsPullRequest) + .WithCriteria(() => IsMainGitVersionRepo) + .WithCriteria(() => IsTagged) + .Does(() => +{ + +}) +.OnError(exception => +{ + Information("Publish-Gem Task failed, but continuing with next Task..."); + publishingError = true; +}); + +Task("Publish-GitHub-Release") + .IsDependentOn("Package") + .WithCriteria(() => !BuildSystem.IsLocalBuild) + .WithCriteria(() => !IsPullRequest) + .WithCriteria(() => IsMainGitVersionRepo) + .WithCriteria(() => IsTagged) + .Does(() => +{ + +}) +.OnError(exception => +{ + Information("Publish-GitHub-Release Task failed, but continuing with next Task..."); + publishingError = true; +}); + +Task("Deploy") + .IsDependentOn("Publish-MyGet") + .IsDependentOn("Publish-NuGet") + .IsDependentOn("Publish-Chocolatey") + .IsDependentOn("Publish-Gem") + .IsDependentOn("Publish-GitHub-Release") + .Finally(() => +{ + if(publishingError) + { + throw new Exception("An error occurred during the publishing of Cake. All publishing tasks have been attempted."); + } +}); \ No newline at end of file From c39d96f2c51ae10e405fb9187c5286ed98438e86 Mon Sep 17 00:00:00 2001 From: Jake Ginnivan Date: Fri, 1 Jul 2016 17:47:13 +0800 Subject: [PATCH 03/22] Fixed few issues --- build.cake | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.cake b/build.cake index 9480d50fac..24b886b2ae 100644 --- a/build.cake +++ b/build.cake @@ -111,8 +111,8 @@ Task("Create-Release-Notes") { var releaseNotesExitCode = StartProcess( @"tools\GitReleaseNotes\tools\gitreleasenotes.exe", - new ProcessSettings { Arguments = ". /o artifacts/releasenotes.md" }); - if (string.IsNullOrEmpty(System.IO.File.ReadAllText("./artifacts/releasenotes.md"))) + new ProcessSettings { Arguments = ". /o build/releasenotes.md" }); + if (string.IsNullOrEmpty(System.IO.File.ReadAllText("./build/releasenotes.md"))) System.IO.File.WriteAllText("./build/releasenotes.md", "No issues closed since last release"); if (releaseNotesExitCode != 0) throw new Exception("Failed to generate release notes"); @@ -126,7 +126,7 @@ Task("Upload-AppVeyor-Artifacts") .WithCriteria(() => BuildSystem.AppVeyor.IsRunningOnAppVeyor) .Does(() => { - System.IO.File.WriteAllLines(outputDir + "artifacts", new[]{ + System.IO.File.WriteAllLines("build/artifacts", new[]{ "NuGetExeBuild:GitVersion.Portable." + nugetVersion +".nupkg", "NuGetCommandLineBuild:GitVersion.CommandLine." + nugetVersion +".nupkg", "NuGetRefBuild:GitVersion." + nugetVersion +".nupkg", From 522e310c8d83f62a2b3076d9dd88a61a06b3d13a Mon Sep 17 00:00:00 2001 From: Jake Ginnivan Date: Fri, 1 Jul 2016 21:36:38 +0800 Subject: [PATCH 04/22] Use default target --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 36c91ac796..827a6eac8c 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,7 +2,7 @@ configuration: - Debug build_script: - - ps: .\build.ps1 -Target "AppVeyor" + - ps: .\build.ps1 cache: - src\packages -> **\packages.config # preserve "packages" directory in the root of build folder but will reset it if packages.config is modified \ No newline at end of file From 942c86b8bcfef42d291b5521b311ca7d3edaf936 Mon Sep 17 00:00:00 2001 From: Jake Ginnivan Date: Sat, 2 Jul 2016 09:14:40 +0800 Subject: [PATCH 05/22] Some targets changes --- build.cake | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/build.cake b/build.cake index 24b886b2ae..7402d9f7b7 100644 --- a/build.cake +++ b/build.cake @@ -119,7 +119,8 @@ Task("Create-Release-Notes") }); Task("Package") - .IsDependentOn("Zip-Files"); + .IsDependentOn("Create-Release-Notes") + .IsDependentOn("Zip-Files"); Task("Upload-AppVeyor-Artifacts") .IsDependentOn("Package") @@ -149,11 +150,7 @@ Task("Upload-AppVeyor-Artifacts") Task("Travis") .IsDependentOn("Run-NUnit-Tests"); -Task("ReleaseNotes") - .IsDependentOn("Create-Release-Notes"); - Task("Default") - .IsDependentOn("Package") .IsDependentOn("Upload-AppVeyor-Artifacts"); RunTarget(target); \ No newline at end of file From 92d538c6b57ba99d0bc71c306eb4aefc6cce0a2c Mon Sep 17 00:00:00 2001 From: Jake Ginnivan Date: Sat, 2 Jul 2016 09:29:24 +0800 Subject: [PATCH 06/22] Fixed target ordering issue --- build.cake | 1 + 1 file changed, 1 insertion(+) diff --git a/build.cake b/build.cake index 7402d9f7b7..c3e0237562 100644 --- a/build.cake +++ b/build.cake @@ -107,6 +107,7 @@ Task("Zip-Files") }); Task("Create-Release-Notes") + .IsDependentOn("Build") .Does(() => { var releaseNotesExitCode = StartProcess( From 3bd0c2e0c5467dd59e31b771ed88a4d817a61cf2 Mon Sep 17 00:00:00 2001 From: Jake Ginnivan Date: Sat, 2 Jul 2016 09:56:13 +0800 Subject: [PATCH 07/22] Stopped tests being duplicated (GitVersion.Core existed in each test project folder) --- build.cake | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/build.cake b/build.cake index c3e0237562..b7ae6f3bc2 100644 --- a/build.cake +++ b/build.cake @@ -96,7 +96,10 @@ Task("Run-NUnit-Tests") .IsDependentOn("Build") .Does(() => { - NUnit3("src/*.Tests/bin/" + configuration + "/*.Tests.dll"); + NUnit3(new [] { + "src/GitVersionCore.Tests/bin/" + configuration + "/GitVersionCore.Tests.dll", + "src/GitVersionExe.Tests/bin/" + configuration + "/GitVersionExe.Tests.dll", + "src/GitVersionTask.Tests/bin/" + configuration + "/GitVersionTask.Tests.dll" }); }); Task("Zip-Files") From 596daec02217378827236546f45612bfad96c4c4 Mon Sep 17 00:00:00 2001 From: Jake Ginnivan Date: Sat, 2 Jul 2016 10:29:10 +0800 Subject: [PATCH 08/22] Stop tests being run by appveyor as well as the build script, remove no docs warning in release build --- Build.cmd | 17 ----------------- appveyor.yml | 6 ++++++ src/GitVersion.sln | 9 ++++++--- src/GitVersionCore/GitVersionCore.csproj | 1 + src/GitVersionExe/GitVersionExe.csproj | 1 + src/GitVersionTask/GitVersionTask.csproj | 1 + 6 files changed, 15 insertions(+), 20 deletions(-) delete mode 100644 Build.cmd diff --git a/Build.cmd b/Build.cmd deleted file mode 100644 index 364d1ab554..0000000000 --- a/Build.cmd +++ /dev/null @@ -1,17 +0,0 @@ -@echo on - -set framework=v4.0.30319 -set src=%~dp0src\ - -"%src%.nuget\nuget.exe" restore %src% - -"%SystemDrive%\Windows\Microsoft.NET\Framework\%framework%\MSBuild.exe" "%src%GitVersion.sln" - -rmdir /s /q "%tmp%GitVersion" -md "%tmp%GitVersion" - -xcopy /E "%~dp0build\NuGetCommandLineBuild\tools" "%tmp%GitVersion" - -"%tmp%GitVersion\GitVersion.exe" /l console /output buildserver /updateAssemblyInfo /proj "%src%GitVersion.sln" - -rmdir /s /q "%tmp%GitVersion" diff --git a/appveyor.yml b/appveyor.yml index 827a6eac8c..d2fe53292d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,8 +1,14 @@ +assembly_info: + patch: false + configuration: - Debug build_script: - ps: .\build.ps1 +test: off +skip_tags: true + cache: - src\packages -> **\packages.config # preserve "packages" directory in the root of build folder but will reset it if packages.config is modified \ No newline at end of file diff --git a/src/GitVersion.sln b/src/GitVersion.sln index d9c3232212..5df3d460f1 100644 --- a/src/GitVersion.sln +++ b/src/GitVersion.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.25123.0 +VisualStudioVersion = 14.0.25420.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitVersionExe", "GitVersionExe\GitVersionExe.csproj", "{C3578A7B-09A6-4444-9383-0DEAFA4958BD}" EndProject @@ -18,8 +18,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution ..\.travis.yml = ..\.travis.yml ..\appveyor.yml = ..\appveyor.yml ..\BREAKING CHANGES.md = ..\BREAKING CHANGES.md - ..\Build.cmd = ..\Build.cmd + ..\build.cake = ..\build.cake + ..\build.ps1 = ..\build.ps1 + ..\build.sh = ..\build.sh ..\CONTRIBUTING.md = ..\CONTRIBUTING.md + ..\deploy.cake = ..\deploy.cake ..\GitVersion.yml = ..\GitVersion.yml ..\LICENSE = ..\LICENSE ..\mkdocs.yml = ..\mkdocs.yml @@ -33,9 +36,9 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TfsTask", "TfsTask", "{A0ED1410-E970-45E8-A357-05605E2B7BFF}" ProjectSection(SolutionItems) = preProject GitVersionTfsTask\Create-Vsix.ps1 = GitVersionTfsTask\Create-Vsix.ps1 + GitVersionTfsTask\extension-icon.png = GitVersionTfsTask\extension-icon.png GitVersionTfsTask\GitVersion.ps1 = GitVersionTfsTask\GitVersion.ps1 GitVersionTfsTask\icon.png = GitVersionTfsTask\icon.png - GitVersionTfsTask\extension-icon.png = GitVersionTfsTask\extension-icon.png GitVersionTfsTask\manifest.json = GitVersionTfsTask\manifest.json GitVersionTfsTask\overview.md = GitVersionTfsTask\overview.md GitVersionTfsTask\task.json = GitVersionTfsTask\task.json diff --git a/src/GitVersionCore/GitVersionCore.csproj b/src/GitVersionCore/GitVersionCore.csproj index b6e9fc9b07..e43cb37b2f 100644 --- a/src/GitVersionCore/GitVersionCore.csproj +++ b/src/GitVersionCore/GitVersionCore.csproj @@ -36,6 +36,7 @@ prompt 4 bin\Release\GitVersionCore.xml + 1591 diff --git a/src/GitVersionExe/GitVersionExe.csproj b/src/GitVersionExe/GitVersionExe.csproj index d013548403..4771231277 100644 --- a/src/GitVersionExe/GitVersionExe.csproj +++ b/src/GitVersionExe/GitVersionExe.csproj @@ -38,6 +38,7 @@ 4 false bin\Release\GitVersion.xml + 1591 diff --git a/src/GitVersionTask/GitVersionTask.csproj b/src/GitVersionTask/GitVersionTask.csproj index f73562bfb9..07a3bc47cf 100644 --- a/src/GitVersionTask/GitVersionTask.csproj +++ b/src/GitVersionTask/GitVersionTask.csproj @@ -36,6 +36,7 @@ prompt 4 false + 1591 From f4d620fedb626290ae1ebd46c8b3c40c8b35ce86 Mon Sep 17 00:00:00 2001 From: Jake Ginnivan Date: Sat, 2 Jul 2016 11:55:50 +0800 Subject: [PATCH 09/22] Make sure artifacts get built --- build.cake | 30 ++++++++++---------------- src/GitVersionExe/GitVersionExe.csproj | 1 - 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/build.cake b/build.cake index b7ae6f3bc2..fa10b4b05a 100644 --- a/build.cake +++ b/build.cake @@ -22,6 +22,8 @@ void Build() XBuild("./src/GitVersion.sln", new XBuildSettings() .SetConfiguration(configuration) .WithProperty("POSIX", "True") + .WithProperty("GitVersion_NuGetVersion", nugetVersion) + .WithProperty("GitVersion_SemVer", semVersion) .SetVerbosity(Verbosity.Verbose) ); } @@ -31,6 +33,8 @@ void Build() .SetConfiguration(configuration) .SetPlatformTarget(PlatformTarget.MSIL) .WithProperty("Windows", "True") + .WithProperty("GitVersion_NuGetVersion", nugetVersion) + .WithProperty("GitVersion_SemVer", semVersion) .UseToolVersion(MSBuildToolVersion.VS2015) .SetVerbosity(Verbosity.Minimal) .SetNodeReuse(false)); @@ -48,23 +52,13 @@ Task("Version") .IsDependentOn("DogfoodBuild") .Does(() => { - if(!BuildSystem.IsLocalBuild) + GitVersion(new GitVersionSettings { - GitVersion(new GitVersionSettings - { - UpdateAssemblyInfo = true, - LogFilePath = "console", - OutputType = GitVersionOutput.BuildServer, - ToolPath = @"src\GitVersionExe\bin\Release\GitVersion.exe" - }); - - version = EnvironmentVariable("GitVersion_MajorMinorPatch"); - nugetVersion = EnvironmentVariable("GitVersion_NuGetVersion"); - preReleaseTag = EnvironmentVariable("GitVersion_PreReleaseTag"); - semVersion = EnvironmentVariable("GitVersion_LegacySemVerPadded"); - milestone = string.Concat("v", version); - } - + UpdateAssemblyInfo = true, + LogFilePath = "console", + OutputType = GitVersionOutput.BuildServer, + ToolPath = @"src\GitVersionExe\bin\Release\GitVersion.exe" + }); GitVersion assertedVersions = GitVersion(new GitVersionSettings { OutputType = GitVersionOutput.Json, @@ -75,7 +69,6 @@ Task("Version") nugetVersion = assertedVersions.NuGetVersion; preReleaseTag = assertedVersions.PreReleaseTag; semVersion = assertedVersions.LegacySemVerPadded; - milestone = string.Concat("v", version); }); Task("NuGet-Package-Restore") @@ -106,7 +99,7 @@ Task("Zip-Files") .IsDependentOn("Run-NUnit-Tests") .Does(() => { - Zip("./build/NuGetCommandLineBuild/Tools/", "GitVersion_" + nugetVersion + ".zip"); + Zip("./build/NuGetCommandLineBuild/Tools/", "build/GitVersion_" + nugetVersion + ".zip"); }); Task("Create-Release-Notes") @@ -147,7 +140,6 @@ Task("Upload-AppVeyor-Artifacts") AppVeyor.UploadArtifact("build/NuGetTaskBuild/GitVersionTask." + nugetVersion +".nupkg"); AppVeyor.UploadArtifact("build/GitVersionTfsTaskBuild/gittools.gitversion-" + semVersion + ".vsix"); AppVeyor.UploadArtifact("build/GitVersion_" + nugetVersion + ".zip"); - AppVeyor.UploadArtifact("build/GitVersionTfsBuildTask_" + nugetVersion + ".zip"); }); diff --git a/src/GitVersionExe/GitVersionExe.csproj b/src/GitVersionExe/GitVersionExe.csproj index 4771231277..2c71c9a75e 100644 --- a/src/GitVersionExe/GitVersionExe.csproj +++ b/src/GitVersionExe/GitVersionExe.csproj @@ -177,7 +177,6 @@ - From 6d268203f042ab1d134c2456158b4a838acea3c2 Mon Sep 17 00:00:00 2001 From: Jake Ginnivan Date: Sat, 2 Jul 2016 12:02:35 +0800 Subject: [PATCH 10/22] Make sure tfx is installed before build and only produce artifacts on AppVeyor --- appveyor.yml | 3 +++ build.cake | 20 +++++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index d2fe53292d..d25bd9bb1f 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,3 +1,6 @@ +install: + npm i -g tfx-cli + assembly_info: patch: false diff --git a/build.cake b/build.cake index fa10b4b05a..b549430aea 100644 --- a/build.cake +++ b/build.cake @@ -19,25 +19,27 @@ void Build() { if(IsRunningOnUnix()) { - XBuild("./src/GitVersion.sln", new XBuildSettings() + XBuild("./src/GitVersion.sln", new XBuildSettings() .SetConfiguration(configuration) .WithProperty("POSIX", "True") - .WithProperty("GitVersion_NuGetVersion", nugetVersion) - .WithProperty("GitVersion_SemVer", semVersion) - .SetVerbosity(Verbosity.Verbose) - ); + .SetVerbosity(Verbosity.Verbose)); } else { - MSBuild("./src/GitVersion.sln", new MSBuildSettings() + var msBuildSettings = new MSBuildSettings() .SetConfiguration(configuration) .SetPlatformTarget(PlatformTarget.MSIL) .WithProperty("Windows", "True") - .WithProperty("GitVersion_NuGetVersion", nugetVersion) - .WithProperty("GitVersion_SemVer", semVersion) .UseToolVersion(MSBuildToolVersion.VS2015) .SetVerbosity(Verbosity.Minimal) - .SetNodeReuse(false)); + .SetNodeReuse(false); + + if (BuildSystem.AppVeyor.IsRunningOnAppVeyor) { + msBuildSettings = msBuildSettings + .WithProperty("GitVersion_NuGetVersion", nugetVersion) + .WithProperty("GitVersion_SemVer", semVersion); + } + MSBuild("./src/GitVersion.sln", msBuildSettings); } } From 59075bc7ae94a9b09327685ac6a2dbbfc0b840dc Mon Sep 17 00:00:00 2001 From: Jake Ginnivan Date: Sat, 2 Jul 2016 12:26:58 +0800 Subject: [PATCH 11/22] Pass more variables --- build.cake | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/build.cake b/build.cake index b549430aea..c23c04b6ae 100644 --- a/build.cake +++ b/build.cake @@ -37,7 +37,9 @@ void Build() if (BuildSystem.AppVeyor.IsRunningOnAppVeyor) { msBuildSettings = msBuildSettings .WithProperty("GitVersion_NuGetVersion", nugetVersion) - .WithProperty("GitVersion_SemVer", semVersion); + .WithProperty("GitVersion_SemVer", semVersion) + .WithProperty("GitVersion_MajorMinorPatch", version) + .WithProperty("GitVersion_PreReleaseTag", preReleaseTag); } MSBuild("./src/GitVersion.sln", msBuildSettings); } From e27ed3076b463c154751abf6a87587d6f45786b3 Mon Sep 17 00:00:00 2001 From: Jake Ginnivan Date: Sat, 2 Jul 2016 12:46:14 +0800 Subject: [PATCH 12/22] Upload gem --- build.cake | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/build.cake b/build.cake index c23c04b6ae..b4d2e5f33e 100644 --- a/build.cake +++ b/build.cake @@ -128,12 +128,17 @@ Task("Upload-AppVeyor-Artifacts") .WithCriteria(() => BuildSystem.AppVeyor.IsRunningOnAppVeyor) .Does(() => { + var gem = string.IsNullOrEmpty(preReleaseTag) ? + "gitversion-" + version + ".gem" : + "gitversion-" + version + "." + preReleaseTag + ".gem"; + System.IO.File.WriteAllLines("build/artifacts", new[]{ "NuGetExeBuild:GitVersion.Portable." + nugetVersion +".nupkg", "NuGetCommandLineBuild:GitVersion.CommandLine." + nugetVersion +".nupkg", "NuGetRefBuild:GitVersion." + nugetVersion +".nupkg", "NuGetTaskBuild:GitVersionTask." + nugetVersion +".nupkg", "NuGetExeBuild:GitVersion.Portable." + nugetVersion +".nupkg", + "GemBuild:" + gem, "zip:GitVersion_" + nugetVersion + ".zip", "releaseNotes:releasenotes.md" }); @@ -144,6 +149,7 @@ Task("Upload-AppVeyor-Artifacts") AppVeyor.UploadArtifact("build/NuGetTaskBuild/GitVersionTask." + nugetVersion +".nupkg"); AppVeyor.UploadArtifact("build/GitVersionTfsTaskBuild/gittools.gitversion-" + semVersion + ".vsix"); AppVeyor.UploadArtifact("build/GitVersion_" + nugetVersion + ".zip"); + AppVeyor.UploadArtifact("build/GemBuild/" + gem); }); From f1c37e081f4b09809c3a45408895ea2b6ed16a96 Mon Sep 17 00:00:00 2001 From: Jake Ginnivan Date: Sat, 2 Jul 2016 14:35:55 +0800 Subject: [PATCH 13/22] Setup deploy script --- appveyor.deploy.yml | 11 +++ build.cake | 8 +-- deploy.cake | 171 +++++++++++++++++++++++++++++++++----------- deploy.ps1 | 145 +++++++++++++++++++++++++++++++++++++ 4 files changed, 288 insertions(+), 47 deletions(-) create mode 100644 appveyor.deploy.yml create mode 100644 deploy.ps1 diff --git a/appveyor.deploy.yml b/appveyor.deploy.yml new file mode 100644 index 0000000000..56e8d38394 --- /dev/null +++ b/appveyor.deploy.yml @@ -0,0 +1,11 @@ +install: + npm i -g tfx-cli + +assembly_info: + patch: false + +build_script: + - ps: .\deploy.ps1 + +test: off +skip_non_tags: true diff --git a/build.cake b/build.cake index b4d2e5f33e..75293fdfc8 100644 --- a/build.cake +++ b/build.cake @@ -15,7 +15,7 @@ bool IsTagged = (BuildSystem.AppVeyor.Environment.Repository.Tag.IsTag && bool IsMainGitVersionRepo = StringComparer.OrdinalIgnoreCase.Equals("gittools/gitversion", BuildSystem.AppVeyor.Environment.Repository.Name); bool IsPullRequest = BuildSystem.AppVeyor.Environment.PullRequest.IsPullRequest; -void Build() +void Build(string configuration) { if(IsRunningOnUnix()) { @@ -49,7 +49,7 @@ Task("DogfoodBuild") .IsDependentOn("NuGet-Package-Restore") .Does(() => { - Build(); + Build(configuration); }); Task("Version") @@ -86,7 +86,7 @@ Task("Build") .IsDependentOn("NuGet-Package-Restore") .Does(() => { - Build(); + Build(configuration); }); Task("Run-NUnit-Tests") @@ -137,7 +137,7 @@ Task("Upload-AppVeyor-Artifacts") "NuGetCommandLineBuild:GitVersion.CommandLine." + nugetVersion +".nupkg", "NuGetRefBuild:GitVersion." + nugetVersion +".nupkg", "NuGetTaskBuild:GitVersionTask." + nugetVersion +".nupkg", - "NuGetExeBuild:GitVersion.Portable." + nugetVersion +".nupkg", + "GitVersionTfsTaskBuild:gittools.gitversion." + semVersion +".vsix", "GemBuild:" + gem, "zip:GitVersion_" + nugetVersion + ".zip", "releaseNotes:releasenotes.md" diff --git a/deploy.cake b/deploy.cake index 1d42ad8ebf..29517c37c2 100644 --- a/deploy.cake +++ b/deploy.cake @@ -1,28 +1,94 @@ +#addin "Cake.Json" -Task("Publish-MyGet") - .IsDependentOn("Package") - .WithCriteria(() => !BuildSystem.IsLocalBuild) - .WithCriteria(() => !IsPullRequest) - .WithCriteria(() => IsMainGitVersionRepo) - .Does(() => +using System.Net; +using System.Linq; +using System.Collections.Generic; + +string Get(string url) { + var assetsRequest = WebRequest.CreateHttp(url); + assetsRequest.Method = "GET"; + assetsRequest.Accept = "application/vnd.github.v3+json"; + assetsRequest.UserAgent = "BuildScript"; + + using (var assetsResponse = assetsRequest.GetResponse()) + { + var assetsStream = assetsResponse.GetResponseStream(); + var assetsReader = new StreamReader(assetsStream); + var assetsBody = assetsReader.ReadToEnd(); + return assetsBody; + } +} +Task("EnsureRequirements") + .Does(() => + { + if (!AppVeyor.IsRunningOnAppVeyor) + throw new Exception("Deployment should happen via appveyor"); + + var isTag = + AppVeyor.Environment.Repository.Tag.IsTag && + !string.IsNullOrWhiteSpace(AppVeyor.Environment.Repository.Tag.Name); + if (!isTag) + throw new Exception("Deployment should happen from a published GitHub release"); + }); + +var tag = ""; +Dictionary artifactLookup = null; +Task("UpdateVersionInfo") + .IsDependentOn("EnsureRequirements") + .Does(() => + { + tag = AppVeyor.Environment.Repository.Tag.Name; + AppVeyor.UpdateBuildVersion(tag); + }); + +Task("DownloadGitHubReleaseArtifacts") + .IsDependentOn("UpdateVersionInfo") + .Does(() => + { + var assets_url = ParseJson(Get("https://api.github.com/repos/shouldly/shouldly/releases/tags/" + tag)) + .GetValue("assets_url").Value(); + EnsureDirectoryExists("./releaseArtifacts"); + foreach(var asset in DeserializeJson(Get(assets_url))) + { + DownloadFile(asset.Value("browser_download_url"), "./releaseArtifacts/" + asset.Value("name")); + } + + // Turns .artifacts file into a lookup + artifactLookup = System.IO.File + .ReadAllLines("./releaseArtifacts/artifacts") + .Select(l => l.Split(':')) + .ToDictionary(v => v[0], v => v[1]); + }); + +Task("Publish-NuGetPackage") + .IsDependentOn("DownloadGitHubReleaseArtifacts") + .Does(() => +{ + NuGetPush( + "./releaseArtifacts/" + artifactLookup["NuGetExeBuild"], + new NuGetPushSettings { + ApiKey = EnvironmentVariable("NuGetApiKey"), + Source = "https://www.nuget.org/api/v2/package" + }); }) .OnError(exception => { - Information("Publish-MyGet Task failed, but continuing with next Task..."); + Information("Publish-NuGet Task failed, but continuing with next Task..."); publishingError = true; }); -Task("Publish-NuGet") - .IsDependentOn("Package") - .WithCriteria(() => !BuildSystem.IsLocalBuild) - .WithCriteria(() => !IsPullRequest) - .WithCriteria(() => IsMainGitVersionRepo) - .WithCriteria(() => IsTagged) +Task("Publish-NuGetCommandLine") + .IsDependentOn("DownloadGitHubReleaseArtifacts") .Does(() => { - + NuGetPush( + "./releaseArtifacts/" + artifactLookup["NuGetCommandLineBuild"], + new NuGetPushSettings { + ApiKey = EnvironmentVariable("NuGetApiKey"), + Source = "https://www.nuget.org/api/v2/package" + }); }) .OnError(exception => { @@ -30,60 +96,79 @@ Task("Publish-NuGet") publishingError = true; }); -Task("Publish-Chocolatey") - .IsDependentOn("Package") - .WithCriteria(() => !BuildSystem.IsLocalBuild) - .WithCriteria(() => !IsPullRequest) - .WithCriteria(() => IsMainGitVersionRepo) - .WithCriteria(() => IsTagged) + +Task("Publish-MsBuildTask") + .IsDependentOn("DownloadGitHubReleaseArtifacts") .Does(() => { - + NuGetPush( + "./releaseArtifacts/" + artifactLookup["NuGetTaskBuild"], + new NuGetPushSettings { + ApiKey = EnvironmentVariable("NuGetApiKey"), + Source = "https://www.nuget.org/api/v2/package" + }); }) .OnError(exception => { - Information("Publish-Chocolatey Task failed, but continuing with next Task..."); + Information("Publish-NuGet Task failed, but continuing with next Task..."); publishingError = true; }); -Task("Publish-Gem") - .IsDependentOn("Package") - .WithCriteria(() => !BuildSystem.IsLocalBuild) - .WithCriteria(() => !IsPullRequest) - .WithCriteria(() => IsMainGitVersionRepo) - .WithCriteria(() => IsTagged) +Task("Publish-Chocolatey") + .IsDependentOn("DownloadGitHubReleaseArtifacts") .Does(() => { - + NuGetPush( + "./releaseArtifacts/" + artifactLookup["NuGetExeBuild"], + new NuGetPushSettings { + ApiKey = EnvironmentVariable("ChocolateyApiKey"), + Source = "https://chocolatey.org/api/v2/package" + }); }) .OnError(exception => { - Information("Publish-Gem Task failed, but continuing with next Task..."); + Information("Publish-Chocolatey Task failed, but continuing with next Task..."); publishingError = true; }); -Task("Publish-GitHub-Release") - .IsDependentOn("Package") - .WithCriteria(() => !BuildSystem.IsLocalBuild) - .WithCriteria(() => !IsPullRequest) - .WithCriteria(() => IsMainGitVersionRepo) - .WithCriteria(() => IsTagged) +Task("Publish-Gem") + .IsDependentOn("DownloadGitHubReleaseArtifacts") .Does(() => { + var returnCode = StartProcess("gem", new ProcessSettings + { + Arguments = "push ./releaseArtifacts/" + artifactLookup["NuGetExeBuild"] + " --key " + EnvironmentVariable("GemApiKey") + }); -}) -.OnError(exception => + if (returnCode != 0) { + Information("Publish-Gem Task failed, but continuing with next Task..."); + publishingError = true; + } +}); + + +Task("Publish-VstsTask") + .IsDependentOn("DownloadGitHubReleaseArtifacts") + .Does(() => { - Information("Publish-GitHub-Release Task failed, but continuing with next Task..."); - publishingError = true; + var returnCode = StartProcess("tfx", new ProcessSettings + { + Arguments = "extension publish --vsix ./releaseArtifacts/" + artifactLookup["GitVersionTfsTaskBuild"] + " --no-prompt --auth-type pat --token " + EnvironmentVariable("GemApiKey") + }); + + if (returnCode != 0) { + Information("Publish-VstsTask Task failed, but continuing with next Task..."); + publishingError = true; + } }); Task("Deploy") - .IsDependentOn("Publish-MyGet") - .IsDependentOn("Publish-NuGet") + .IsDependentOn("Publish-NuGetPackage") + .IsDependentOn("Publish-NuGetCommandLine") + .IsDependentOn("Publish-MsBuildTask") .IsDependentOn("Publish-Chocolatey") .IsDependentOn("Publish-Gem") - .IsDependentOn("Publish-GitHub-Release") + .IsDependentOn("Publish-VstsTask") .Finally(() => { if(publishingError) diff --git a/deploy.ps1 b/deploy.ps1 new file mode 100644 index 0000000000..eaf1d62d9a --- /dev/null +++ b/deploy.ps1 @@ -0,0 +1,145 @@ +########################################################################## +# This is the Cake bootstrapper script for PowerShell. +# This file was downloaded from https://github.com/cake-build/resources +# Feel free to change this file to fit your needs. +########################################################################## + +<# + +.SYNOPSIS +This is a Powershell script to bootstrap a Cake build. + +.DESCRIPTION +This Powershell script will download NuGet if missing, restore NuGet tools (including Cake) +and execute your Cake build script with the parameters you provide. + +.PARAMETER Script +The build script to execute. +.PARAMETER Target +The build script target to run. +.PARAMETER Configuration +The build configuration to use. +.PARAMETER Verbosity +Specifies the amount of information to be displayed. +.PARAMETER Experimental +Tells Cake to use the latest Roslyn release. +.PARAMETER WhatIf +Performs a dry run of the build script. +No tasks will be executed. +.PARAMETER Mono +Tells Cake to use the Mono scripting engine. +.PARAMETER SkipToolPackageRestore +Skips restoring of packages. +.PARAMETER ScriptArgs +Remaining arguments are added here. + +.LINK +http://cakebuild.net + +#> + +[CmdletBinding()] +Param( + [string]$Script = "deploy.cake", + [string]$Target = "Default", + [string]$Configuration = "Release", + [ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")] + [string]$Verbosity = "Verbose", + [switch]$Experimental, + [Alias("DryRun","Noop")] + [switch]$WhatIf, + [switch]$Mono, + [switch]$SkipToolPackageRestore, + [Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)] + [string[]]$ScriptArgs +) + +Write-Host "Preparing to run build script..." + +$PSScriptRoot = split-path -parent $MyInvocation.MyCommand.Definition; +$TOOLS_DIR = Join-Path $PSScriptRoot "tools" +$NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe" +$NUGET_URL = "http://dist.nuget.org/win-x86-commandline/latest/nuget.exe" +$CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe" +$PACKAGES_CONFIG = Join-Path $TOOLS_DIR "packages.config" + +# Should we use mono? +$UseMono = ""; +if($Mono.IsPresent) { + Write-Verbose -Message "Using the Mono based scripting engine." + $UseMono = "-mono" +} + +# Should we use the new Roslyn? +$UseExperimental = ""; +if($Experimental.IsPresent -and !($Mono.IsPresent)) { + Write-Verbose -Message "Using experimental version of Roslyn." + $UseExperimental = "-experimental" +} + +# Is this a dry run? +$UseDryRun = ""; +if($WhatIf.IsPresent) { + $UseDryRun = "-dryrun" +} + +# Make sure tools folder exists +if ((Test-Path $PSScriptRoot) -and !(Test-Path $TOOLS_DIR)) { + Write-Verbose -Message "Creating tools directory..." + New-Item -Path $TOOLS_DIR -Type directory | out-null +} + +# Make sure that packages.config exist. +if (!(Test-Path $PACKAGES_CONFIG)) { + Write-Verbose -Message "Downloading packages.config..." + try { Invoke-WebRequest -Uri http://cakebuild.net/download/bootstrapper/packages -OutFile $PACKAGES_CONFIG } catch { + Throw "Could not download packages.config." + } +} + +# Try find NuGet.exe in path if not exists +if (!(Test-Path $NUGET_EXE)) { + Write-Verbose -Message "Trying to find nuget.exe in PATH..." + $existingPaths = $Env:Path -Split ';' | Where-Object { (![string]::IsNullOrEmpty($_)) -and (Test-Path $_) } + $NUGET_EXE_IN_PATH = Get-ChildItem -Path $existingPaths -Filter "nuget.exe" | Select -First 1 + if ($NUGET_EXE_IN_PATH -ne $null -and (Test-Path $NUGET_EXE_IN_PATH.FullName)) { + Write-Verbose -Message "Found in PATH at $($NUGET_EXE_IN_PATH.FullName)." + $NUGET_EXE = $NUGET_EXE_IN_PATH.FullName + } +} + +# Try download NuGet.exe if not exists +if (!(Test-Path $NUGET_EXE)) { + Write-Verbose -Message "Downloading NuGet.exe..." + try { + (New-Object System.Net.WebClient).DownloadFile($NUGET_URL, $NUGET_EXE) + } catch { + Throw "Could not download NuGet.exe." + } +} + +# Save nuget.exe path to environment to be available to child processed +$ENV:NUGET_EXE = $NUGET_EXE + +# Restore tools from NuGet? +if(-Not $SkipToolPackageRestore.IsPresent) { + Push-Location + Set-Location $TOOLS_DIR + Write-Verbose -Message "Restoring tools from NuGet..." + $NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$TOOLS_DIR`"" + if ($LASTEXITCODE -ne 0) { + Throw "An error occured while restoring NuGet tools." + } + Write-Verbose -Message ($NuGetOutput | out-string) + Pop-Location +} + +# Make sure that Cake has been installed. +if (!(Test-Path $CAKE_EXE)) { + Throw "Could not find Cake.exe at $CAKE_EXE" +} + +# Start Cake +Write-Host "Running build script..." +Invoke-Expression "& `"$CAKE_EXE`" `"$Script`" -target=`"$Target`" -configuration=`"$Configuration`" -verbosity=`"$Verbosity`" $UseMono $UseDryRun $UseExperimental $ScriptArgs" +exit $LASTEXITCODE From 65a4b3424cd13d25915595142869315b115883b0 Mon Sep 17 00:00:00 2001 From: Jake Ginnivan Date: Sat, 2 Jul 2016 14:43:51 +0800 Subject: [PATCH 14/22] Fix mono cake build issue --- build.cake | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/build.cake b/build.cake index 75293fdfc8..058799cc26 100644 --- a/build.cake +++ b/build.cake @@ -15,7 +15,7 @@ bool IsTagged = (BuildSystem.AppVeyor.Environment.Repository.Tag.IsTag && bool IsMainGitVersionRepo = StringComparer.OrdinalIgnoreCase.Equals("gittools/gitversion", BuildSystem.AppVeyor.Environment.Repository.Name); bool IsPullRequest = BuildSystem.AppVeyor.Environment.PullRequest.IsPullRequest; -void Build(string configuration) +void Build(string configuration, string nugetVersion, string semVersion, string version, string preReleaseTag) { if(IsRunningOnUnix()) { @@ -34,7 +34,8 @@ void Build(string configuration) .SetVerbosity(Verbosity.Minimal) .SetNodeReuse(false); - if (BuildSystem.AppVeyor.IsRunningOnAppVeyor) { + if (BuildSystem.AppVeyor.IsRunningOnAppVeyor) + { msBuildSettings = msBuildSettings .WithProperty("GitVersion_NuGetVersion", nugetVersion) .WithProperty("GitVersion_SemVer", semVersion) @@ -49,7 +50,7 @@ Task("DogfoodBuild") .IsDependentOn("NuGet-Package-Restore") .Does(() => { - Build(configuration); + Build(configuration, nugetVersion, semVersion, version, preReleaseTag); }); Task("Version") @@ -86,7 +87,7 @@ Task("Build") .IsDependentOn("NuGet-Package-Restore") .Does(() => { - Build(configuration); + Build(configuration, nugetVersion, semVersion, version, preReleaseTag); }); Task("Run-NUnit-Tests") From 86aab0fee432ba41eaf51ffa839ac8dd7d42cf32 Mon Sep 17 00:00:00 2001 From: Jake Ginnivan Date: Sun, 3 Jul 2016 12:40:58 +0800 Subject: [PATCH 15/22] Use dynamic repos on travis --- build.cake | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/build.cake b/build.cake index 058799cc26..cb13747e8d 100644 --- a/build.cake +++ b/build.cake @@ -57,17 +57,26 @@ Task("Version") .IsDependentOn("DogfoodBuild") .Does(() => { + string url = null; + // We need to use dynamic repositories on Travis + if (TravisCI.IsRunningOnTravisCI) + { + url = "https://github.com/GitTools/GitVersion.git"; + } + GitVersion(new GitVersionSettings { UpdateAssemblyInfo = true, LogFilePath = "console", OutputType = GitVersionOutput.BuildServer, - ToolPath = @"src\GitVersionExe\bin\Release\GitVersion.exe" + ToolPath = @"src\GitVersionExe\bin\Release\GitVersion.exe", + Url = url }); GitVersion assertedVersions = GitVersion(new GitVersionSettings { OutputType = GitVersionOutput.Json, - ToolPath = @"src\GitVersionExe\bin\Release\GitVersion.exe" + ToolPath = @"src\GitVersionExe\bin\Release\GitVersion.exe", + Url = url }); version = assertedVersions.MajorMinorPatch; From ed74139607e7aea51780739c85398c1a8a2f5085 Mon Sep 17 00:00:00 2001 From: Jake Ginnivan Date: Sun, 3 Jul 2016 15:25:57 +0800 Subject: [PATCH 16/22] Trying to get travis builds to pass --- .travis.yml | 2 ++ build.cake | 9 +++++++-- src/GitVersion.sln.DotSettings | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2f95b12cf3..2104b4e835 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,8 @@ os: before_install: - git fetch --unshallow # Travis always does a shallow clone, but GitVersion needs the full history including branches and tags script: + - export PR=https://api.github.com/repos/$TRAVIS_REPO_SLUG/pulls/$TRAVIS_PULL_REQUEST + - export BRANCH=$(if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then echo $TRAVIS_BRANCH; else echo `curl -s $PR | jq -r .head.ref`; fi) - ./build.sh cache: directories: diff --git a/build.cake b/build.cake index cb13747e8d..08ea2b6ce5 100644 --- a/build.cake +++ b/build.cake @@ -58,10 +58,13 @@ Task("Version") .Does(() => { string url = null; + string branch = null; // We need to use dynamic repositories on Travis if (TravisCI.IsRunningOnTravisCI) { url = "https://github.com/GitTools/GitVersion.git"; + branch = EnvironmentVariable("BRANCH"); + Information("Travis branch: {0}", branch); } GitVersion(new GitVersionSettings @@ -70,13 +73,15 @@ Task("Version") LogFilePath = "console", OutputType = GitVersionOutput.BuildServer, ToolPath = @"src\GitVersionExe\bin\Release\GitVersion.exe", - Url = url + Url = url, + Branch = branch }); GitVersion assertedVersions = GitVersion(new GitVersionSettings { OutputType = GitVersionOutput.Json, ToolPath = @"src\GitVersionExe\bin\Release\GitVersion.exe", - Url = url + Url = url, + Branch = branch }); version = assertedVersions.MajorMinorPatch; diff --git a/src/GitVersion.sln.DotSettings b/src/GitVersion.sln.DotSettings index 1640e95699..9b2f0d5ba1 100644 --- a/src/GitVersion.sln.DotSettings +++ b/src/GitVersion.sln.DotSettings @@ -549,6 +549,7 @@ II.2.12 <HandlesEvent /> True True True + True True True False From e59a8d6a6768c56c3bb3c68946b4e5977d09cfc0 Mon Sep 17 00:00:00 2001 From: Jake Ginnivan Date: Sun, 3 Jul 2016 15:35:40 +0800 Subject: [PATCH 17/22] Exclude no-mono tests again --- build.cake | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/build.cake b/build.cake index 08ea2b6ce5..16a83689bc 100644 --- a/build.cake +++ b/build.cake @@ -108,10 +108,15 @@ Task("Run-NUnit-Tests") .IsDependentOn("Build") .Does(() => { + var settings = new NUnit3Settings(); + if(IsRunningOnUnix()) + settings.Where = "cat != NoMono"; + } NUnit3(new [] { "src/GitVersionCore.Tests/bin/" + configuration + "/GitVersionCore.Tests.dll", "src/GitVersionExe.Tests/bin/" + configuration + "/GitVersionExe.Tests.dll", - "src/GitVersionTask.Tests/bin/" + configuration + "/GitVersionTask.Tests.dll" }); + "src/GitVersionTask.Tests/bin/" + configuration + "/GitVersionTask.Tests.dll" }, + settings); }); Task("Zip-Files") From b6fa048f10ec46b88269898be7c54874c7ee8152 Mon Sep 17 00:00:00 2001 From: Jake Ginnivan Date: Sun, 3 Jul 2016 15:50:02 +0800 Subject: [PATCH 18/22] Missing brace --- build.cake | 1 + 1 file changed, 1 insertion(+) diff --git a/build.cake b/build.cake index 16a83689bc..ac4b129426 100644 --- a/build.cake +++ b/build.cake @@ -110,6 +110,7 @@ Task("Run-NUnit-Tests") { var settings = new NUnit3Settings(); if(IsRunningOnUnix()) + { settings.Where = "cat != NoMono"; } NUnit3(new [] { From 8385b54f1e76b3dce52b6d72e7969f629b70a1fa Mon Sep 17 00:00:00 2001 From: Jake Ginnivan Date: Sat, 9 Jul 2016 11:15:13 +0800 Subject: [PATCH 19/22] Don't need travis workaround anymore --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2104b4e835..2f95b12cf3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,8 +8,6 @@ os: before_install: - git fetch --unshallow # Travis always does a shallow clone, but GitVersion needs the full history including branches and tags script: - - export PR=https://api.github.com/repos/$TRAVIS_REPO_SLUG/pulls/$TRAVIS_PULL_REQUEST - - export BRANCH=$(if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then echo $TRAVIS_BRANCH; else echo `curl -s $PR | jq -r .head.ref`; fi) - ./build.sh cache: directories: From dd98bde05eca38f5a4444e06e8648dca3219690a Mon Sep 17 00:00:00 2001 From: Jake Ginnivan Date: Sat, 9 Jul 2016 14:55:56 +0800 Subject: [PATCH 20/22] Don't need dynamic repos any more on Travis --- build.cake | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/build.cake b/build.cake index ac4b129426..552c13366c 100644 --- a/build.cake +++ b/build.cake @@ -57,31 +57,17 @@ Task("Version") .IsDependentOn("DogfoodBuild") .Does(() => { - string url = null; - string branch = null; - // We need to use dynamic repositories on Travis - if (TravisCI.IsRunningOnTravisCI) - { - url = "https://github.com/GitTools/GitVersion.git"; - branch = EnvironmentVariable("BRANCH"); - Information("Travis branch: {0}", branch); - } - GitVersion(new GitVersionSettings { UpdateAssemblyInfo = true, LogFilePath = "console", OutputType = GitVersionOutput.BuildServer, - ToolPath = @"src\GitVersionExe\bin\Release\GitVersion.exe", - Url = url, - Branch = branch + ToolPath = @"src\GitVersionExe\bin\Release\GitVersion.exe" }); GitVersion assertedVersions = GitVersion(new GitVersionSettings { OutputType = GitVersionOutput.Json, - ToolPath = @"src\GitVersionExe\bin\Release\GitVersion.exe", - Url = url, - Branch = branch + ToolPath = @"src\GitVersionExe\bin\Release\GitVersion.exe" }); version = assertedVersions.MajorMinorPatch; From a67533c839003ca0a4192064157f766965e9dc37 Mon Sep 17 00:00:00 2001 From: Jake Ginnivan Date: Sat, 9 Jul 2016 15:16:53 +0800 Subject: [PATCH 21/22] Upload test results to appveyor --- build.cake | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/build.cake b/build.cake index 552c13366c..4bca8733ba 100644 --- a/build.cake +++ b/build.cake @@ -104,6 +104,10 @@ Task("Run-NUnit-Tests") "src/GitVersionExe.Tests/bin/" + configuration + "/GitVersionExe.Tests.dll", "src/GitVersionTask.Tests/bin/" + configuration + "/GitVersionTask.Tests.dll" }, settings); + if (BuildSystem.AppVeyor.IsRunningOnAppVeyor) + { + BuildSystem.AppVeyor.UploadTestResults("TestResult.xml", AppVeyorTestResultsType.NUnit3); + } }); Task("Zip-Files") From 249be6986c92fc6152a26d9eb0cf97ed302b39a0 Mon Sep 17 00:00:00 2001 From: Jake Ginnivan Date: Sat, 9 Jul 2016 15:48:38 +0800 Subject: [PATCH 22/22] Added additional logging --- build.cake | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/build.cake b/build.cake index 4bca8733ba..d5005309b4 100644 --- a/build.cake +++ b/build.cake @@ -104,9 +104,10 @@ Task("Run-NUnit-Tests") "src/GitVersionExe.Tests/bin/" + configuration + "/GitVersionExe.Tests.dll", "src/GitVersionTask.Tests/bin/" + configuration + "/GitVersionTask.Tests.dll" }, settings); - if (BuildSystem.AppVeyor.IsRunningOnAppVeyor) + if (AppVeyor.IsRunningOnAppVeyor) { - BuildSystem.AppVeyor.UploadTestResults("TestResult.xml", AppVeyorTestResultsType.NUnit3); + Information("Uploading test results"); + AppVeyor.UploadTestResults("TestResult.xml", AppVeyorTestResultsType.NUnit3); } }); @@ -136,7 +137,7 @@ Task("Package") Task("Upload-AppVeyor-Artifacts") .IsDependentOn("Package") - .WithCriteria(() => BuildSystem.AppVeyor.IsRunningOnAppVeyor) + .WithCriteria(() => AppVeyor.IsRunningOnAppVeyor) .Does(() => { var gem = string.IsNullOrEmpty(preReleaseTag) ?