Permalink
Browse files

Add CI scripts

  • Loading branch information...
1 parent 3542be4 commit 3b3d0d05b54f8e6b75d6fd356a4ad156448b9ade @ChrisMaddock ChrisMaddock committed Oct 18, 2016
View
@@ -190,4 +190,7 @@ _Pvt_Extensions/
ModelManifest.xml
# Cake tools
-tools/*
+tools/*
+
+# NuGet restore
+*/project.lock.json
View
@@ -0,0 +1,5 @@
+build_script:
+ - ps: .\build.ps1 -Target "Appveyor"
+
+# disable built-in tests.
+test: off
View
@@ -1,50 +1,78 @@
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
+
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
//////////////////////////////////////////////////////////////////////
// PREPARATION
//////////////////////////////////////////////////////////////////////
-// Get whether or not this is a local build.
-var local = BuildSystem.IsLocalBuild;
-var isRunningOnUnix = IsRunningOnUnix();
-var isRunningOnWindows = IsRunningOnWindows();
+var isLocal = BuildSystem.IsLocalBuild;
var isRunningOnAppVeyor = AppVeyor.IsRunningOnAppVeyor;
-var isPullRequest = AppVeyor.Environment.PullRequest.IsPullRequest;
-
-// Versioning
-var packageVersion = "3.0.1";
-var packageModifier = "";
-var displayVersion = "3.0.1";
-
-var semVersion = packageVersion + packageModifier;
+var version = "3.0.1";
+var packageModifier = configuration == "Debug" ? "-dbg" : "";
// Directories
-var basePath = Directory(".");
-var outputDirectory = basePath + Directory("bin") + Directory(configuration);
-var androidDirectory = basePath + Directory("src/runner/nunit.runner.Droid/bin") + Directory(configuration);
-var iosDirectory = basePath + Directory("src/runner/nunit.runner.iOS/bin/AnyCPU") + Directory(configuration);
-var wp81Directory = basePath + Directory("src/runner/nunit.runner.wp81/bin") + Directory(configuration);
+var basePath = Context.Environment.WorkingDirectory.FullPath;
+var outputDirectory = basePath + "bin" + configuration;
+var androidDirectory = basePath + "src/runner/nunit.runner.Droid/bin" + configuration;
+var iosDirectory = basePath + "src/runner/nunit.runner.iOS/bin/AnyCPU" + configuration;
+var wp81Directory = basePath + "src/runner/nunit.runner.wp81/bin" + configuration;
-///////////////////////////////////////////////////////////////////////////////
-// SETUP / TEARDOWN
-///////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////
+// SET VERSION
+//////////////////////////////////////////////////////////////////////
-Setup(() =>
+Task("Set-Appveyor-Tag")
+ .WithCriteria(() => isRunningOnAppVeyor)
+ .Does(() =>
{
- Information("Building version {0} of Nunit.Xamarin.", semVersion);
+ var tag = AppVeyor.Environment.Repository.Tag;
+
+ if (tag.IsTag)
+ {
+ version = tag.Name;
+ }
+ else
+ {
+ var buildNumber = AppVeyor.Environment.Build.Number.ToString("00000");
+ var branch = AppVeyor.Environment.Repository.Branch;
+ var isPullRequest = AppVeyor.Environment.PullRequest.IsPullRequest;
+
+ if (branch == "master" && !isPullRequest)
+ {
+ version = version + "-dev-" + buildNumber + packageModifier;
+ }
+ else
+ {
+ var suffix = "-ci-" + buildNumber + packageModifier;
+
+ if (isPullRequest)
+ suffix += "-pr-" + AppVeyor.Environment.PullRequest.Number;
+ else if (AppVeyor.Environment.Repository.Branch.StartsWith("release", StringComparison.OrdinalIgnoreCase))
+ suffix += "-pre-" + buildNumber;
+ else
+ suffix += "-" + branch;
+
+ // Nuget limits "special version part" to 20 chars. Add one for the hyphen.
+ if (suffix.Length > 21)
+ suffix = suffix.Substring(0, 21);
+
+ version = version + suffix;
+ }
+ }
+
+ AppVeyor.UpdateBuildVersion(version);
});
//////////////////////////////////////////////////////////////////////
-// TASKS
+// CLEAN/BUILD
//////////////////////////////////////////////////////////////////////
Task("Clean")
- .WithCriteria(() => isRunningOnWindows)
.Does(() =>
{
CleanDirectories(new DirectoryPath[] {
@@ -58,50 +86,54 @@ Task("Restore-NuGet-Packages")
Source = new List<string> {
"https://www.nuget.org/api/v2/",
"https://www.myget.org/F/nunit/api/v2"
- }
+ },
+ Verbosity = NuGetVerbosity.Quiet
});
});
Task("Build")
.IsDependentOn("Restore-NuGet-Packages")
.Does(() =>
{
- if(isRunningOnUnix)
- {
- XBuild("./nunit.runner.sln", new XBuildSettings()
- .SetConfiguration("Debug")
- .WithTarget("AnyCPU")
- .WithProperty("TreatWarningsAsErrors", "true")
- .SetVerbosity(Verbosity.Minimal)
- );
- }
- else
- {
- MSBuild("./nunit.runner.sln", new MSBuildSettings()
- .SetConfiguration(configuration)
- .SetPlatformTarget(PlatformTarget.MSIL)
- .WithProperty("TreatWarningsAsErrors", "true")
- .SetVerbosity(Verbosity.Minimal)
- .SetNodeReuse(false)
- );
- }
+ MSBuild("./nunit.runner.sln", new MSBuildSettings()
+ .SetConfiguration(configuration)
+ .SetPlatformTarget(PlatformTarget.MSIL)
+ .WithProperty("TreatWarningsAsErrors", "true")
+ .SetVerbosity(Verbosity.Minimal)
+ .SetNodeReuse(false)
+ );
});
+//////////////////////////////////////////////////////////////////////
+// PACKAGE/PUBLISH
+//////////////////////////////////////////////////////////////////////
+
Task("Create-NuGet-Packages")
.IsDependentOn("Build")
.Does(() =>
{
+ CreateDirectory(outputDirectory);
+
NuGetPack("nuget/nunit.runners.xamarin.nuspec", new NuGetPackSettings
{
- Version = semVersion,
+ Version = version,
BasePath = basePath,
OutputDirectory = outputDirectory,
});
});
+Task("UploadArtifacts")
+ .WithCriteria(() => isRunningOnAppVeyor)
+ .IsDependentOn("Package")
+ .Does(() =>
+{
+ foreach(var package in System.IO.Directory.GetFiles(outputDirectory, "*.nupkg"))
+ AppVeyor.UploadArtifact(package);
+});
+
Task("Publish-NuGet")
.IsDependentOn("Create-NuGet-Packages")
- .WithCriteria(() => local)
+ .WithCriteria(() => isLocal)
.Does(() =>
{
// Resolve the API key.
@@ -111,11 +143,11 @@ Task("Publish-NuGet")
}
// Get the path to the package.
- var packagePath = outputDirectory + File(string.Concat("nunit.runner.xamarin.", semVersion, ".nupkg"));
+ var packagePath = outputDirectory + File(string.Concat("nunit.runner.xamarin.", version, ".nupkg"));
// Push the package.
NuGetPush(packagePath, new NuGetPushSettings {
- ApiKey = apiKey
+ ApiKey = apiKey
});
});
@@ -128,4 +160,9 @@ Task("Package")
Task("Publish")
.IsDependentOn("Publish-NuGet");
+Task("Appveyor")
+ .IsDependentOn("Set-Appveyor-Tag")
+ .IsDependentOn("Package")
+ .IsDependentOn("UploadArtifacts");
+
RunTarget(target);
View
@@ -1,83 +0,0 @@
-#!/bin/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="Default"
-CONFIGURATION="Release"
-VERBOSITY="verbose"
-DRYRUN=false
-SHOW_VERSION=false
-
-# 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=true ;;
- --version) SHOW_VERSION=true ;;
- 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/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://www.nuget.org/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
- mono "$CAKE_EXE" -version
-elif $DRYRUN; then
- mono "$CAKE_EXE" $SCRIPT -verbosity=$VERBOSITY -configuration=$CONFIGURATION -target=$TARGET -dryrun
-else
- mono "$CAKE_EXE" $SCRIPT -verbosity=$VERBOSITY -configuration=$CONFIGURATION -target=$TARGET
-fi
-
-exit $?
Oops, something went wrong.

0 comments on commit 3b3d0d0

Please sign in to comment.