Skip to content

Commit

Permalink
Merge pull request #1 from buildkite/pie-1385-update-net-collector-ap…
Browse files Browse the repository at this point in the history
…i-payload-to-pass

[PIE-1385] Update API payload to contain name and version
  • Loading branch information
KatieWright26 authored Feb 7, 2023
2 parents d28f084 + d3647fb commit 4bc7307
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<RepositoryUrl>https://github.com/buildkite/test-collector-dotnet</RepositoryUrl>
<RespositoryType>git</RespositoryType>
<TargetFramework>net6.0</TargetFramework>
<Version>0.1.1</Version>
<Version>0.1.2</Version>
<IsPackable>true</IsPackable> </PropertyGroup>
<ItemGroup>
<Compile Include="Timing.fs" />
Expand Down
25 changes: 19 additions & 6 deletions Buildkite.TestAnalytics.Common/Payload.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ open System
/// The main data storage for test analytics data.
module Payload =
open Newtonsoft.Json

/// Stores information about the detected runtime environment.
type RuntimeEnvironment =
{ Ci: string
Expand All @@ -15,7 +14,9 @@ module Payload =
Branch: string option
CommitSha: string option
Message: string option
Url: string option }
Url: string option
Collector: string
Version: string }

/// Stores information about the test suite and it's results.
type Payload =
Expand Down Expand Up @@ -44,7 +45,9 @@ module Payload =
Branch = optionalEnvVar "BUILDKITE_BRANCH"
CommitSha = optionalEnvVar "BUILDKITE_COMMIT"
Message = optionalEnvVar "BUILDKITE_MESSAGE"
Url = optionalEnvVar "BUILDKITE_BUILD_URL" }
Url = optionalEnvVar "BUILDKITE_BUILD_URL"
Version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()
Collector = "dotnet-buildkite-test-collector" }
)
elif Option.isSome (optionalEnvVar "GITHUB_ACTION") then
Some(
Expand All @@ -66,7 +69,10 @@ module Payload =
"https://github.com/%s/actions/run/%s"
(getEnvVar "GITHUB_REPOSITORY")
(getEnvVar "GITHUB_RUN_ID")
) }
)
Version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()
Collector = "dotnet-buildkite-test-collector"
}
)
elif Option.isSome (optionalEnvVar "CIRCLE_BUILD_NUM") then
Some(
Expand All @@ -77,7 +83,9 @@ module Payload =
Branch = optionalEnvVar "CIRCLE_BRANCH"
CommitSha = optionalEnvVar "CIRCLE_SHA1"
Message = None
Url = optionalEnvVar "CIRCLE_BUILD_URL" }
Url = optionalEnvVar "CIRCLE_BUILD_URL"
Version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()
Collector = "dotnet-buildkite-test-collector" }
)
elif Option.isSome (optionalEnvVar "CI") then
Some(
Expand All @@ -88,7 +96,9 @@ module Payload =
Branch = None
CommitSha = None
Message = None
Url = None }
Url = None
Version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()
Collector = "dotnet-buildkite-test-collector" }
)
else
None
Expand Down Expand Up @@ -148,12 +158,15 @@ module Payload =
Map [
("CI", env.Ci :> obj)
("key", env.Key :> obj)
("collector", env.Collector :> obj)
("version", env.Version :> obj)
]
|> maybeAppend "number" env.Number
|> maybeAppend "branch" env.Branch
|> maybeAppend "commit_sha" env.CommitSha
|> maybeAppend "url" env.Url


let dataAsJson (payload: Payload) : Map<string, obj> list =
payload.Data
|> List.map (fun testData -> TestData.AsJson(testData, payload.StartedAt))
Expand Down
11 changes: 8 additions & 3 deletions Buildkite.TestAnalytics.Tests/PayloadTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ let ``when it detects a Buildkite CI environment it returns an empty payload`` (
Assert.Equal(runEnv.CommitSha, Some(env.["BUILDKITE_COMMIT"]))
Assert.Equal(runEnv.Message, Some(env.["BUILDKITE_MESSAGE"]))
Assert.Equal(runEnv.Url, Some(env.["BUILDKITE_BUILD_URL"]))
Assert.Equal(runEnv.Version, "0.1.2.0")
Assert.Equal(runEnv.Collector, "dotnet-buildkite-test-collector")


[<Fact>]
Expand Down Expand Up @@ -83,7 +85,8 @@ let ``when it detects a Github Actions CI environment it returns an empty payloa
Assert.Equal(runEnv.Branch, Some(env.["GITHUB_REF"]))
Assert.Equal(runEnv.CommitSha, Some(env.["GITHUB_SHA"]))
Assert.Equal(runEnv.Message, None)

Assert.Equal(runEnv.Version, "0.1.2.0")
Assert.Equal(runEnv.Collector, "dotnet-buildkite-test-collector")
Assert.Equal(
runEnv.Url,
Some(sprintf "https://github.com/doc-brown/flux-capacitor/actions/run/%s" env.["GITHUB_RUN_ID"])
Expand Down Expand Up @@ -115,7 +118,8 @@ let ``when it detects a Circle CI environment it returns an empty payload`` () =
Assert.Equal(runEnv.CommitSha, Some(env.["CIRCLE_SHA1"]))
Assert.Equal(runEnv.Message, None)
Assert.Equal(runEnv.Url, Some "https://example.test/circle")

Assert.Equal(runEnv.Version, "0.1.2.0")
Assert.Equal(runEnv.Collector, "dotnet-buildkite-test-collector")
[<Fact>]
let ``when it detects a generic CI environment it returns an empty payload`` () =
let env = Map [ ("CI", "true") ]
Expand All @@ -137,7 +141,8 @@ let ``when it detects a generic CI environment it returns an empty payload`` ()
Assert.Same(runEnv.CommitSha, None)
Assert.Same(runEnv.Message, None)
Assert.Same(runEnv.Url, None)

Assert.Equal(runEnv.Version, "0.1.2.0")
Assert.Equal(runEnv.Collector, "dotnet-buildkite-test-collector")
let genericEmptyPayload () =
let env = Map [ ("CI", "true") ]
Payload.Init(Some(getEnvVarFactory env)).Value
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Useful resources for developing collectors include the [Buildkite Test Analytics

## 👩‍💻 Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/buildkite/test-collector-python
Bug reports and pull requests are welcome on GitHub at https://github.com/buildkite/test-collector-dotnet

## 🚀 Releasing

Expand Down

0 comments on commit 4bc7307

Please sign in to comment.