From 5145455d28f7fb4526979a579debe66f3461448c Mon Sep 17 00:00:00 2001 From: DiegoDiaz-TomTom Date: Thu, 7 Nov 2024 14:42:28 +0100 Subject: [PATCH 1/2] feat: create ttxcmetrics client with plugins --- Package.swift | 14 ++++++++++++-- Sources/TTXCMetricsApp/main.swift | 4 ++++ Sources/TTXCMetricsClient/TTXCMetrics.swift | 19 +++++++++++++++++++ .../Common/Extensions/+HTTPHeaders.swift | 7 ------- .../AzureSharedKeyAuthorization.swift | 7 ------- docs/Getting Started.md | 9 +++++++++ 6 files changed, 44 insertions(+), 16 deletions(-) create mode 100644 Sources/TTXCMetricsApp/main.swift create mode 100644 Sources/TTXCMetricsClient/TTXCMetrics.swift diff --git a/Package.swift b/Package.swift index 3f41fe9..b18a6f6 100644 --- a/Package.swift +++ b/Package.swift @@ -8,6 +8,8 @@ let package = Package( platforms: [ .macOS(.v13), ], products: [ + .executable(name: "TTXCMetrics", targets: ["TTXCMetricsApp"]), + .library(name: "TTXCMetricsClient", targets: ["TTXCMetricsClient"]), .executable(name: "XCMetrics", targets: ["XCMetricsApp"]), .executable(name: "XCMetricsBackend", targets: ["XCMetricsBackend"]), .library(name: "XCMetricsBackendLib", targets: ["XCMetricsBackendLib"]), @@ -53,6 +55,14 @@ let package = Package( .product(name: "ArgumentParser", package: "swift-argument-parser"), ] ), + .target( + name: "TTXCMetricsClient", + dependencies: ["XCMetricsClient", "XCMetricsPlugins"] + ), + .executableTarget( + name: "TTXCMetricsApp", + dependencies: ["TTXCMetricsClient"] + ), .target( name: "XCMetricsPlugins", dependencies: [ @@ -73,7 +83,7 @@ let package = Package( .product(name: "NIOHTTP2", package: "swift-nio-http2") ] ), - .target( + .executableTarget( name: "XCMetricsApp", dependencies: ["XCMetricsClient"] ), @@ -103,7 +113,7 @@ let package = Package( .unsafeFlags(["-cross-module-optimization"], .when(configuration: .release)) ] ), - .target(name: "XCMetricsBackend", dependencies: [.target(name: "XCMetricsBackendLib")]), + .executableTarget(name: "XCMetricsBackend", dependencies: [.target(name: "XCMetricsBackendLib")]), .testTarget( name: "XCMetricsTests", dependencies: [ diff --git a/Sources/TTXCMetricsApp/main.swift b/Sources/TTXCMetricsApp/main.swift new file mode 100644 index 0000000..f98a9d7 --- /dev/null +++ b/Sources/TTXCMetricsApp/main.swift @@ -0,0 +1,4 @@ +import Foundation +import TTXCMetricsClient + +TTXCMetrics.main() diff --git a/Sources/TTXCMetricsClient/TTXCMetrics.swift b/Sources/TTXCMetricsClient/TTXCMetrics.swift new file mode 100644 index 0000000..f93d258 --- /dev/null +++ b/Sources/TTXCMetricsClient/TTXCMetrics.swift @@ -0,0 +1,19 @@ +import Foundation +import XCMetricsClient +import XCMetricsPlugins + +public struct TTXCMetrics { + public static func main() { + let metrics = XCMetrics.parseOrExit() + let configuration = XCMetricsConfiguration() + configuration.add(plugin: ThermalThrottlingPlugin().create()) + + // The git directory is usually Xcode's `$SRCROOT` environment variable + let gitDirectory: String? = ProcessInfo.processInfo.environment["SRCROOT"] + if let gitDirectory { + configuration.add(plugin: GitPlugin(gitDirectoryPath: gitDirectory).create()) + } + + metrics.run(with: configuration) + } +} diff --git a/Sources/XCMetricsBackendLib/Common/Extensions/+HTTPHeaders.swift b/Sources/XCMetricsBackendLib/Common/Extensions/+HTTPHeaders.swift index 9d6881d..9f85891 100644 --- a/Sources/XCMetricsBackendLib/Common/Extensions/+HTTPHeaders.swift +++ b/Sources/XCMetricsBackendLib/Common/Extensions/+HTTPHeaders.swift @@ -1,10 +1,3 @@ -// -// +HTTPHeaders.swift -// -// -// Created by Diego Otero Díaz on 18/10/24. -// - import Foundation import Vapor diff --git a/Sources/XCMetricsBackendLib/UploadMetrics/Repository/AzureRepository/AzureSharedKeyAuthorization.swift b/Sources/XCMetricsBackendLib/UploadMetrics/Repository/AzureRepository/AzureSharedKeyAuthorization.swift index f815239..94abebf 100644 --- a/Sources/XCMetricsBackendLib/UploadMetrics/Repository/AzureRepository/AzureSharedKeyAuthorization.swift +++ b/Sources/XCMetricsBackendLib/UploadMetrics/Repository/AzureRepository/AzureSharedKeyAuthorization.swift @@ -1,10 +1,3 @@ -// -// AzureSharedKeyAuthorization.swift -// -// -// Created by Diego Otero Díaz on 18/10/24. -// - import CryptoSwift import Foundation import Vapor diff --git a/docs/Getting Started.md b/docs/Getting Started.md index 2d9fa19..d85c32d 100644 --- a/docs/Getting Started.md +++ b/docs/Getting Started.md @@ -15,6 +15,15 @@ One of the pre-requisites is to get a binary release of XCMetrics directly from >If you're downloading a pre-built executable version of XCMetrics, you can skip the following section. +#### Compile TomTom's TTXCMetrics Executable +In a terminal window inside the `XCMetrics` repo, run the following: + +```shell +swift build --product TTXCMetrics -c release +``` + +An executable named `TTXCMetrics` will be placed inside `.build/release/TTXCMetrics`. This is the executable that manages the metrics collection for you. + #### Compile XCMetrics Executable In a terminal window inside the `XCMetrics` repo, run the following: From 8111de9bd6cbb23d14b8c52bf2167ec942d7c77d Mon Sep 17 00:00:00 2001 From: DiegoDiaz-TomTom Date: Thu, 7 Nov 2024 15:03:07 +0100 Subject: [PATCH 2/2] ci: update linux runner's image version --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a8c7644..80cd148 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -32,7 +32,7 @@ jobs: linux: runs-on: ubuntu-latest container: - image: swift:5.7 + image: swift:5.9-jammy steps: - name: Checkout uses: actions/checkout@v1