Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement userAgent for Data Connect #8

Merged
merged 3 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/spm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ jobs:
target: [iOS, tvOS, macOS, catalyst, visionOS]
xcode: [Xcode_15.2, Xcode_15.4, Xcode_16_Release_Candidate]
runs-on: ${{ matrix.os }}
env:
FIREBASE_MAIN: 1
steps:
- uses: actions/checkout@v4
- name: Xcode
Expand Down
19 changes: 15 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import class Foundation.ProcessInfo
import PackageDescription

// let firebaseVersion = "10.25.0"

let package = Package(
name: "FirebaseDataConnect",
platforms: [.iOS(.v12), .macCatalyst(.v13), .macOS(.v10_15), .tvOS(.v13), .watchOS(.v7)],
Expand All @@ -31,8 +29,7 @@ let package = Package(
),
],
dependencies: [
.package(url: "https://github.com/firebase/firebase-ios-sdk",
from: "11.0.0"),
firebaseDependency(),
.package(
url: "https://github.com/grpc/grpc-swift.git",
from: "1.19.1" // TODO: Constrain to a range at time of release
Expand All @@ -43,6 +40,8 @@ let package = Package(
name: "FirebaseDataConnect",
dependencies: [
.product(name: "GRPC", package: "grpc-swift"),
.product(name: "FirebaseCore", package: "firebase-ios-sdk"),
// TODO: Investigate switching Auth and AppCheck to interop.
.product(name: "FirebaseAuth", package: "firebase-ios-sdk"),
.product(name: "FirebaseAppCheck", package: "firebase-ios-sdk"),

Expand All @@ -56,3 +55,15 @@ let package = Package(
),
]
)

func firebaseDependency() -> Package.Dependency {
let firebaseURL = "https://github.com/firebase/firebase-ios-sdk"

// Point SPM CI to the tip of main of https://github.com/firebase/firebase-ios-sdk so that the
// release process can defer publishing the GoogleAppMeasurement tag until after testing.
if ProcessInfo.processInfo.environment["FIREBASE_MAIN"] != nil {
return .package(url: firebaseURL, branch: "main")
}

return .package(url: firebaseURL, exact: "11.3.0")
}
23 changes: 23 additions & 0 deletions Sources/Internal/Component.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import Foundation

/// Class for registration with the Firebase component system, including userAgent functionality.
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
@objc(FIRDataConnectComponent) class DataConnectComponent: NSObject {
@objc class func sdkVersion() -> String {
return Version.version
}
}
20 changes: 20 additions & 0 deletions Sources/Internal/Version.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import Foundation

@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
struct Version {
static let version = "11.3.0-beta"
}
40 changes: 40 additions & 0 deletions Tests/Unit/UserAgentTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import Foundation
import XCTest

import FirebaseCore
@testable import FirebaseDataConnect

final class UserAgentTests: XCTestCase {
static var options: FirebaseOptions = {
let options = FirebaseOptions(googleAppID: "0:0000000000000:ios:0000000000000000",
gcmSenderID: "00000000000000000-00000000000-000000000")
options.projectID = "user-agent-test"
options.apiKey = "testUserAgentDummyApiKey"
return options
}()

override class func setUp() {
FirebaseApp.configure(name: "user-agent", options: options)
}

/// Confirm that Data Connect gets added to the user agent.
func testUserAgent() {
let userAgent = FirebaseApp.firebaseUserAgent()
paulb777 marked this conversation as resolved.
Show resolved Hide resolved
let version = Version.version
XCTAssertTrue(userAgent.contains("fire-dc/\(version)"))
}
}
Loading