diff --git a/Buildkite.TestAnalytics.Common/Buildkite.TestAnalytics.Common.fsproj b/Buildkite.TestAnalytics.Common/Buildkite.TestAnalytics.Common.fsproj index a1bada1..42a77eb 100644 --- a/Buildkite.TestAnalytics.Common/Buildkite.TestAnalytics.Common.fsproj +++ b/Buildkite.TestAnalytics.Common/Buildkite.TestAnalytics.Common.fsproj @@ -14,7 +14,7 @@ https://github.com/buildkite/test-collector-dotnet git net6.0 - 0.1.1 + 0.1.2 true diff --git a/Buildkite.TestAnalytics.Common/Payload.fs b/Buildkite.TestAnalytics.Common/Payload.fs index 6a4aa03..3b69632 100644 --- a/Buildkite.TestAnalytics.Common/Payload.fs +++ b/Buildkite.TestAnalytics.Common/Payload.fs @@ -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 @@ -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 = @@ -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( @@ -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( @@ -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( @@ -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 @@ -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 list = payload.Data |> List.map (fun testData -> TestData.AsJson(testData, payload.StartedAt)) diff --git a/Buildkite.TestAnalytics.Tests/PayloadTests.fs b/Buildkite.TestAnalytics.Tests/PayloadTests.fs index c83d44f..675e13f 100644 --- a/Buildkite.TestAnalytics.Tests/PayloadTests.fs +++ b/Buildkite.TestAnalytics.Tests/PayloadTests.fs @@ -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") [] @@ -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"]) @@ -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") [] let ``when it detects a generic CI environment it returns an empty payload`` () = let env = Map [ ("CI", "true") ] @@ -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 diff --git a/README.md b/README.md index 8eb4d1a..8f32e2a 100644 --- a/README.md +++ b/README.md @@ -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