Skip to content

Commit

Permalink
Create initial benchmark. (#878)
Browse files Browse the repository at this point in the history
* Create initial benchmark.

* Fix path 😅

* Publish benchmark results to Azure

* Add secret to env variables
  • Loading branch information
nojaf authored May 30, 2020
1 parent 829faa6 commit e0d629a
Show file tree
Hide file tree
Showing 11 changed files with 406 additions and 29 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
run: dotnet fake run build.fsx
env:
CI: true
TABLE_STORAGE_CONNECTION_STRING: ${{ secrets.TABLE_STORAGE_CONNECTION_STRING }}
- name: "trigger fantomas-ui pipeline"
if: matrix.os == 'ubuntu-latest' && github.ref == 'refs/heads/master'
run: curl -X POST -F token=${{secrets.FANTOMAS_UI_TOKEN}} -F ref=preview -F "variables[TRIGGER]=true" https://gitlab.com/api/v4/projects/8920076/trigger/pipeline
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,5 @@ external-project-tests/
.paket/paket.exe
.fake/
.vscode/
.ionide
.ionide
BenchmarkDotNet.Artifacts/
70 changes: 70 additions & 0 deletions build.fsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

open Fake.Core

#r "paket:
nuget Microsoft.Azure.Cosmos.Table
nuget Fake.BuildServer.AppVeyor
nuget Fake.Core.ReleaseNotes
nuget Fake.Core.Xml
Expand All @@ -15,6 +19,7 @@ nuget Fake.Core.Target //"

open Fake.Core
open Fake.IO
open Fake.IO.FileSystemOperators
open Fake.Core.TargetOperators
open Fake.BuildServer
open System
Expand Down Expand Up @@ -346,6 +351,70 @@ Target.create "MyGet" (fun _ ->
pushPackage args
)

let git command =
CreateProcess.fromRawCommandLine "git" command
|> CreateProcess.redirectOutput
|> Proc.run
|> fun p -> p.Result.Output.Trim()

open Microsoft.Azure.Cosmos.Table
open Microsoft.Azure.Documents

Target.create "Benchmark" (fun _ ->
DotNet.exec id ("src" </> "Fantomas.Benchmarks" </> "bin" </> "Release" </> "netcoreapp3.1" </> "Fantomas.Benchmarks.dll") ""
|> ignore

match Environment.environVarOrNone "TABLE_STORAGE_CONNECTION_STRING" with
| Some conn ->
let branchName = git "rev-parse --abbrev-ref HEAD"
let commit = git "rev-parse HEAD"
let operatingSystem = Environment.environVar "RUNNER_OS"

let results =
System.IO.File.ReadLines("./BenchmarkDotNet.Artifacts/results/Fantomas.Benchmarks.Runners.CodePrinterTest-report.csv")
|> Seq.map (fun line -> line.Split(',') |> Array.toList)
|> Seq.toList
|> fun lineGroups ->
match lineGroups with
| [ header; values ] ->
let csvValues = List.zip header values

let buildNumber =
match buildNumber with
|Some i -> [ "BuildNumber", i.ToString() ]
| None -> []

let metaData =
[ "Branch", branchName
"Commit", commit
"Operating System", operatingSystem
yield! buildNumber ]

[ yield! csvValues; yield! metaData ]
| _ ->
[]

let storageAccount = CloudStorageAccount.Parse(conn)
let tableClient = storageAccount.CreateCloudTableClient()
let table = tableClient.GetTableReference("FantomasBenchmarks")
let entry = DynamicTableEntity()
entry.PartitionKey <- "GithubActions"
entry.RowKey <- (sprintf "%s|%s|%s" branchName commit operatingSystem).ToLower()

results
|> List.iter (fun (k,v) ->
let key = k.Replace(' ','_')
if not (isNull v) then
entry.Properties.Add(key, EntityProperty.CreateEntityPropertyFromObject(v)))

let tableOperation = TableOperation.InsertOrReplace(entry)

table.Execute(tableOperation)
|> printfn "%O"
| None ->
printfn "Not saving benchmark results to the cloud"
)

// --------------------------------------------------------------------------------------
// Run all targets by default. Invoke 'build <Target>' to override

Expand All @@ -355,6 +424,7 @@ Target.create "All" ignore
==> "ProjectVersion"
==> "Build"
==> "UnitTests"
==> "Benchmark"
==> "Pack"
==> "All"
==> "Push"
Expand Down
Loading

0 comments on commit e0d629a

Please sign in to comment.