From d90cd7cf61c79516b3fb11b67d3bad52e7080f1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Bedn=C3=A1=C5=99?= Date: Tue, 20 Oct 2020 14:58:33 +0200 Subject: [PATCH] feat: rollback structure (#3) --- .circleci/config.yml | 160 ++++++++++++++++-- .github/PULL_REQUEST_TEMPLATE.md | 2 +- .gitignore | 5 + .jazzy.yml | 6 + .swift-version | 1 + .swiftlint.yml | 41 +++++ Package.swift | 6 + README.md | 60 ++++++- Scripts/influxdb-onboarding.sh | 39 +++++ .../InfluxDBClient.swift | 7 + .../influxdb_client_swift.swift | 3 - Tests/LinuxMain.swift | 3 +- .../InfluxDBClientTests.swift | 16 ++ .../XCTestManifests.swift | 9 + .../influxdb_client_swiftTests.swift | 15 -- 15 files changed, 341 insertions(+), 32 deletions(-) create mode 100644 .jazzy.yml create mode 100644 .swift-version create mode 100644 .swiftlint.yml create mode 100755 Scripts/influxdb-onboarding.sh create mode 100644 Sources/influxdb-client-swift/InfluxDBClient.swift delete mode 100644 Sources/influxdb-client-swift/influxdb_client_swift.swift create mode 100644 Tests/influxdb-client-swiftTests/InfluxDBClientTests.swift create mode 100644 Tests/influxdb-client-swiftTests/XCTestManifests.swift delete mode 100644 Tests/influxdb-client-swiftTests/influxdb_client_swiftTests.swift diff --git a/.circleci/config.yml b/.circleci/config.yml index 01c267cc..6255849c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,13 +1,153 @@ -# Use the latest 2.1 version of CircleCI pipeline process engine. See: https://circleci.com/docs/2.0/configuration-reference +# +# The MIT License +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# + version: 2.1 -# Use a package of configuration called an orb. -orbs: - # Declare a dependency on the welcome-orb - welcome: circleci/welcome-orb@0.4.1 -# Orchestrate or schedule a set of jobs + +commands: + influxdb-onboarding: + steps: + - run: + name: "Install onBoarding dependencies" + command: | + apt-get update + apt-get install wget + apt-get install curl + apt-get install ruby --yes + gem install xcpretty + - run: + name: "Post onBoarding request to InfluxDB 2" + command: ./Scripts/influxdb-onboarding.sh + prepare: + description: "Prepare environment to tests" + steps: + - checkout + - influxdb-onboarding + +jobs: + tests-swift: + parameters: + swift-image: + type: string + default: &default-swift-image "swift:5.3" + influxdb-image: + type: string + default: &default-influxdb-image "influxdb:2.0.0-rc" + docker: + - image: << parameters.swift-image >> + - image: &influx-image quay.io/influxdb/<< parameters.influxdb-image >> + environment: + INFLUXD_HTTP_BIND_ADDRESS: :8086 + steps: + - prepare + - restore_cache: + name: Restoring Package Cache + keys: + - &cache-key package-cache-{{ checksum "Package.swift" }}-<< parameters.swift-image >> + - package-cache-{{ checksum "Package.swift" }} + - package-cache- + - run: + name: Install dependencies + command: swift package update + - run: + name: Run tests + command: | + swift build + swift test --enable-code-coverage 2>&1 | xcpretty --report junit + llvm-cov export -format="lcov" .build/debug/influxdb-client-swiftPackageTests.xctest -instr-profile .build/debug/codecov/default.profdata > info.lcov + - save_cache: + name: Saving Package Cache + key: *cache-key + paths: + - Package.resolved + - ./builde/repositories + - store_test_results: + path: build/ + - run: + name: Collecting coverage reports + command: bash <(curl -s https://codecov.io/bash) -f ./info.lcov || echo "Codecov did not collect coverage reports" + + check-code-style: + docker: + - image: *default-swift-image + steps: + - checkout + - run: | + apt-get update + apt-get install wget unzip --yes + wget https://github.com/realm/SwiftLint/releases/download/0.40.3/swiftlint_linux.zip + unzip -n swiftlint_linux.zip + - run: + name: Checks style consistency across sources. + command: ./swiftlint lint + + check-documentation: + docker: + - image: *default-swift-image + steps: + - checkout + - restore_cache: + name: Restoring Cache + keys: + - &documentation-cache-key sc-cache-v2-swift:5.3 + - run: + name: Build SourceKitten and jazzy + command: | + apt-get update + apt-get install ruby-dev libsqlite3-dev --yes + gem install jazzy + if [ ! -f ./SourceKitten/.build/debug/sourcekitten ]; then + git clone https://github.com/jpsim/SourceKitten.git + cd SourceKitten + swift build + cd ../ + fi + - run: + name: Checks generating docs. + command: | + swift build + SourceKitten/.build/debug/sourcekitten doc --spm > doc.json + jazzy --sourcekitten-sourcefile doc.json --config .jazzy.yml + - save_cache: + name: Saving Cache + key: *documentation-cache-key + paths: + - ./SourceKitten/.build/debug/sourcekitten + - /var/lib/gems/ + workflows: - # Name the workflow "welcome" - welcome: - # Run the welcome/run job in its own container + version: 2 + build: jobs: - - welcome/run \ No newline at end of file + - check-code-style + - check-documentation + - tests-swift: + name: swift-5.3 + nightly: + triggers: + - schedule: + cron: "0 0 * * *" + filters: + branches: + only: + - master + jobs: + - tests-swift diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 3164d7cd..06bdc658 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -9,6 +9,6 @@ _Briefly describe your proposed changes:_ - [ ] CHANGELOG.md updated - [ ] Rebased/mergeable - [ ] A test has been added if appropriate -- [ ] `make check` completes successfully +- [ ] `swift test` completes successfully - [ ] Commit messages are in [semantic format](https://seesparkbox.com/foundry/semantic_commit_messages) - [ ] Sign [CLA](https://influxdata.com/community/cla/) (if not already signed) diff --git a/.gitignore b/.gitignore index 121db363..f8bcb532 100644 --- a/.gitignore +++ b/.gitignore @@ -91,3 +91,8 @@ iOSInjectionProject/ # JetBrains .idea/ + +# Documentation +docs/ +doc.json +SourceKitten/ diff --git a/.jazzy.yml b/.jazzy.yml new file mode 100644 index 00000000..96fb2432 --- /dev/null +++ b/.jazzy.yml @@ -0,0 +1,6 @@ +author: InfluxData +author_url: https://www.influxdata.com +github_url: https://github.com/bonitoo-io/influxdb-client-swift +module: influxdb_client_swift +swift_build_tool: spm +clean: true \ No newline at end of file diff --git a/.swift-version b/.swift-version new file mode 100644 index 00000000..11aa1452 --- /dev/null +++ b/.swift-version @@ -0,0 +1 @@ +5.3 \ No newline at end of file diff --git a/.swiftlint.yml b/.swiftlint.yml new file mode 100644 index 00000000..f32c6bcb --- /dev/null +++ b/.swiftlint.yml @@ -0,0 +1,41 @@ +opt_in_rules: + - array_init + - collection_alignment + - contains_over_first_not_nil + - closure_end_indentation + - closure_spacing + - conditional_returns_on_newline + - empty_count + - empty_string + - explicit_acl + - explicit_init + - explicit_self + - fatal_error_message + - first_where + - force_unwrapping + - implicit_return + - missing_docs + - modifier_order + - multiline_arguments + - multiline_literal_brackets + - multiline_parameters + - operator_usage_whitespace + - pattern_matching_keywords + - redundant_nil_coalescing + - redundant_type_annotation + - sorted_first_last + - sorted_imports + - trailing_closure + - unneeded_parentheses_in_closure_argument + - unused_import + - unused_declaration + - vertical_parameter_alignment_on_call + - vertical_whitespace_closing_braces + - vertical_whitespace_opening_braces + +excluded: + - build + - .build + - Package.swift + - Tests/LinuxMain.swift + - Tests/influxdb-client-swiftTests/XCTestManifests.swift diff --git a/Package.swift b/Package.swift index b429325f..7a818576 100644 --- a/Package.swift +++ b/Package.swift @@ -5,6 +5,12 @@ import PackageDescription let package = Package( name: "influxdb-client-swift", +// platforms: [ +// .macOS(.v11), +// .iOS(.v14), +// .watchOS(.v7), +// .tvOS(.v14) +// ], products: [ // Products define the executables and libraries a package produces, and make them visible to other packages. .library( diff --git a/README.md b/README.md index c6b2a2b9..d5229f60 100644 --- a/README.md +++ b/README.md @@ -16,9 +16,43 @@ This repository contains the reference Swift client for the InfluxDB 2.0. ## Features +TBD + +## Supported Platforms + +This package requires Swift 5 and Xcode 12. + +- iOS 14.0+ +- macOS 11.0+ +- tvOS 14.0+ +- watchOS 7.0+ +- Linux + ## Installation -TBD +### Swift Package Manager + +Add this line to your `Package.swift` : + +~~~swift +.Package(url: "https://github.com/bonitoo-io/influxdb-client-swift", from: "0.0.1") +~~~ + +### CocoaPods + +Add this line to your `Podfile`: + +~~~ruby +pod 'influxdb-client-swift', '~> 0.0.1' +~~~ + +### Carthage + +Add this line to your Cartfile: + +~~~ +github "bonitoo-io/influxdb-client-swift" ~> 0.0.1 +~~~ ## Usage @@ -44,7 +78,29 @@ TBD ## Contributing -Bug reports and pull requests are welcome on GitHub at https://github.com/bonitoo-io/influxdb-client-swift. +If you would like to contribute code you can do through GitHub by forking the repository and sending a pull request into the `master` branch. + +Build Requirements: + +- swift 5.3 or higher + +Run tests: + +```bash +$ swift test +``` + +Check code coverage: + +```bash +$ swift test --enable-code-coverage +``` + +Build distributions: + +```bash +$ swift build +``` ## License diff --git a/Scripts/influxdb-onboarding.sh b/Scripts/influxdb-onboarding.sh new file mode 100755 index 00000000..85da2272 --- /dev/null +++ b/Scripts/influxdb-onboarding.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +# +# The MIT License +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# + +set -e + +echo "Wait to start InfluxDB 2.0" +wget -S --spider --tries=20 --retry-connrefused --waitretry=5 http://localhost:8086/metrics + +echo +echo "Post onBoarding request, to setup initial user (my-user@my-password), org (my-org) and bucketSetup (my-bucket)" +echo +curl -i -X POST http://localhost:8086/api/v2/setup -H 'accept: application/json' \ + -d '{ + "username": "my-user", + "password": "my-password", + "org": "my-org", + "bucket": "my-bucket", + "token": "my-token" + }' diff --git a/Sources/influxdb-client-swift/InfluxDBClient.swift b/Sources/influxdb-client-swift/InfluxDBClient.swift new file mode 100644 index 00000000..e74b5773 --- /dev/null +++ b/Sources/influxdb-client-swift/InfluxDBClient.swift @@ -0,0 +1,7 @@ +// +// Created by Jakub Bednář on 20/10/2020. +// + +/// A InfluxDB Client providing a support for APIs to write and query data. +public class InfluxDBClient { +} diff --git a/Sources/influxdb-client-swift/influxdb_client_swift.swift b/Sources/influxdb-client-swift/influxdb_client_swift.swift deleted file mode 100644 index 5b7d052f..00000000 --- a/Sources/influxdb-client-swift/influxdb_client_swift.swift +++ /dev/null @@ -1,3 +0,0 @@ -struct influxdb_client_swift { - var text = "Hello, World!" -} diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift index f30b9424..bdb81c93 100644 --- a/Tests/LinuxMain.swift +++ b/Tests/LinuxMain.swift @@ -3,4 +3,5 @@ import XCTest import influxdb_client_swiftTests var tests = [XCTestCaseEntry]() -XCTMain(tests) +tests += influxdb_client_swiftTests.allTests() +XCTMain(tests) \ No newline at end of file diff --git a/Tests/influxdb-client-swiftTests/InfluxDBClientTests.swift b/Tests/influxdb-client-swiftTests/InfluxDBClientTests.swift new file mode 100644 index 00000000..9249d94c --- /dev/null +++ b/Tests/influxdb-client-swiftTests/InfluxDBClientTests.swift @@ -0,0 +1,16 @@ +// +// Created by Jakub Bednář on 20/10/2020. +// + +@testable import influxdb_client_swift +import XCTest + +final class InfluxDBClientTests: XCTestCase { + func testCreateInstance() { + XCTAssertNotNil(InfluxDBClient()) + } + + static var allTests = [ + ("testCreateInstance", testCreateInstance) + ] +} diff --git a/Tests/influxdb-client-swiftTests/XCTestManifests.swift b/Tests/influxdb-client-swiftTests/XCTestManifests.swift new file mode 100644 index 00000000..ae3b518c --- /dev/null +++ b/Tests/influxdb-client-swiftTests/XCTestManifests.swift @@ -0,0 +1,9 @@ +import XCTest + +#if !canImport(ObjectiveC) +public func allTests() -> [XCTestCaseEntry] { + [ + testCase(InfluxDBClientTests.allTests), + ] +} +#endif diff --git a/Tests/influxdb-client-swiftTests/influxdb_client_swiftTests.swift b/Tests/influxdb-client-swiftTests/influxdb_client_swiftTests.swift deleted file mode 100644 index 8e2535ae..00000000 --- a/Tests/influxdb-client-swiftTests/influxdb_client_swiftTests.swift +++ /dev/null @@ -1,15 +0,0 @@ -import XCTest -@testable import influxdb_client_swift - -final class influxdb_client_swiftTests: XCTestCase { - func testExample() { - // This is an example of a functional test case. - // Use XCTAssert and related functions to verify your tests produce the correct - // results. - XCTAssertEqual(influxdb_client_swift().text, "Hello, World!") - } - - static var allTests = [ - ("testExample", testExample), - ] -}