forked from octokit/octokit.net
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a build task to validate LINQPad samples (octokit#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
- Loading branch information
1 parent
13d5dab
commit 3369a4a
Showing
14 changed files
with
121 additions
and
8 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 |
---|---|---|
|
@@ -103,4 +103,5 @@ Backup/ | |
!.vscode/launch.json | ||
|
||
# CAKE | ||
tools/ | ||
tools/* | ||
!tools/LINQPad |
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
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
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
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,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; | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.