Skip to content

Commit

Permalink
Merge pull request #2489 from jeremyabbott/octo-tool-manifest
Browse files Browse the repository at this point in the history
Support running Octo from .net core tool-manifest
  • Loading branch information
matthid authored Apr 23, 2020
2 parents 8ab8e89 + e052906 commit 8f6030e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
9 changes: 9 additions & 0 deletions help/markdown/fake-tools-octo.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ You will also need to install and configure at least one [Tentacle](http://octop

This module is a wrapper around the [Octo.exe](https://octopus.com/docs/api-and-integration/octo.exe-command-line) CLI tool which controls Octopus Deploy API. You'll need the Octo.exe tool itself accessible to your FAKE script. Download it from [here](https://octopus.com/downloads).

This module also supports use via a .NET Core Tool-Manifest. Installation is simple! From the root of your repository run the following

```bash
dotnet new tool-manifest # if one doesn't already exist
dotnet tool install Octopus.DotNet.Cli
```

### Generate an API Key

In order to communicate with the Octopus Deploy API you will need an *API key* to authenticate with.
Expand All @@ -34,6 +41,7 @@ It is a good idea to create an account in Octopus Deploy for your Continuous Int
You can define a function defining shared parameters like `ToolPath` or your Octopus Deploy instance details. Then the function can be used in subsequent `Octo` calls.

```fsharp
open Fake.DotNet // needed for ToolType
open Fake.Tools
let setCommon (ps:Octo.Options) =
Expand All @@ -42,6 +50,7 @@ let setCommon (ps:Octo.Options) =
Server = {
ServerUrl = "Your Octopus Server URL"
ApiKey = "Your API key"
ToolType = ToolType.CreateLocalTool() // default is ToolType.FullFramework
}
}
```
Expand Down
3 changes: 2 additions & 1 deletion src/app/Fake.Tools.Octo/Fake.Tools.Octo.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<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" />
<ProjectReference Include="..\Fake.DotNet.Cli\Fake.DotNet.Cli.fsproj" />
</ItemGroup>
<Import Project="..\..\..\.paket\Paket.Restore.targets" />
</Project>
</Project>
10 changes: 6 additions & 4 deletions src/app/Fake.Tools.Octo/Octo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
module Fake.Tools.Octo

open Fake.Core
open Fake.DotNet
open Fake.IO
open Fake.IO.Globbing
open Fake.IO.FileSystemOperators
Expand All @@ -22,6 +23,7 @@ type ServerOptions = {

/// Common Octo.exe CLI params
type Options = {
ToolType : ToolType
ToolName : string
ToolPath : string
WorkingDirectory : string
Expand Down Expand Up @@ -154,7 +156,8 @@ let internal commonOptions =
ToolName = toolName
Server = serverOptions
Timeout = TimeSpan.MaxValue
WorkingDirectory = "" }
WorkingDirectory = ""
ToolType = ToolType.Create() }

/// Default options for 'CreateRelease'
let internal releaseOptions = {
Expand Down Expand Up @@ -259,10 +262,8 @@ let private exec command options =
serverCommandLine { opts with ApiKey = "(Removed for security purposes)" }

let tool = options.ToolPath @@ options.ToolName
let args = List.append (commandLine command) (serverCommandLine options.Server)
|> Arguments.OfArgs
let args = List.append (commandLine command) (serverCommandLine options.Server) |> Arguments.OfArgs
let traceArgs = (List.append (commandLine command) (serverCommandLineForTracing options.Server)) |> List.fold (+) ""

let commandString = command.ToString()

use __ = Trace.traceTask "Octo " commandString
Expand All @@ -271,6 +272,7 @@ let private exec command options =
let result =
RawCommand (tool, args)
|> CreateProcess.fromCommand
|> CreateProcess.withToolType (options.ToolType.WithDefaultToolCommandName "dotnet-octo")
|> CreateProcess.withWorkingDirectory options.WorkingDirectory
|> CreateProcess.withTimeout options.Timeout
|> Proc.run
Expand Down
5 changes: 5 additions & 0 deletions src/test/Fake.Core.UnitTests/Fake.Tools.Octo.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Fake.Tools.Testing.Octo

open Expecto
open Fake.DotNet

[<Tests>]
let defaultTests =
Expand Down Expand Up @@ -36,6 +37,7 @@ let defaultTests =
Common={
ToolName="ToolName-1"
ToolPath="ToolPath-1"
ToolType = ToolType.FullFramework
WorkingDirectory="WorkingDirectory-1"
Server = {
ServerUrl="ServerUrl"
Expand Down Expand Up @@ -137,6 +139,7 @@ let defaultTests =
Common = {
ToolName="ToolName-1"
ToolPath="ToolPath-1"
ToolType=ToolType.FullFramework
WorkingDirectory="WorkingDirectory-1"
Server = {
ServerUrl="ServerUrl"
Expand Down Expand Up @@ -183,6 +186,7 @@ let defaultTests =
Common={
ToolName="ToolName-1"
ToolPath="ToolPath-1"
ToolType=ToolType.FullFramework
WorkingDirectory="WorkingDirectory-1"
Server = {
ServerUrl="ServerUrl"
Expand Down Expand Up @@ -215,6 +219,7 @@ let defaultTests =
Common={
ToolName="ToolName-1"
ToolPath="ToolPath-1"
ToolType=ToolType.FullFramework
WorkingDirectory="WorkingDirectory-1"
Server = {
ServerUrl="ServerUrl"
Expand Down

0 comments on commit 8f6030e

Please sign in to comment.