From 4239ca8cc7e08bcce347397290a92d44d59daeb8 Mon Sep 17 00:00:00 2001 From: Paul Beusterien Date: Tue, 26 Jan 2021 13:15:21 -0800 Subject: [PATCH] Initial CI and SPM (#1) --- .github/workflows/check.yml | 53 +++++++++++ .github/workflows/datatransport.yml | 28 ++---- .github/workflows/spm.yml | 22 +++++ .gitignore | 53 +++++++++++ .../GDTCCTWatchOSTestApp/Podfile | 12 +-- .../GDTCORLibrary/GDTCORPlatform.m | 2 +- Mintfile | 1 + Package.swift | 92 +++++++++++++++++++ SwiftPMTests/objc-import-test/objc-header.m | 19 ++++ SwiftPMTests/objc-import-test/objc-module.m | 15 +++ SwiftPMTests/swift-test/main.swift | 24 +++++ setup-scripts.sh | 22 +++++ 12 files changed, 315 insertions(+), 28 deletions(-) create mode 100644 .github/workflows/check.yml create mode 100644 .github/workflows/spm.yml create mode 100644 .gitignore create mode 100644 Mintfile create mode 100644 Package.swift create mode 100644 SwiftPMTests/objc-import-test/objc-header.m create mode 100644 SwiftPMTests/objc-import-test/objc-module.m create mode 100644 SwiftPMTests/swift-test/main.swift create mode 100755 setup-scripts.sh diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 0000000..7ff802f --- /dev/null +++ b/.github/workflows/check.yml @@ -0,0 +1,53 @@ +name: check + +on: + pull_request: + push: + branches: main + +jobs: + check: + runs-on: macos-latest + env: + MINT_PATH: ${{ github.workspace }}/mint + steps: + - uses: actions/checkout@v2 + + - uses: actions/setup-python@v2 + with: + python-version: 3.6 + + - name: Cache Mint packages + uses: actions/cache@v1 + with: + path: ${{ env.MINT_PATH }} + key: ${{ runner.os }}-mint-${{ hashFiles('**/Mintfile') }} + restore-keys: ${{ runner.os }}-mint- + + - name: Setup Scripts Directory + run: ./setup-scripts.sh + + - name: Setup check + run: | + brew update + brew install clang-format@11 + brew install mint + mint bootstrap + + - name: Style + run: scripts/style.sh test-only + + - name: Whitespace + run: scripts/check_whitespace.sh + + - name: Filename spaces + run: scripts/check_filename_spaces.sh + + - name: Copyrights + run: scripts/check_copyright.sh + + - name: Module imports + run: scripts/check_no_module_imports.sh + + - name: Imports + run: scripts/check_imports.swift diff --git a/.github/workflows/datatransport.yml b/.github/workflows/datatransport.yml index 9bb451b..52f4a60 100644 --- a/.github/workflows/datatransport.yml +++ b/.github/workflows/datatransport.yml @@ -2,25 +2,20 @@ name: datatransport on: pull_request: - paths: - - 'GoogleDataTransport**' - - '.github/workflows/datatransport.yml' - - 'Gemfile' schedule: # Run every day at 11pm (PST) - cron uses UTC times - cron: '0 7 * * *' jobs: pod_lib_lint: - # Don't run on private repo unless it is a PR. - if: (github.repository == 'Firebase/firebase-ios-sdk' && github.event_name == 'schedule') || github.event_name == 'pull_request' - runs-on: macos-latest strategy: matrix: target: [ios, tvos, macos, watchos] steps: - uses: actions/checkout@v2 + - name: Setup Scripts Directory + run: ./setup-scripts.sh - name: Setup Bundler run: ./scripts/setup_bundler.sh - name: PodLibLint DataTransport @@ -28,26 +23,24 @@ jobs: scripts/third_party/travis/retry.sh scripts/pod_lib_lint.rb GoogleDataTransport.podspec --platforms=${{ matrix.target }} catalyst: - # Don't run on private repo unless it is a PR. - if: (github.repository == 'Firebase/firebase-ios-sdk' && github.event_name == 'schedule') || github.event_name == 'pull_request' - runs-on: macOS-latest steps: - uses: actions/checkout@v2 + - name: Setup Scripts Directory + run: ./setup-scripts.sh - name: Setup Bundler run: scripts/setup_bundler.sh - name: Setup project and Test Catalyst run: scripts/third_party/travis/retry.sh scripts/test_catalyst.sh GoogleDataTransport build watchos-testapp: - # Don't run on private repo unless it is a PR. - if: (github.repository == 'Firebase/firebase-ios-sdk' && github.event_name == 'schedule') || github.event_name == 'pull_request' - runs-on: macOS-latest steps: - uses: actions/checkout@v2 - name: Xcode 12 run: sudo xcode-select -s /Applications/Xcode_12.app/Contents/Developer + - name: Setup Scripts Directory + run: ./setup-scripts.sh - name: Setup Bundler run: scripts/setup_bundler.sh - name: Prereqs @@ -55,12 +48,7 @@ jobs: - name: Setup project and build watchOS test app run: scripts/third_party/travis/retry.sh scripts/build.sh GoogleDataTransport watchOS xcodebuild -# Scheduled jobs - - datatransport-cron-only: - # Don't run on private repo. - if: github.event_name == 'schedule' && github.repository == 'Firebase/firebase-ios-sdk' - + datatransport-options-matrix: runs-on: macos-latest strategy: matrix: @@ -72,6 +60,8 @@ jobs: needs: pod_lib_lint steps: - uses: actions/checkout@v2 + - name: Setup Scripts Directory + run: ./setup-scripts.sh - name: Setup Bundler run: ./scripts/setup_bundler.sh - name: PodLibLint DataTransport Cron diff --git a/.github/workflows/spm.yml b/.github/workflows/spm.yml new file mode 100644 index 0000000..2fe8365 --- /dev/null +++ b/.github/workflows/spm.yml @@ -0,0 +1,22 @@ +name: spm + +on: + pull_request: + schedule: + # Run every day at 11pm (PST) - cron uses UTC times + - cron: '0 7 * * *' + +jobs: + swift-build-run: + runs-on: macOS-latest + strategy: + matrix: + target: [iOS, tvOS, macOS, catalyst] + steps: + - uses: actions/checkout@v2 + - name: Setup Scripts Directory + run: ./setup-scripts.sh + - name: Initialize xcodebuild + run: xcodebuild -list + - name: iOS Unit Tests + run: scripts/third_party/travis/retry.sh scripts/build.sh GoogleDataTransport ${{ matrix.target }} spm diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..592d6c4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,53 @@ +# OS X +.DS_Store + +# Xcode +build/ +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata/ +*.xccheckout +profile +*.moved-aside +DerivedData +*.hmap +*.ipa + +# Swift Package Manager +*/.build +Package.resolved + +# Mint package manager +Mint + +# IntelliJ +.idea + +# Vim +*.swo +*.swp +*~ + +# Bundler +/.bundle +/vendor + +# Pods +Pods/ +Podfile.lock +*.xcworkspace + +# CocoaPods generate +gen/ + +#firebase-ios-sdk clone +firebase-ios-sdk/ + +#scripts link +scripts diff --git a/GoogleDataTransport/GDTCCTWatchOSTestApp/Podfile b/GoogleDataTransport/GDTCCTWatchOSTestApp/Podfile index 222c363..30f67f0 100644 --- a/GoogleDataTransport/GDTCCTWatchOSTestApp/Podfile +++ b/GoogleDataTransport/GDTCCTWatchOSTestApp/Podfile @@ -9,12 +9,9 @@ target 'GDTCCTWatchOSIndependentTestAppWatchKitExtension' do # Pods for GDTCCTWatchOSIndependentTestAppWatchKitExtension pod 'SwiftProtobuf', '~> 1.0' pod 'GoogleDataTransport', :path => '../../' - pod 'FirebaseCore', :path => '../../' - pod 'FirebaseMessaging', :path => '../../' - pod 'FirebaseInstanceID', :path => '../../' - pod 'FirebaseCoreDiagnostics', :path => '../../' - pod 'FirebaseInstallations', :path => '../../' - pod 'FirebaseStorage', :path => '../../' + pod 'FirebaseCore' + pod 'FirebaseMessaging' + pod 'FirebaseStorage' end @@ -22,8 +19,7 @@ target 'GDTCCTServiceExtension' do platform :watchos, '6.0' # Pods for GDTCCTServiceExtension - pod 'FirebaseMessaging', :path => '../../' - pod 'FirebaseInstanceID', :path => '../../' + pod 'FirebaseMessaging' pod 'SwiftProtobuf', '~> 1.0' pod 'GoogleDataTransport', :path => '../../' end diff --git a/GoogleDataTransport/GDTCORLibrary/GDTCORPlatform.m b/GoogleDataTransport/GDTCORLibrary/GDTCORPlatform.m index d3f245d..e7bbbf6 100644 --- a/GoogleDataTransport/GDTCORLibrary/GDTCORPlatform.m +++ b/GoogleDataTransport/GDTCORLibrary/GDTCORPlatform.m @@ -149,7 +149,7 @@ GDTCORNetworkMobileSubtype GDTCORNetworkMobileSubTypeMessage() { } else { return GDTCORNetworkMobileSubtypeUNKNOWN; } -#else // TARGET_OS_IOS +#else // TARGET_OS_IOS return GDTCORNetworkMobileSubtypeUNKNOWN; #endif // TARGET_OS_IOS } diff --git a/Mintfile b/Mintfile new file mode 100644 index 0000000..30fa82e --- /dev/null +++ b/Mintfile @@ -0,0 +1 @@ +nicklockwood/SwiftFormat@0.45.5 diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..e968892 --- /dev/null +++ b/Package.swift @@ -0,0 +1,92 @@ +// swift-tools-version:5.3 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +// Copyright 2021 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 PackageDescription + +let package = Package( + name: "GoogleDataTransport", + platforms: [.iOS(.v10), .macOS(.v10_12), .tvOS(.v10), .watchOS(.v6)], + products: [ + .library( + name: "GoogleDataTransport", + targets: ["GoogleDataTransport"] + ), + ], + dependencies: [ + .package( + name: "nanopb", + url: "https://github.com/firebase/nanopb.git", + "2.30907.0" ..< "2.30908.0" + ), + ], + // TODO: Restructure directory structure to simplify the excludes here. + targets: [ + .target( + name: "GoogleDataTransport", + dependencies: [ + .product(name: "nanopb", package: "nanopb"), + ], + path: "GoogleDataTransport", + exclude: [ + "CHANGELOG.md", + "README.md", + "generate_project.sh", + "GDTCCTWatchOSTestApp/", + "GDTWatchOSTestApp/", + "GDTCCTTestApp/", + "GDTTestApp/", + "GDTCCTTests/", + "GDTCORTests/", + "ProtoSupport/", + ], + sources: [ + "GDTCORLibrary", + "GDTCCTLibrary", + ], + publicHeadersPath: "GDTCORLibrary/Public", + cSettings: [ + .headerSearchPath("../"), + .define("GDTCOR_VERSION", to: "0.0.1"), + .define("PB_FIELD_32BIT", to: "1"), + .define("PB_NO_PACKED_STRUCTS", to: "1"), + .define("PB_ENABLE_MALLOC", to: "1"), + ], + linkerSettings: [ + .linkedFramework("SystemConfiguration", .when(platforms: [.iOS, .macOS, .tvOS])), + .linkedFramework("CoreTelephony", .when(platforms: [.macOS, .iOS])), + ] + ), + .testTarget( + name: "swift-test", + dependencies: [ + "GoogleDataTransport", + ], + path: "SwiftPMTests/swift-test" + ), + .testTarget( + name: "objc-import-test", + dependencies: [ + "GoogleDataTransport", + ], + path: "SwiftPMTests/objc-import-test" + ), + // TODO: - need to port Network/third_party/GTMHTTPServer.m to ARC. + // TODO: - Setup unit tests in SPM. + ], + cLanguageStandard: .c99, + cxxLanguageStandard: CXXLanguageStandard.gnucxx14 +) diff --git a/SwiftPMTests/objc-import-test/objc-header.m b/SwiftPMTests/objc-import-test/objc-header.m new file mode 100644 index 0000000..31b81fd --- /dev/null +++ b/SwiftPMTests/objc-import-test/objc-header.m @@ -0,0 +1,19 @@ +// Copyright 2021 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 "GoogleDataTransport/GDTCORClock.h" +#import "GoogleDataTransport/GDTCORTransport.h" + +#import +#import diff --git a/SwiftPMTests/objc-import-test/objc-module.m b/SwiftPMTests/objc-import-test/objc-module.m new file mode 100644 index 0000000..7b73041 --- /dev/null +++ b/SwiftPMTests/objc-import-test/objc-module.m @@ -0,0 +1,15 @@ +// Copyright 2021 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 GoogleDataTransport; diff --git a/SwiftPMTests/swift-test/main.swift b/SwiftPMTests/swift-test/main.swift new file mode 100644 index 0000000..5addedc --- /dev/null +++ b/SwiftPMTests/swift-test/main.swift @@ -0,0 +1,24 @@ +// Copyright 2021 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 GoogleDataTransport + +import XCTest + +class importTest: XCTestCase { + func testImports() throws { + XCTAssertTrue(GDTCORClock.snapshot().timeMillis > 0) + } +} diff --git a/setup-scripts.sh b/setup-scripts.sh new file mode 100755 index 0000000..423b82a --- /dev/null +++ b/setup-scripts.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# Copyright 2021 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. + +git clone \ + --depth 1 \ + --no-checkout \ + https://github.com/firebase/firebase-ios-sdk.git \ +; +cd firebase-ios-sdk +git checkout master -- scripts +cd .. +ln -s firebase-ios-sdk/scripts scripts