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

Squirrel for FAKE v5 #2076

Merged
merged 4 commits into from
Sep 8, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 15 additions & 0 deletions Fake.sln
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Fake.Tools.Octo", "src\app\
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Fake.Core.Vault", "src\app\Fake.Core.Vault\Fake.Core.Vault.fsproj", "{AAAF92C5-C40D-40B8-84BA-137DF0E98B56}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fake.Tools.Squirrel", "src\app\Fake.Tools.Squirrel\Fake.Tools.Squirrel.fsproj", "{3DEF2E95-4BF8-413F-930E-32103A39364A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -1056,6 +1058,18 @@ Global
{AAAF92C5-C40D-40B8-84BA-137DF0E98B56}.Release|x64.Build.0 = Release|Any CPU
{AAAF92C5-C40D-40B8-84BA-137DF0E98B56}.Release|x86.ActiveCfg = Release|Any CPU
{AAAF92C5-C40D-40B8-84BA-137DF0E98B56}.Release|x86.Build.0 = Release|Any CPU
{3DEF2E95-4BF8-413F-930E-32103A39364A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3DEF2E95-4BF8-413F-930E-32103A39364A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3DEF2E95-4BF8-413F-930E-32103A39364A}.Debug|x64.ActiveCfg = Debug|Any CPU
{3DEF2E95-4BF8-413F-930E-32103A39364A}.Debug|x64.Build.0 = Debug|Any CPU
{3DEF2E95-4BF8-413F-930E-32103A39364A}.Debug|x86.ActiveCfg = Debug|Any CPU
{3DEF2E95-4BF8-413F-930E-32103A39364A}.Debug|x86.Build.0 = Debug|Any CPU
{3DEF2E95-4BF8-413F-930E-32103A39364A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3DEF2E95-4BF8-413F-930E-32103A39364A}.Release|Any CPU.Build.0 = Release|Any CPU
{3DEF2E95-4BF8-413F-930E-32103A39364A}.Release|x64.ActiveCfg = Release|Any CPU
{3DEF2E95-4BF8-413F-930E-32103A39364A}.Release|x64.Build.0 = Release|Any CPU
{3DEF2E95-4BF8-413F-930E-32103A39364A}.Release|x86.ActiveCfg = Release|Any CPU
{3DEF2E95-4BF8-413F-930E-32103A39364A}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1136,6 +1150,7 @@ Global
{E656E3E2-18D2-4D8E-935C-200DB00E1F19} = {7BFFAE76-DEE9-417A-A79B-6A6644C4553A}
{F1641150-B89D-40B7-A3BE-9DC357410FDA} = {7BFFAE76-DEE9-417A-A79B-6A6644C4553A}
{AAAF92C5-C40D-40B8-84BA-137DF0E98B56} = {901F162F-8925-4390-89C5-9EE2C343F744}
{3DEF2E95-4BF8-413F-930E-32103A39364A} = {901F162F-8925-4390-89C5-9EE2C343F744}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {058A0C5E-2216-4306-8AFB-0AE28320C26A}
Expand Down
1 change: 1 addition & 0 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ let dotnetAssemblyInfos =
"Fake.Tools.Git", "Running git commands"
"Fake.Tools.GitVersion", "GitVersion helper"
"Fake.Tools.Octo", "Octopus Deploy octo.exe tool helper"
"Fake.Tools.Squirrel", "Squirrel for windows Squirrel.exe tool helper"
"Fake.Tools.Pickles", "Convert Gherkin to HTML"
"Fake.Tools.Rsync", "Running Rsync commands"
"Fake.Tracing.NAntXml", "NAntXml"
Expand Down
25 changes: 25 additions & 0 deletions help/markdown/fake-tools-squirrel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Releasifying NuGet packages with Squirrel

<div class="alert alert-info">
<h5>INFO</h5>
<p>This documentation is for FAKE version 5.0 or later.</p>
</div>

[Squirrel.Windows](https://github.com/Squirrel/Squirrel.Windows) is an installation an auto-update system for Windows desktop apps.

[API-Reference](apidocs/v5/fake-tools-squirrel.html)

## Squirrel.exe CLI tool

This module is a wrapper around the [Squirrel.exe](https://github.com/Squirrel/Squirrel.Windows/blob/master/docs/using/squirrel-command-line.md) CLI tool that is available in the [squirrel.windows](https://www.nuget.org/packages/squirrel.windows/) NuGet package.

## Releasify

[Releasifying](https://github.com/Squirrel/Squirrel.Windows/blob/master/docs/getting-started/2-packaging.md#releasifying) create all files necessary for release from a NuGet package

```fsharp
open Fake.Tools

Squirrel.releasify (fun p -> { p with ReleaseDir = "squirrel_release") "bin/myProject.nupkg"
```

1 change: 1 addition & 0 deletions help/templates/template.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@
<li><a href="/apidocs/v5/index.html#Fake.Tools.Git">Git</a></li>
<li><a href="/fake-tools-pickles.html">Pickles</a></li>
<li><a href="/fake-tools-octo.html">Octo</a></li>
<li><a href="/fake-tools-squirrel.html">Octo</a></li>
<li><a href="/apidocs/v5/fake-tools-rsync.html">Rsync</a></li>
</ul>
</li>
Expand Down
17 changes: 17 additions & 0 deletions src/app/Fake.Tools.Squirrel/AssemblyInfo.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Auto-Generated by FAKE; do not edit
namespace System
open System.Reflection

[<assembly: AssemblyTitleAttribute("FAKE - F# Make Squirrel for windows Squirrel.exe tool helper")>]
[<assembly: AssemblyProductAttribute("FAKE - F# Make")>]
[<assembly: AssemblyVersionAttribute("5.3.1")>]
[<assembly: AssemblyInformationalVersionAttribute("5.3.1-alpha")>]
[<assembly: AssemblyFileVersionAttribute("5.3.1")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] AssemblyTitle = "FAKE - F# Make Squirrel for windows Squirrel.exe tool helper"
let [<Literal>] AssemblyProduct = "FAKE - F# Make"
let [<Literal>] AssemblyVersion = "5.3.1"
let [<Literal>] AssemblyInformationalVersion = "5.3.1-alpha"
let [<Literal>] AssemblyFileVersion = "5.3.1"
24 changes: 24 additions & 0 deletions src/app/Fake.Tools.Squirrel/Fake.Tools.Squirrel.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TargetFrameworks>net46;netstandard1.6;netstandard2.0</TargetFrameworks>
<DefineConstants>$(DefineConstants);NO_DOTNETCORE_BOOTSTRAP</DefineConstants>
<AssemblyName>Fake.Tools.Squirrel</AssemblyName>
<OutputType>Library</OutputType>
</PropertyGroup>
<PropertyGroup>
<DefineConstants>$(DefineConstants);NETSTANDARD</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.fs" />
<Compile Include="Squirrel.fs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Fake.Core.Environment\Fake.Core.Environment.fsproj" />
<ProjectReference Include="..\Fake.Core.Process\Fake.Core.Process.fsproj" />
<ProjectReference Include="..\Fake.IO.FileSystem\Fake.IO.FileSystem.fsproj" />
</ItemGroup>
<Import Project="..\..\..\.paket\Paket.Restore.targets" />
</Project>
143 changes: 143 additions & 0 deletions src/app/Fake.Tools.Squirrel/Squirrel.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
/// Contains types and utility functions related to creating [Squirrel](https://github.com/Squirrel/Squirrel.Windows) installer.
[<RequireQualifiedAccess>]
module Fake.Tools.Squirrel

open Fake.Core
open Fake.IO
open Fake.IO.FileSystemOperators
open Fake.IO.Globbing
open System
open System.IO
open System.Text

/// The [Squirrel](https://github.com/Squirrel/Squirrel.Windows) Console Parameters type.
///
/// For reference, see: [Squirrel Command Line Options](https://github.com/Squirrel/Squirrel.Windows/blob/master/docs/advanced-releasify.md)
type ReleasifyParams =
{
/// The output directory for the generated installer
ReleaseDir : string

/// The working directory.
WorkingDir : string option

/// The full path to an optional setup.exe template
BootstrapperExe : string option

/// The full path to an optional animated gif to be displayed during installation
LoadingGif : string option

/// The full path to an optional icon, which will be used for the generated installer.
SetupIcon : string option

/// Do not create an MSI file
NoMsi : bool

/// The path to Squirrel: `squirrel.exe`
ToolPath : string

/// Maximum time to allow Squirrel to run before being killed.
TimeOut : TimeSpan

/// Sign the installer with signtool.exe
SignExecutable : bool option

/// The code signing certificate to be used for signing
SigningKeyFile : string option

/// The secret key for the code signing certificate
SigningSecret : string option }

let internal defaultParams = lazy(
let toolname = "Squirrel.exe"
{
ReleaseDir = ""
WorkingDir = None
BootstrapperExe = None
LoadingGif = None
SetupIcon = None
NoMsi = false
ToolPath = Tools.findToolInSubPath toolname ( Directory.GetCurrentDirectory() </> "tools" </> "Squirrel")
TimeOut = TimeSpan.FromMinutes 10.
SignExecutable = None
SigningKeyFile = None
SigningSecret = None })

let private createSigningArgs (parameters : ReleasifyParams) =
new StringBuilder()
|> StringBuilder.appendWithoutQuotes "--signWithParams=\""
|> StringBuilder.appendWithoutQuotes "/a"
|> StringBuilder.appendIfSome parameters.SigningKeyFile (sprintf "/f %s")
|> StringBuilder.appendIfSome parameters.SigningSecret (sprintf "/p %s")
|> StringBuilder.appendWithoutQuotes "\""
|> StringBuilder.toText

let internal buildSquirrelArgs parameters nugetPackage =
new StringBuilder()
|> StringBuilder.appendIfNotNullOrEmpty nugetPackage "--releasify="
|> StringBuilder.appendIfNotNullOrEmpty parameters.ReleaseDir "--releaseDir="
|> StringBuilder.appendIfSome parameters.LoadingGif (sprintf "\"--loadingGif=%s\"")
|> StringBuilder.appendIfSome parameters.SetupIcon (sprintf "\"--setupIcon=%s\"")
|> StringBuilder.appendIfTrue parameters.NoMsi "--no-msi"
|> StringBuilder.appendIfSome parameters.BootstrapperExe (sprintf "\"--bootstrapperExe=%s\"")
|> StringBuilder.appendIfSome parameters.SignExecutable (fun _ -> createSigningArgs parameters)
|> StringBuilder.toText

module internal ResultHandling =
let (|OK|Failure|) = function
| 0 -> OK
| x -> Failure x

let buildErrorMessage = function
| OK -> None
| Failure errorCode ->
Some (sprintf "Squirrel reported an error (Error Code %d)" errorCode)

let failBuildIfSquirrelReportedError =
buildErrorMessage
>> Option.iter failwith

/// Creates a Squirrel installer for given NuGet package
/// Will fail if Squirrel terminates with non-zero exit code.
///
/// ## Parameters
///
/// - `setParams` - Function used to manipulate the default `SquirrelParams` value.
/// - `nugetPackage` - The package to create an installer for
///
/// ## Sample usage
///
/// Target.create "CreatePackage" (fun _ ->
/// Squirrel.pack (fun p -> { p with WorkingDir = Some "./tmp" }) "./my.nupkg"
/// )
///
/// ## Defaults for setParams
///
/// - `ReleaseDir` - `""`
/// - `WorkingDir` - `None`
/// - `BootstrapperExe` - `None`
/// - `LoadingGif` - `None`
/// - `SetupIcon` - `None`
/// - `NoMsi` - `false`
/// - `ToolPath` - The `squirrel.exe` path if it exists in a subdirectory of the current directory.
/// - `TimeOut` - 10 minutes
/// - `SignExecutable` - `None`
/// - `SigningKeyFile` - `None`
/// - `SigningSecret` - `None`
let releasify (setParams: ReleasifyParams -> ReleasifyParams) (nugetPackage: string): unit =
use __ = Trace.traceTask "Squirrel" nugetPackage
let parameters = defaultParams.Value |> setParams
let args = buildSquirrelArgs parameters nugetPackage
Trace.tracefn "%s" args

let result =
Process.execSimple
(fun info -> { info with
FileName = parameters.ToolPath
WorkingDirectory = defaultArg parameters.WorkingDir "."
Arguments = args})
parameters.TimeOut

ResultHandling.failBuildIfSquirrelReportedError result

__.MarkSuccess()
Empty file.
8 changes: 4 additions & 4 deletions src/legacy/FakeLib/SquirrelHelper.fs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// Contains types and utility functions related to creating [Squirrel](https://github.com/Squirrel/Squirrel.Windows) installer.
[<System.Obsolete("This API is obsolete. There is no alternative in FAKE 5 yet. You can help by porting this module.")>]
[<System.Obsolete("FAKE0001 Use the Fake.Tools.Squirrel module instead")>]
module Fake.Squirrel

open Fake
Expand All @@ -11,7 +11,7 @@ open System.Text
///
/// For reference, see: [Squirrel Command Line Options](https://github.com/Squirrel/Squirrel.Windows/blob/master/docs/advanced-releasify.md)
[<CLIMutable>]
[<System.Obsolete("This API is obsolete. There is no alternative in FAKE 5 yet. You can help by porting this module.")>]
[<System.Obsolete("FAKE0001 Use the Fake.Tools.Squirrel module instead")>]
type SquirrelParams =
{
/// The output directory for the generated installer
Expand Down Expand Up @@ -62,7 +62,7 @@ type SquirrelParams =
/// - `SignExecutable` - `None`
/// - `SigningKeyFile` - `None`
/// - `SigningSecret` - `None`
[<System.Obsolete("This API is obsolete. There is no alternative in FAKE 5 yet. You can help by porting this module.")>]
[<System.Obsolete("FAKE0001 Use the Fake.Tools.Squirrel module instead")>]
let SquirrelDefaults =
let toolname = "Squirrel.exe"
{
Expand Down Expand Up @@ -125,7 +125,7 @@ module internal ResultHandling =
/// Target "CreatePackage" (fun _ ->
/// SquirrelPack (fun p -> { p with WorkingDir = Some "./tmp" }) "./my.nupkg"
/// )
[<System.Obsolete("This API is obsolete. There is no alternative in FAKE 5 yet. You can help by porting this module.")>]
[<System.Obsolete("FAKE0001 Use Fake.Tools.Squirrel.releasify instead")>]
let SquirrelPack setParams nugetPackage =
use __ = traceStartTaskUsing "Squirrel" ""
let parameters = SquirrelDefaults |> setParams
Expand Down