Skip to content

Commit 3a9213a

Browse files
Add SDK version tracking to DataDog logs (#34)
* Added SDKVersion constant * Add SDK version to DD logs * Use actual SDK version on checkout * Use actual sdk version on HeadlessCheckoutOrderEndpoint * Added release workflow * fix: add explicit permissions to release workflow * fix: address PR feedback - run tests before file modification and atomic push
1 parent 09c4e34 commit 3a9213a

File tree

5 files changed

+113
-4
lines changed

5 files changed

+113
-4
lines changed

.github/workflows/release.yml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: 'Version number (e.g., 0.0.8)'
8+
required: true
9+
type: string
10+
11+
env:
12+
DEVELOPER_DIR: /Applications/Xcode_16.4.app/Contents/Developer
13+
14+
jobs:
15+
release:
16+
name: Create Release
17+
runs-on: macos-15
18+
permissions:
19+
contents: write
20+
21+
steps:
22+
- uses: actions/checkout@v4
23+
with:
24+
token: ${{ secrets.GITHUB_TOKEN }}
25+
26+
- name: Setup Xcode
27+
uses: maxim-lobanov/setup-xcode@v1
28+
with:
29+
xcode-version: '16.4'
30+
31+
- name: Validate version format
32+
run: |
33+
if ! echo "${{ inputs.version }}" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?$'; then
34+
echo "Error: Version must follow semantic versioning (e.g., 0.0.8 or 1.0.0-beta)"
35+
exit 1
36+
fi
37+
38+
- name: Check if tag already exists
39+
run: |
40+
if git rev-parse "${{ inputs.version }}" >/dev/null 2>&1; then
41+
echo "Error: Tag ${{ inputs.version }} already exists"
42+
exit 1
43+
fi
44+
45+
- name: Cache SPM packages
46+
uses: actions/cache@v4
47+
with:
48+
path: .build
49+
key: ${{ runner.os }}-spm-${{ hashFiles('Package.resolved') }}
50+
restore-keys: |
51+
${{ runner.os }}-spm-
52+
53+
- name: Run tests
54+
run: |
55+
make ci-test
56+
57+
- name: Run SwiftLint
58+
run: make lint
59+
60+
- name: Update SDK version in code
61+
run: |
62+
VERSION="${{ inputs.version }}"
63+
sed -i '' "s/public static let version = \".*\"/public static let version = \"$VERSION\"/" Sources/Utils/SDKVersion.swift
64+
65+
# Verify the change was made
66+
if ! grep -q "public static let version = \"$VERSION\"" Sources/Utils/SDKVersion.swift; then
67+
echo "Error: Failed to update version in SDKVersion.swift"
68+
exit 1
69+
fi
70+
71+
echo "✅ Updated SDKVersion.swift to version $VERSION"
72+
cat Sources/Utils/SDKVersion.swift
73+
74+
- name: Configure Git
75+
run: |
76+
git config user.name "github-actions[bot]"
77+
git config user.email "github-actions[bot]@users.noreply.github.com"
78+
79+
- name: Commit version bump and create tag
80+
run: |
81+
git add Sources/Utils/SDKVersion.swift
82+
git commit -m "chore: bump version to ${{ inputs.version }}"
83+
git tag "${{ inputs.version }}"
84+
git push origin main --tags
85+
86+
- name: Create GitHub Release
87+
env:
88+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
89+
run: |
90+
gh release create "${{ inputs.version }}" \
91+
--title "Release ${{ inputs.version }}" \
92+
--generate-notes

Sources/Checkout/Views/CrossmintEmbeddedCheckout.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77

88
import SwiftUI
9+
import Utils
910

1011
public struct CrossmintEmbeddedCheckout: View {
1112
private let orderId: String?
@@ -76,8 +77,7 @@ public struct CrossmintEmbeddedCheckout: View {
7677

7778
var queryItems: [URLQueryItem] = []
7879

79-
// TODO: Fetch SDK version dynamically
80-
let sdkMetadata = ["name": "@crossmint/client-sdk-swift", "version": "1.0.0"]
80+
let sdkMetadata = ["name": "@crossmint/client-sdk-swift", "version": SDKVersion.version]
8181
queryItems.append(URLQueryItem(name: "sdkMetadata", value: try sdkMetadata.toJSON()))
8282

8383
if let orderId = orderId {

Sources/Logger/DataDogLoggerProvider.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import Foundation
99
import DatadogCore
1010
import DatadogLogs
11+
import Utils
1112

1213
final class DataDogLoggerProvider: LoggerProvider {
1314
private nonisolated(unsafe) static var isDataDogInitialized: Bool = false
@@ -49,7 +50,8 @@ final class DataDogLoggerProvider: LoggerProvider {
4950
private func buildAttributes(_ attributes: [String: any Encodable]?) -> [String: Encodable] {
5051
var loggerAttributes: [String: Encodable] = [
5152
"service": service,
52-
"platform": "ios"
53+
"platform": "ios",
54+
"sdk_version": SDKVersion.version
5355
]
5456

5557
if let attributes {

Sources/Payments/HeadlessCheckout/Manager/Models/HeadlessCheckoutOrderEndpoint.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import CrossmintService
22
import Http
3+
import Utils
34

45
public enum HeadlessCheckoutOrderEndpoint {
56
case getOrder(orderId: String, headers: [String: String] = [:])
@@ -23,7 +24,7 @@ public enum HeadlessCheckoutOrderEndpoint {
2324
)
2425
case .createOrder(let input, let headers):
2526
let orderSourceHeader = OrderSourceHeader(
26-
sdkMetadata: OrderSourceSDKMetadata(version: "1.0.0") // TODO: get the version from the SDK
27+
sdkMetadata: OrderSourceSDKMetadata(version: SDKVersion.version)
2728
)
2829
var headersWithOrderSource = headers
2930
headersWithOrderSource["x-order-source"] = orderSourceHeader.json()

Sources/Utils/SDKVersion.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//
2+
// SDKVersion.swift
3+
// CrossmintSDK
4+
//
5+
// Created by Tomas Martins on 8/12/25.
6+
//
7+
8+
import Foundation
9+
10+
/// This version is automatically updated by the release workflow
11+
public enum SDKVersion {
12+
/// The current version of the Crossmint Swift SDK
13+
public static let version = "0.0.7"
14+
}

0 commit comments

Comments
 (0)