Simple Continiuos Integration with FAKE and windows scheduler #fsharp

Below are the details about a very simple CI setup,  the one that simply checks GitHub for changes to ‘master’ and if

there were any, runs FAKE build script.

First FAKE script:
//

#r @"../_tools/FAKE/FakeLib.dll"
#r @"../_tools/FAKE/MyFakeTasks.dll"
open Fake
open System.IO
open MyFakeTasks
let author = ["Srdjan Strbanovic"]
let release = @".\WinService\bin\release"
let debug = @".\WinService\bin\debug"
let winservice = !! @".\WinService\WinService.csproj"
Target? Clean <-
fun () ->
CleanDirs [release;debug]
Target? Build <-
fun () ->
MSBuildRelease release "Clean" winservice
|> Log "Clean Release Build:"
MSBuildRelease release "Build" winservice
|> Log "Release Build:"
Target? Default <-
fun () -> trace "Finished..."
"Clean"
==> "Build"
=?> ("Default", GitTasks.Pull(@".\") = 1)
Run? Default
view raw build.fsx hosted with ❤ by GitHub

The only part that should be interesting (the rest is standard FAKE) is conditional dependency for ‘Default’ task.

It depends on returned value from a custom FAKE task that checks if there are changes on GitHub.

Here is the custom task:

using System;
using System.Diagnostics;
using System.Linq;
namespace MyFakeTasks
{
public class GitTasks
{
public static int Pull(string workingDirectory)
{
var processStartInfo = new ProcessStartInfo();
processStartInfo.CreateNoWindow = true;
processStartInfo.RedirectStandardError = true;
processStartInfo.RedirectStandardOutput = true;
processStartInfo.FileName = @"C:\Program Files (x86)\Git\bin\git.exe";
processStartInfo.UseShellExecute = false;
var result = gitPull(processStartInfo, workingDirectory);
Console.WriteLine(result);
return result;
}
static int gitPull(ProcessStartInfo processStartInfo, string workingDirectory)
{
var process = new Process();
processStartInfo.Arguments = "pull";
processStartInfo.WorkingDirectory = workingDirectory;
process.StartInfo = processStartInfo;
process.Start();
var stdErrStr = process.StandardError.ReadToEnd();
var stdOutStr = process.StandardOutput.ReadToEnd();
process.WaitForExit();
process.Close();
Console.Write(stdErrStr.Any() ? stdErrStr : stdOutStr);
return stdOutStr.Contains("Already up-to-date.") ? 0 : 1;
}
}
}
view raw gistfile1.cs hosted with ❤ by GitHub

That is all – “simple” is the keyword  🙂 – here is the screenshot of it running:

Capture

Till next time…

One thought on “Simple Continiuos Integration with FAKE and windows scheduler #fsharp

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: