mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-05-30 09:49:04 +00:00
Add a build task to validate LINQPad samples (#1551)
* add a build task to run LINQPad samples * make modifications to the validation of LINQPad samples * rename the CAKE task to its original name ValidateLINQPadSamples * rename the LINQPad samples file so they get executed in ordinal order (1, 2, ..., 10 and not 1, 10, 2, ...) * remove openssl linking in TravisCI when on macOS
This commit is contained in:
committed by
Ryan Gribble
parent
13d5dab516
commit
3369a4aea1
+2
-1
@@ -103,4 +103,5 @@ Backup/
|
||||
!.vscode/launch.json
|
||||
|
||||
# CAKE
|
||||
tools/
|
||||
tools/*
|
||||
!tools/LINQPad
|
||||
@@ -10,9 +10,6 @@ matrix:
|
||||
osx_image: xcode8
|
||||
dotnet: 1.0.0-preview2-003121
|
||||
|
||||
before_install:
|
||||
- if test "$TRAVIS_OS_NAME" == "osx"; then ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/; ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/; fi
|
||||
|
||||
script:
|
||||
- dotnet --info
|
||||
- ./build.sh
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using Cake.Common.Build;
|
||||
using System.Linq;
|
||||
using Cake.Common;
|
||||
using Cake.Common.Build;
|
||||
using Cake.Common.Diagnostics;
|
||||
using Cake.Core;
|
||||
using Cake.Core.IO;
|
||||
using Cake.Frosting;
|
||||
using System.Linq;
|
||||
|
||||
[Dependency(typeof(Build))]
|
||||
public class LinkSources : FrostingTask<BuildContext>
|
||||
@@ -43,6 +43,6 @@ public class LinkSources : FrostingTask<BuildContext>
|
||||
|
||||
public override bool ShouldRun(BuildContext context)
|
||||
{
|
||||
return !context.Environment.Platform.IsUnix();
|
||||
return context.IsRunningOnWindows();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ using Cake.Frosting;
|
||||
|
||||
[Dependency(typeof(UnitTests))]
|
||||
[Dependency(typeof(LinkSources))]
|
||||
[Dependency(typeof(ValidateLINQPadSamples))]
|
||||
public class Package : FrostingTask<BuildContext>
|
||||
{
|
||||
public override void Run(BuildContext context)
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using Cake.Common;
|
||||
using Cake.Common.Diagnostics;
|
||||
using Cake.Core;
|
||||
using Cake.Core.IO;
|
||||
using Cake.Frosting;
|
||||
|
||||
[Dependency(typeof(Build))]
|
||||
public class ValidateLINQPadSamples : FrostingTask<BuildContext>
|
||||
{
|
||||
public override void Run(BuildContext context)
|
||||
{
|
||||
var assembliesDirectoryPath = context.Environment.WorkingDirectory
|
||||
.Combine("Octokit.Reactive")
|
||||
.Combine("bin")
|
||||
.Combine(context.Configuration)
|
||||
.Combine("net45")
|
||||
.MakeAbsolute(context.Environment)
|
||||
.FullPath;
|
||||
|
||||
var linqpadSamples = context.FileSystem
|
||||
.GetDirectory("samples/linqpad-samples")
|
||||
.GetFiles("*.linq", SearchScope.Current)
|
||||
.Select(x => x.Path)
|
||||
.ToArray();
|
||||
|
||||
var linqpadExe = context.Environment.WorkingDirectory
|
||||
.Combine("tools")
|
||||
.Combine("LINQPad")
|
||||
.CombineWithFilePath("lprun.exe")
|
||||
.MakeAbsolute(context.Environment);
|
||||
|
||||
foreach (var linqpadSample in linqpadSamples)
|
||||
{
|
||||
var sampleName = linqpadSample.GetFilename();
|
||||
var rewrittenSample = RewriteLinqpadScriptToUseLocalAssemblies(assembliesDirectoryPath, linqpadSample.FullPath);
|
||||
|
||||
context.Information("Executing sample {0}...", sampleName);
|
||||
var exitCode = context.StartProcess(
|
||||
linqpadExe,
|
||||
$"-compileonly -lang=Program {rewrittenSample}");
|
||||
|
||||
if (exitCode != 0)
|
||||
{
|
||||
throw new CakeException($"Execution of sample {sampleName} failed");
|
||||
}
|
||||
}
|
||||
|
||||
context.Information("All samples executed successfully");
|
||||
}
|
||||
|
||||
public override bool ShouldRun(BuildContext context)
|
||||
{
|
||||
return context.IsRunningOnWindows();
|
||||
}
|
||||
|
||||
private static string RewriteLinqpadScriptToUseLocalAssemblies(string directory, string filePath)
|
||||
{
|
||||
var text = File.ReadAllText(filePath);
|
||||
|
||||
var openTag = "<Query Kind=\"Program\">";
|
||||
var openTagIndex = text.IndexOf(openTag);
|
||||
var closeTag = "</Query>";
|
||||
var closeTagIndex = text.IndexOf(closeTag);
|
||||
|
||||
if (openTagIndex == -1 || closeTagIndex == -1)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
var endOfMetadata = closeTagIndex + closeTag.Length;
|
||||
|
||||
// write to temp file on disk
|
||||
var tempFilePath = System.IO.Path.GetTempFileName();
|
||||
|
||||
using (var stream = File.OpenWrite(tempFilePath))
|
||||
using (var writer = new StreamWriter(stream))
|
||||
{
|
||||
// reference all known assemblies
|
||||
writer.WriteLine("ref {0}\\System.Reactive.Core.dll;", directory);
|
||||
writer.WriteLine("ref {0}\\System.Reactive.Interfaces.dll;", directory);
|
||||
writer.WriteLine("ref {0}\\System.Reactive.Linq.dll;", directory);
|
||||
writer.WriteLine("ref {0}\\Octokit.dll;", directory);
|
||||
writer.WriteLine("ref {0}\\Octokit.Reactive.dll;", directory);
|
||||
writer.WriteLine("ref C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.5\\System.Net.Http.dll;");
|
||||
writer.WriteLine();
|
||||
|
||||
var xmlText = text.Substring(openTagIndex, endOfMetadata);
|
||||
var rest = text.Substring(endOfMetadata);
|
||||
|
||||
var doc = XDocument.Parse(xmlText);
|
||||
|
||||
// add namespaces specified in xml
|
||||
var namespaces = doc.Descendants()
|
||||
.Where(x => x.Name == "Namespace")
|
||||
.Select(x => x.Value.ToString());
|
||||
|
||||
foreach (var @namespace in namespaces)
|
||||
{
|
||||
writer.WriteLine("using {0};", @namespace);
|
||||
}
|
||||
|
||||
writer.WriteLine();
|
||||
writer.WriteLine(rest);
|
||||
|
||||
writer.Flush();
|
||||
}
|
||||
|
||||
return tempFilePath;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user