Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/appveyor #106

Merged
merged 2 commits into from
Aug 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,6 @@ paket-files/
/*.DS_Store
/src/.DS_Store
project.json

# Archive files
*.zip
11 changes: 11 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 1.0.{build}
image: Visual Studio 2017
build_script:
- ps: >-
cd .\build\

.\install-dotnet-script.ps1
- cmd:
dotnet .\dotnet-script\publish\dotnet-script.dll build.csx

test: off
8 changes: 8 additions & 0 deletions build/Build.csx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#! "netcoreapp1.1"
#r "nuget:NetStandard.Library,1.6.1"
#load "DotNet.csx"

DotNet.Build(@"..\src\Dotnet.Script");
DotNet.Build(@"..\src\Dotnet.Script.Tests");
DotNet.Test(@"..\src\Dotnet.Script.Tests");

47 changes: 47 additions & 0 deletions build/Command.csx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#r "nuget:System.Diagnostics.Process, 4.3.0"
#load "Logger.csx"
using System.Diagnostics;
using System.Threading;
using System.Text.RegularExpressions;

public static class Command
{
public static void Execute(string commandPath, string arguments)
{
var startInformation = CreateProcessStartInfo(commandPath, arguments);
var process = CreateProcess(startInformation);
RunAndWait(process);

if (process.ExitCode != 0)
{
throw new InvalidOperationException("Command failed");
}
}

private static ProcessStartInfo CreateProcessStartInfo(string commandPath, string arguments)
{
var startInformation = new ProcessStartInfo($"\"{commandPath}\"");
startInformation.CreateNoWindow = true;
startInformation.Arguments = arguments;
startInformation.RedirectStandardOutput = true;
startInformation.RedirectStandardError = true;
startInformation.UseShellExecute = false;
return startInformation;
}

private static void RunAndWait(Process process)
{
process.Start();
process.BeginErrorReadLine();
process.BeginOutputReadLine();
process.WaitForExit();
}
private static Process CreateProcess(ProcessStartInfo startInformation)
{
var process = new Process();
process.StartInfo = startInformation;
process.OutputDataReceived += (s,e) => Logger.Log(e.Data);
process.ErrorDataReceived += (s,e) => Logger.Log(e.Data);
return process;
}
}
30 changes: 30 additions & 0 deletions build/DotNet.csx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#load "Command.csx"
#load "FileUtils.csx"

public static class DotNet
{
public static void Test(string pathToProjectFolder)
{
string pathToTestProject = FindProjectFile(pathToProjectFolder);
Command.Execute("dotnet.exe","test " + pathToTestProject + " --configuration Release");
}

public static void Pack(string pathToProjectFolder, string pathToPackageOutputFolder)
{
string pathToProjectFile = FindProjectFile(pathToProjectFolder);
Command.Execute("dotnet.exe",$"pack {pathToProjectFile} --configuration Release --output {pathToPackageOutputFolder} ");
}

public static void Build(string pathToProjectFolder)
{
string pathToProjectFile = FindProjectFile(pathToProjectFolder);
Command.Execute("dotnet.exe","--version");
Command.Execute("dotnet.exe","restore " + pathToProjectFile);
Command.Execute("dotnet.exe","build " + pathToProjectFile + " --configuration Release");
}

private static string FindProjectFile(string pathToProjectFolder)
{
return FileUtils.FindFile(pathToProjectFolder, "*.csproj");
}
}
Binary file not shown.
118 changes: 118 additions & 0 deletions build/FileUtils.csx
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#load "Logger.csx"
#load "Command.csx"
using System.Text.RegularExpressions;


public static class FileUtils
{
public static void ReplaceInFile(string pattern, string value, string pathToFile)
{
var source = ReadFile(pathToFile);
var replacedSource = Regex.Replace(source, pattern, value);
WriteFile(pathToFile, replacedSource);
}


public static string ReadFile(string pathToFile)
{
using (var fileStream = new FileStream(pathToFile, FileMode.Open, FileAccess.Read))
{
using (var reader = new StreamReader(fileStream))
{
return reader.ReadToEnd();
}
}
}

public static void WriteFile(string pathToFile, string content)
{
using (var fileStream = new FileStream(pathToFile, FileMode.Create))
{
using (var writer = new StreamWriter(fileStream))
{
writer.Write(content);
}
}
}

public static string FindFile(string path, string filePattern)
{
Logger.Log($"Looking for {filePattern} in {path}");
string[] pathsToFile = Directory.GetFiles(path, filePattern, SearchOption.AllDirectories).ToArray();
if (pathsToFile.Length > 1)
{
Logger.Log("Found multiple files");
var files = pathsToFile.Select(p => new FileInfo(p));
var file = files.OrderBy(f => f.LastWriteTime).Last();
Logger.Log($"Choosing {file.FullName}");
return file.FullName;
}
else
if (pathsToFile.Length == 0)
{
Logger.Log($"File {filePattern} not found in {path}");
return null;
}
Logger.Log($"Found {pathsToFile[0]}");
return pathsToFile[0];
}

public static string FindDirectory(string path, string filePattern)
{
string pathToFile = FindFile(path, filePattern);
return Path.GetDirectoryName(pathToFile);
}

public static void RemoveDirectory(string path)
{
if (!Directory.Exists(path))
{
return;
}

// http://stackoverflow.com/questions/329355/cannot-delete-directory-with-directory-deletepath-true
foreach (string directory in Directory.GetDirectories(path))
{
RemoveDirectory(directory);
}

try
{
Directory.Delete(path, true);
}
catch (IOException)
{
Directory.Delete(path, true);
}
catch (UnauthorizedAccessException)
{
Directory.Delete(path, true);
}
}

public static void CreateDirectory(string directory)
{
RemoveDirectory(directory);
Directory.CreateDirectory(directory);
}

public static void RoboCopy(string source, string destination, string arguments = null)
{
if (!Directory.Exists(source))
{
throw new InvalidOperationException(string.Format("The directory {0} does not exist", source));
}

Command.Execute("robocopy", string.Format("{0} {1} {2}", source, destination, arguments));
}

public static void CopySolution(string pathToSolutionFolder, string pathToDestinationFolder)
{
if (Directory.Exists(pathToDestinationFolder))
{
CreateDirectory(pathToDestinationFolder);
}

RoboCopy(pathToSolutionFolder, pathToDestinationFolder, "/e /XD bin obj .vs NuGet TestResults packages");
}
}
7 changes: 7 additions & 0 deletions build/Logger.csx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
public static class Logger
{
public static void Log(string message)
{
Console.WriteLine(message);
}
}
6 changes: 6 additions & 0 deletions build/install-dotnet-script.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
$client = New-Object "System.Net.WebClient"
$url = "https://github.com/filipw/dotnet-script/releases/download/0.11.0-beta/dotnet-script.0.11.0-beta.zip"
$file = "$pwd/dotnet-script.zip"
$client.DownloadFile($url,$file)
Expand-Archive $file -DestinationPath $pwd\dotnet-script -Force

5 changes: 5 additions & 0 deletions build/omnisharp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"script": {
"enableScriptNuGetReferences": true
}
}