-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from filipw/feature/appveyor
Feature/appveyor
- Loading branch information
Showing
10 changed files
with
235 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -253,3 +253,6 @@ paket-files/ | |
/*.DS_Store | ||
/src/.DS_Store | ||
project.json | ||
|
||
# Archive files | ||
*.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"script": { | ||
"enableScriptNuGetReferences": true | ||
} | ||
} |