Skip to content
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
44 changes: 43 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ commands:
destination: Reports
path: build/reports/tests/test/

pre_start_ios_simulator:
description: >-
Pre-start iOS Simulator, as the build may fail if it takes too long to start up during that step
steps:
- run:
name: Pre-start iOS Simulator
command: |
bash CircleciScripts/pre_start_iOS_simulator.sh

jobs:
build:
environment:
Expand Down Expand Up @@ -115,6 +124,7 @@ jobs:
paths:
- smithy-swift/build
- smithy-swift/*/build

test_smithy_kotlin:
environment:
# Configure the JVM and Gradle to avoid OOM errors
Expand Down Expand Up @@ -154,6 +164,7 @@ jobs:
name: Run ktlint
command: |
./gradlew ktlint

test_smithy_swift:
environment:
# Configure the JVM and Gradle to avoid OOM errors
Expand Down Expand Up @@ -194,9 +205,32 @@ jobs:
command: |
./gradlew ktlint

build_and_unittest_swift_client_runtime:
macos:
xcode: "11.4.1"
steps:
- checkout
- pre_start_ios_simulator
- run:
name: Install swiftlint
command: |
HOMEBREW_NO_AUTO_UPDATE=1 brew install swiftlint
- run:
name: Build ClientRuntime
working_directory: ~/project/smithy-swift/ClientRuntime
command: |
xcodebuild build-for-testing -project ClientRuntime.xcodeproj -scheme ClientRuntime -sdk iphonesimulator -destination "${destination}"
- run:
name: Unit Test ClientRuntime
working_directory: ~/project/smithy-swift/ClientRuntime
command: |
xcodebuild test-without-building -enableCodeCoverage YES -project ClientRuntime.xcodeproj -scheme ClientRuntime -sdk iphonesimulator -destination "${destination}"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This saves considerable amount of time as the test files are built during the previous step build-for-testing

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good thinking love it. if build fails it never gets to this step right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope

bash <(curl https://codecov.io/bash | sed 's/"$beta_xcode_partials"//g')

workflows:
version: 2
workflow:

build_and_test_codegen:
jobs:
- build
- test_smithy_kotlin:
Expand All @@ -207,3 +241,11 @@ workflows:
requires:
- build
- lint_smithy_swift

build_and_test_swift_client_runtime:
jobs:
- build_and_unittest_swift_client_runtime:
filters:
branches:
only:
- swift-client-runtime
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently only configured for this branch

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will change when we move repos

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes also when we move this to master branch

32 changes: 32 additions & 0 deletions CircleciScripts/pre_start_iOS_simulator.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Create simulator if needed
test_device_id=$( xcrun simctl list devices | grep "circleci-test-device" | sed 's/ *circleci-test-device *(//' | sed 's/).*//' )

if [[ -z $test_device_id ]] ; then
echo "Creating test device"

# Get the most recent available runtime
runtime=$( xcrun simctl list runtimes iOS | sed 's/iOS //' | sort -h | tail -1 | sed 's/.* - //' | tr -d '[:space:]' )
echo "Runtime: '${runtime}'"

# Get the last alphabetical device (probably something in the iPhone X family, as of 2019-05-31)
devicetype=$( xcrun simctl list devicetypes iPhone | sort | tail -1 | sed 's/.*(//' | sed 's/).*//' | tr -d '[:space:]' )
echo "Device type: '${devicetype}'"

test_device_id=$( xcrun simctl create "circleci-test-device" "${devicetype}" "${runtime}" | tr -d '[:space:]' )
fi

echo "test_device_id: ${test_device_id}"
echo "export test_device_id='$test_device_id'" >> $BASH_ENV

# Boot sim if needed
xcrun simctl list devices ${test_device_id} | grep -q Booted
if [[ $? -eq 1 ]] ; then
echo "Booting ${test_device_id}"
xcrun simctl boot ${test_device_id}
fi

# destinationspecifier for xcodebuild commands
destination="platform=iOS Simulator,id=${test_device_id}"
echo "destination: ${destination}"
echo "export destination='$destination'" >> $BASH_ENV

38 changes: 38 additions & 0 deletions smithy-swift/ClientRuntime/.swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
excluded:
- Pods

analyzer_rules:
- unused_import
- unused_declaration

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These rules are same as the ones used in amplify-ios project

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same linter too right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. Swift community seems to be unanimously accepting https://github.com/realm/SwiftLint

disabled_rules:
- trailing_whitespace

opt_in_rules:
- empty_count

# configurable rules can be customized from this configuration file
force_cast: warning
closing_brace: error
colon:
severity: error
comma: error
empty_count: warning
empty_enum_arguments: error
function_body_length:
warning: 100
error: 150
identifier_name:
excluded:
- id
- of
- or
line_length:
warning: 120
error: 160
opening_brace: error
return_arrow_whitespace: error
statement_position:
severity: error
todo: warning
trailing_semicolon: error
41 changes: 39 additions & 2 deletions smithy-swift/ClientRuntime/ClientRuntime.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@
43DD7767249702C70038F7AB /* MockURLProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockURLProtocol.swift; sourceTree = "<group>"; };
43DD776924973A7A0038F7AB /* URLSessionDelegateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLSessionDelegateTests.swift; sourceTree = "<group>"; };
43DD776B24973AF60038F7AB /* NetworkingTestUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkingTestUtils.swift; sourceTree = "<group>"; };
43DD776D24981F860038F7AB /* Data+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Data+Extensions.swift"; sourceTree = "<group>"; };
43DD7770249892A10038F7AB /* BoolTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BoolTests.swift; sourceTree = "<group>"; };
43DD7772249936740038F7AB /* DateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateTests.swift; sourceTree = "<group>"; };
43DD7776249957000038F7AB /* XMLSimpleTypesTestsUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XMLSimpleTypesTestsUtils.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -541,7 +540,6 @@
43DD7767249702C70038F7AB /* MockURLProtocol.swift */,
43DD776924973A7A0038F7AB /* URLSessionDelegateTests.swift */,
43DD776B24973AF60038F7AB /* NetworkingTestUtils.swift */,
43DD776D24981F860038F7AB /* Data+Extensions.swift */,
43DD7792249BED370038F7AB /* HttpSerializeTests.swift */,
);
path = NetworkingTests;
Expand Down Expand Up @@ -647,6 +645,7 @@
43DD75D8249025250038F7AB /* Sources */,
43DD75D9249025250038F7AB /* Frameworks */,
43DD75DA249025250038F7AB /* Resources */,
43DD77D924A54B070038F7AB /* ShellScript */,
);
buildRules = (
);
Expand All @@ -664,6 +663,7 @@
43DD75E1249025250038F7AB /* Sources */,
43DD75E2249025250038F7AB /* Frameworks */,
43DD75E3249025250038F7AB /* Resources */,
43DD77D824A54A470038F7AB /* ShellScript */,
);
buildRules = (
);
Expand Down Expand Up @@ -729,6 +729,43 @@
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
43DD77D824A54A470038F7AB /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"warning: Recommended to install SwiftLint, download from https://github.com/realm/SwiftLint\"\nfi\n";
};
43DD77D924A54B070038F7AB /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"warning: Recommended to install SwiftLint, download from https://github.com/realm/SwiftLint\"\nfi\n";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Swiftlint is now build in to the build process if the executable is present in the host machine. Else this step is skipped.

};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
43DD75D8249025250038F7AB /* Sources */ = {
isa = PBXSourcesBuildPhase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ public enum ClientError: Error {
case serializationFailed(String)
case deserializationFailed(Error)
case dataNotFound(String)

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,18 @@
import Foundation

class DataNetworkOperation: NetworkOperation {

init(session: SessionProtocol, request: HttpRequest, completion: @escaping NetworkResult) {
super.init()
self.completion = completion
do {
let urlRequest = try request.toUrlRequest()
self.task = session.dataTask(with: urlRequest)
}
catch {
} catch {
completion(.failure(ClientError.serializationFailed("Serialization failed due to malformed url")))
}
}

override func receiveData(data: Data) {
response?.content = .data(data)
completion?(Result.success(response!))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public struct Endpoint {
public let protocolType: ProtocolType?
public let host: String
public let port: Int?

public init(host: String, path: String, port: Int? = nil, queryItems: [URLQueryItem]? = nil, protocolType: ProtocolType? = .https) {
self.host = host
self.path = path
Expand All @@ -48,5 +48,3 @@ public extension Endpoint {
return components.url
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@
import Foundation

public class HttpClient {

let session: SessionProtocol
let operationQueue: OperationQueue

public init(config: HttpClientConfiguration) {
self.operationQueue = config.operationQueue
let delegate = SessionDelegate(operationQueue: config.operationQueue)
self.session = URLSession(configuration: config.toUrlSessionConfig(), delegate: delegate, delegateQueue: config.operationQueue)
}

init(session: SessionProtocol, config: HttpClientConfiguration) {
self.session = session
self.operationQueue = config.operationQueue
}
public func execute(request: HttpRequest, completion: @escaping NetworkResult) -> StreamingProvider? {

public func execute(request: HttpRequest, completion: @escaping NetworkResult) -> StreamingProvider? {
switch request.body {
case .data, .file, .none :
let operation = DataNetworkOperation(session: session, request: request, completion: completion)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ public class HttpClientConfiguration {
public var protocolType: ProtocolType
//initialize with default headers
public var defaultHeaders: HttpHeaders

public var operationQueue: OperationQueue

public var protocolClasses: [AnyClass]?

//add any other properties here you want to give the service operations control over to be mappted to the urlsessionconfig below

public init(protocolType: ProtocolType = .https,
Expand All @@ -38,31 +38,34 @@ public class HttpClientConfiguration {
}

extension HttpClientConfiguration {

func toUrlSessionConfig () -> URLSessionConfiguration {
let config = URLSessionConfiguration.default
config.networkServiceType = .default
//essentially uses the network.framework to check network availablity automatically behind the scenes and wont call until network is available. do we want to set this to true for automatic reachability?
/* essentially uses the network.framework to check network availablity automatically
behind the scenes and wont call until network is available.
do we want to set this to true for automatic reachability?
*/
config.waitsForConnectivity = true
config.allowsCellularAccess = true
config.httpAdditionalHeaders = HttpHeaders().dictionary
config.operationQueue = self.operationQueue
config.requestCachePolicy = .reloadIgnoringLocalCacheData

if let protocolClasses = self.protocolClasses {
config.protocolClasses = protocolClasses
}

return config

}
}

extension URLSessionConfiguration {

static var _operationQueue:OperationQueue = OperationQueue()
var operationQueue:OperationQueue {
// swiftlint:disable identifier_name
static var _operationQueue: OperationQueue = OperationQueue()

var operationQueue: OperationQueue {
get {
return URLSessionConfiguration._operationQueue
}
Expand Down
Loading