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

Improve log integration with AppVeyor #1490

Merged
merged 4 commits into from
Apr 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
82 changes: 43 additions & 39 deletions src/app/FakeLib/AppVeyor.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,68 +5,68 @@ open System
open System.IO

/// AppVeyor environment variables as [described](http://www.appveyor.com/docs/environment-variables)
type AppVeyorEnvironment =
type AppVeyorEnvironment =

/// AppVeyor Build Agent API URL
static member ApiUrl = environVar "APPVEYOR_API_URL"

/// AppVeyor Account Name
static member AccountName = environVar "APPVEYOR_ACCOUNT_NAME"

/// AppVeyor unique project ID
static member ProjectId = environVar "APPVEYOR_PROJECT_ID"

/// Project name
static member ProjectName = environVar "APPVEYOR_PROJECT_NAME"

/// Project slug (as seen in project details URL)
static member ProjectSlug = environVar "APPVEYOR_PROJECT_SLUG"

/// Path to clone directory
static member BuildFolder = environVar "APPVEYOR_BUILD_FOLDER"

/// AppVeyor unique build ID
static member BuildId = environVar "APPVEYOR_BUILD_ID"

/// Build number
static member BuildNumber = environVar "APPVEYOR_BUILD_NUMBER"

/// Build version
static member BuildVersion = environVar "APPVEYOR_BUILD_VERSION"

/// GitHub Pull Request number
static member PullRequestNumber = environVar "APPVEYOR_PULL_REQUEST_NUMBER"

/// GitHub Pull Request title
static member PullRequestTitle = environVar "APPVEYOR_PULL_REQUEST_TITLE"

/// AppVeyor unique job ID
static member JobId = environVar "APPVEYOR_JOB_ID"

/// GitHub, BitBucket or Kiln
static member RepoProvider = environVar "APPVEYOR_REPO_PROVIDER"

/// git or mercurial
static member RepoScm = environVar "APPVEYOR_REPO_SCM"

/// Repository name in format owner-name/repo-name
static member RepoName = environVar "APPVEYOR_REPO_NAME"

/// Build branch
static member RepoBranch = environVar "APPVEYOR_REPO_BRANCH"

/// Commit ID (SHA)
static member RepoCommit = environVar "APPVEYOR_REPO_COMMIT"

/// Commit author's name
static member RepoCommitAuthor = environVar "APPVEYOR_REPO_COMMIT_AUTHOR"

/// Commit author's email address
static member RepoCommitAuthorEmail = environVar "APPVEYOR_REPO_COMMIT_AUTHOR_EMAIL"

/// Commit date/time
static member RepoCommitTimestamp = environVar "APPVEYOR_REPO_COMMIT_TIMESTAMP"

/// Commit message
static member RepoCommitMessage = environVar "APPVEYOR_REPO_COMMIT_MESSAGE"

Expand All @@ -81,7 +81,7 @@ type AppVeyorEnvironment =

/// If the build has been started by the "Re-Build commit/PR" button or from the same API
static member IsReBuild = environVar "APPVEYOR_RE_BUILD"

/// true if build has started by pushed tag; otherwise false
static member RepoTag =
let rt = environVar "APPVEYOR_REPO_TAG"
Expand All @@ -93,31 +93,35 @@ type AppVeyorEnvironment =
/// Platform name set on Build tab of project settings (or through platform parameter in appveyor.yml).
static member Platform = environVar "PLATFORM"

/// Configuration name set on Build tab of project settings (or through configuration parameter in appveyor.yml).
/// Configuration name set on Build tab of project settings (or through configuration parameter in appveyor.yml).
static member Configuration = environVar "CONFIGURATION"

/// The job name
static member JobName = environVar "APPVEYOR_JOB_NAME"
let private sendToAppVeyor args =
ExecProcess (fun info ->

let private sendToAppVeyor args =
ExecProcess (fun info ->
info.FileName <- "appveyor"
info.Arguments <- args) (System.TimeSpan.MaxValue)
|> ignore

let private add msg category =
sprintf "AddMessage %s -Category %s" (quoteIfNeeded msg) (quoteIfNeeded category) |> sendToAppVeyor
let private add msg category =
if not <| isNullOrEmpty msg then
let enableProcessTracingPreviousValue = enableProcessTracing
enableProcessTracing <- false
sprintf "AddMessage %s -Category %s" (quoteIfNeeded msg) (quoteIfNeeded category) |> sendToAppVeyor
enableProcessTracing <- enableProcessTracingPreviousValue
let private addNoCategory msg = sprintf "AddMessage %s" (quoteIfNeeded msg) |> sendToAppVeyor

// Add trace listener to track messages
if buildServer = BuildServer.AppVeyor then
if buildServer = BuildServer.AppVeyor then
{ new ITraceListener with
member this.Write msg =
member this.Write msg =
match msg with
| ErrorMessage x -> add x "Error"
| ImportantMessage x -> add x "Warning"
| LogMessage(x, _) -> add x "Information"
| TraceMessage(x, _) ->
| TraceMessage(x, _) ->
if not enableProcessTracing then addNoCategory x
| StartMessage | FinishedMessage | OpenTag(_, _) | CloseTag _ -> () }
|> listeners.Add
Expand All @@ -129,23 +133,23 @@ let FinishTestSuite testSuiteName = () // Nothing in API yet
let StartTestSuite testSuiteName = () // Nothing in API yet

/// Starts the test case.
let StartTestCase testSuiteName testCaseName =
let StartTestCase testSuiteName testCaseName =
sendToAppVeyor <| sprintf "AddTest \"%s\" -Outcome Running" (testSuiteName + " - " + testCaseName)

/// Reports a failed test.
let TestFailed testSuiteName testCaseName message details =
let TestFailed testSuiteName testCaseName message details =
sendToAppVeyor <| sprintf "UpdateTest \"%s\" -Outcome Failed -ErrorMessage %s -ErrorStackTrace %s" (testSuiteName + " - " + testCaseName)
(EncapsulateSpecialChars message) (EncapsulateSpecialChars details)

/// Ignores the test case.
/// Ignores the test case.
let IgnoreTestCase testSuiteName testCaseName message = sendToAppVeyor <| sprintf "UpdateTest \"%s\" -Outcome Ignored" (testSuiteName + " - " + testCaseName)

/// Reports a succeeded test.
let TestSucceeded testSuiteName testCaseName = sendToAppVeyor <| sprintf "UpdateTest \"%s\" -Outcome Passed" (testSuiteName + " - " + testCaseName)

/// Finishes the test case.
let FinishTestCase testSuiteName testCaseName (duration : System.TimeSpan) =
let duration =
let FinishTestCase testSuiteName testCaseName (duration : System.TimeSpan) =
let duration =
duration.TotalMilliseconds
|> round
|> string
Expand Down Expand Up @@ -238,7 +242,7 @@ let PushArtifacts paths =

/// AppVeyor parameters for update build as [described](https://www.appveyor.com/docs/build-worker-api/#update-build-details)
[<CLIMutable>]
type UpdateBuildParams =
type UpdateBuildParams =
{ /// Build version; must be unique for the current project
Version : string
/// Commit message
Expand Down Expand Up @@ -271,7 +275,7 @@ let UpdateBuild (setParams : UpdateBuildParams -> UpdateBuildParams) =
if buildServer = BuildServer.AppVeyor then
let parameters = setParams defaultUpdateBuildParams

let committedStr =
let committedStr =
match parameters.Committed with
| Some x -> x.ToString("o")
| None -> ""
Expand All @@ -290,5 +294,5 @@ let UpdateBuild (setParams : UpdateBuildParams -> UpdateBuildParams) =
|> sendToAppVeyor

/// Update build version. This must be unique for the current project.
let UpdateBuildVersion version =
let UpdateBuildVersion version =
UpdateBuild (fun p -> { p with Version = version })
50 changes: 35 additions & 15 deletions src/app/FakeLib/TargetHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
module Fake.TargetHelper

open System
open System.Text
open System.Collections.Generic
open System.Linq

Expand Down Expand Up @@ -333,9 +334,16 @@ let runBuildFailureTargets() =

/// Prints all targets.
let PrintTargets() =
log "The following targets are available:"
let sb = StringBuilder()
let appendfn fmt = Printf.ksprintf (sb.AppendLine >> ignore) fmt

appendfn "The following targets are available:"
for t in TargetDict.Values do
logfn " %s%s" t.Name (if isNullOrEmpty t.Description then "" else sprintf " - %s" t.Description)
appendfn " %s%s" t.Name (if isNullOrEmpty t.Description then "" else sprintf " - %s" t.Description)

sb.Length <- sb.Length - Environment.NewLine.Length

log <| sb.ToString()


// Maps the specified dependency type into the list of targets
Expand Down Expand Up @@ -380,35 +388,47 @@ let PrintDependencyGraph verbose target =
match TargetDict.TryGetValue (target) with
| false,_ -> PrintTargets()
| true,target ->
logfn "%sDependencyGraph for Target %s:" (if verbose then String.Empty else "Shortened ") target.Name
let sb = StringBuilder()
let appendfn fmt = Printf.ksprintf (sb.AppendLine >> ignore) fmt

appendfn "%sDependencyGraph for Target %s:" (if verbose then String.Empty else "Shortened ") target.Name

let logDependency ((t: TargetTemplate<unit>), depType, level, isVisited) =
if verbose || not isVisited then
let indent = (String(' ', level * 3))
if depType = DependencyType.Soft then
log <| sprintf "%s<=? %s" indent t.Name
appendfn "%s<=? %s" indent t.Name
else
log <| sprintf "%s<== %s" indent t.Name
appendfn "%s<== %s" indent t.Name

let _, ordered = visitDependencies logDependency target.Name

log ""
log "The resulting target order is:"
Seq.iter (logfn " - %s") ordered
appendfn ""
appendfn "The resulting target order is:"
Seq.iter (appendfn " - %s") ordered

sb.Length <- sb.Length - Environment.NewLine.Length

log <| sb.ToString()

/// <summary>Writes a dependency graph of all targets in the DOT format.</summary>
let PrintDotDependencyGraph () =
logfn "digraph G {"
logfn " rankdir=TB;"
logfn " node [shape=box];"
let sb = StringBuilder()
let appendfn fmt = Printf.ksprintf (sb.AppendLine >> ignore) fmt

appendfn "digraph G {"
appendfn " rankdir=TB;"
appendfn " node [shape=box];"
for target in TargetDict.Values do
logfn " \"%s\";" target.Name
appendfn " \"%s\";" target.Name
let deps = target.Dependencies
for d in target.Dependencies do
logfn " \"%s\" -> \"%s\"" target.Name d
appendfn " \"%s\" -> \"%s\"" target.Name d
for d in target.SoftDependencies do
logfn " \"%s\" -> \"%s\" [style=dotted];" target.Name d
logfn "}"
appendfn " \"%s\" -> \"%s\" [style=dotted];" target.Name d
sb.Append "}" |> ignore

log <| sb.ToString()

/// Writes a summary of errors reported during build.
let WriteErrors () =
Expand Down
2 changes: 1 addition & 1 deletion src/app/FakeLib/TraceHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ let traceStartTaskUsing task description =
traceStartTask task description
{ new IDisposable with member x.Dispose() = traceEndTask task description }

let console = new ConsoleTraceListener(false, colorMap) :> ITraceListener
let console = new ConsoleTraceListener(false, colorMap, false) :> ITraceListener

open System.Diagnostics

Expand Down
Loading