From 4f9999e40871d7f21113d46cf871a10941128476 Mon Sep 17 00:00:00 2001 From: Jan Kobersky Date: Fri, 27 Oct 2023 14:31:27 +0200 Subject: [PATCH 1/6] Resolved #41: Added addAsyncOperation function --- .../WPNAsyncOperation.swift | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Sources/WultraPowerauthNetworking/WPNAsyncOperation.swift b/Sources/WultraPowerauthNetworking/WPNAsyncOperation.swift index 0b7a46f..ff12f5f 100644 --- a/Sources/WultraPowerauthNetworking/WPNAsyncOperation.swift +++ b/Sources/WultraPowerauthNetworking/WPNAsyncOperation.swift @@ -53,6 +53,20 @@ open class WPNAsyncBlockOperation: WPNAsyncOperation { } } +public extension OperationQueue { + + + /// Creates an asynchonous operation with the execution block and adds to the receiver. + /// - Parameters: + /// - completionQueue: Disatch queue that in which will be the completionblocked called + /// - executionBlock: Block to execute + func addAsyncOperation(_ completionQueue: DispatchQueue? = nil, _ executionBlock: @escaping WPNAsyncBlockOperation.ExecutionBlock) { + let op = WPNAsyncBlockOperation(executionBlock) + op.completionQueue = completionQueue + addOperation(op) + } +} + /// Base class for asynchronous operations that will be put in `OperationQueue` open class WPNAsyncOperation: Operation, CompletableInSpecificQueue { From cbaafb0cc027ff282117bd0e0b0dc5d88b7b2cbd Mon Sep 17 00:00:00 2001 From: Jan Kobersky Date: Fri, 27 Oct 2023 14:53:02 +0200 Subject: [PATCH 2/6] Fixed #44: Replaced serializeSignedRequests with concurencyStrategy --- .../WPNAsyncOperation.swift | 1 - .../WPNNetworkingService.swift | 35 ++++++++++++------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/Sources/WultraPowerauthNetworking/WPNAsyncOperation.swift b/Sources/WultraPowerauthNetworking/WPNAsyncOperation.swift index ff12f5f..fbc6d83 100644 --- a/Sources/WultraPowerauthNetworking/WPNAsyncOperation.swift +++ b/Sources/WultraPowerauthNetworking/WPNAsyncOperation.swift @@ -55,7 +55,6 @@ open class WPNAsyncBlockOperation: WPNAsyncOperation { public extension OperationQueue { - /// Creates an asynchonous operation with the execution block and adds to the receiver. /// - Parameters: /// - completionQueue: Disatch queue that in which will be the completionblocked called diff --git a/Sources/WultraPowerauthNetworking/WPNNetworkingService.swift b/Sources/WultraPowerauthNetworking/WPNNetworkingService.swift index f1202ad..ea55809 100644 --- a/Sources/WultraPowerauthNetworking/WPNNetworkingService.swift +++ b/Sources/WultraPowerauthNetworking/WPNNetworkingService.swift @@ -18,6 +18,24 @@ import Foundation import PowerAuth2 import PowerAuthCore +/// Strategy that decides if request will be put in serial or concurent queue. +/// +/// More about this topic can be found in the +/// [PowerAuth documentation](https://developers.wultra.com/components/powerauth-mobile-sdk/develop/documentation/PowerAuth-SDK-for-iOS#request-synchronization) +public enum WPNRequestConcurencyStrategy { + /// All requests will be put into concurent queue. + /// + /// We recommend not using this option unless you're managing theserialization of requests yourself. + /// + /// More about this topic can be found in the + /// [PowerAuth documentation](https://developers.wultra.com/components/powerauth-mobile-sdk/develop/documentation/PowerAuth-SDK-for-iOS#request-synchronization) + case concurentAll + /// Only request that needs PowerAuth signature will be put into serial queue. + case serialSigned + /// All requests will be put into serial queue. + case serialAll +} + /// Networking service for dispatching PowerAuth signed requests. public class WPNNetworkingService { @@ -32,19 +50,10 @@ public class WPNNetworkingService { /// Response delegate is called on each received response public weak var responseDelegate: WPNResponseDelegate? - /// Requests that should be signed with the PowerAuth signing will - /// be serialized in the PowerAuth serial queue when the value is `true`. - /// - /// Default value is `true` - /// - /// With this approach, all signed requests across `WPNNetworkingService` instances using the - /// the same PowerAuth instance (and possibly other classes too) will be serialized into - /// the single serial queue. We recommend leaving this option on unless you're managing the - /// serialization of requests yourself. + /// Strategy that decides if request will be put in serial or concurent queue. /// - /// More about this topic can be found in the - /// [PowerAuth documentation](https://developers.wultra.com/components/powerauth-mobile-sdk/develop/documentation/PowerAuth-SDK-for-iOS#request-synchronization) - public var serializeSignedRequests: Bool = true + /// Default value is `serialSigned` + public var concurencyStrategy = WPNRequestConcurencyStrategy.serialSigned /// PowerAuth instance that will be used for this networking. public let powerAuth: PowerAuthSDK @@ -251,7 +260,7 @@ public class WPNNetworkingService { op.completionQueue = completionQueue - if serializeSignedRequests && request.needsSignature { + if (concurencyStrategy == .serialSigned && request.needsSignature) || concurencyStrategy == .serialAll { // Add operation to the "signing" queue. if !powerAuth.executeOperation(onSerialQueue: op) { // Operation wont be added to the queue if there is a missing From e10da196d8b6131b281718fd1f481ff4da570665 Mon Sep 17 00:00:00 2001 From: Jan Kobersky Date: Fri, 27 Oct 2023 14:53:11 +0200 Subject: [PATCH 3/6] Project upgrade --- Deploy/WultraPowerAuthNetworking.podspec | 4 ++-- Package.swift | 6 ++--- .../WPNHttpClient.swift | 9 ++----- .../WPNNetworkingService.swift | 3 --- .../WultraPowerauthNetworking/WPNUtils.swift | 24 ++++--------------- WultraPowerAuthNetworking.podspec | 4 ++-- .../project.pbxproj | 19 ++++++++++----- .../WultraPowerAuthNetworking.xcscheme | 2 +- 8 files changed, 28 insertions(+), 43 deletions(-) diff --git a/Deploy/WultraPowerAuthNetworking.podspec b/Deploy/WultraPowerAuthNetworking.podspec index bef7741..8916b22 100644 --- a/Deploy/WultraPowerAuthNetworking.podspec +++ b/Deploy/WultraPowerAuthNetworking.podspec @@ -10,8 +10,8 @@ Pod::Spec.new do |s| s.source = { :git => 'https://github.com/wultra/networking-apple.git', :tag => s.version } s.source_files = 'Sources/WultraPowerauthNetworking/**/*.swift' s.platform = :ios - s.swift_version = "5.7" - s.ios.deployment_target = '11.0' + s.swift_version = "5.9" + s.ios.deployment_target = '12.0' s.dependency 'PowerAuth2', '>= 1.7.3' end \ No newline at end of file diff --git a/Package.swift b/Package.swift index 550349c..6e27a38 100644 --- a/Package.swift +++ b/Package.swift @@ -1,12 +1,12 @@ -// swift-tools-version:5.7 +// swift-tools-version:5.9 import PackageDescription let package = Package( name: "WultraPowerAuthNetworking", platforms: [ - .iOS(.v11), - .tvOS(.v11) + .iOS(.v12), + .tvOS(.v12) ], products: [ .library( diff --git a/Sources/WultraPowerauthNetworking/WPNHttpClient.swift b/Sources/WultraPowerauthNetworking/WPNHttpClient.swift index aa91717..ccad237 100644 --- a/Sources/WultraPowerauthNetworking/WPNHttpClient.swift +++ b/Sources/WultraPowerauthNetworking/WPNHttpClient.swift @@ -62,13 +62,8 @@ class WPNHttpClient: NSObject, URLSessionDelegate { } if let progressCallback = progressCallback { - if #available(iOS 11.0, tvOS 11.0, *) { - observation = task.progress.observe(\.fractionCompleted) { progress, _ in - progressCallback(progress.fractionCompleted) - } - } else { - // iOS 10 (iPhone 5 and older) - progressCallback(-1) + observation = task.progress.observe(\.fractionCompleted) { progress, _ in + progressCallback(progress.fractionCompleted) } } task.resume() diff --git a/Sources/WultraPowerauthNetworking/WPNNetworkingService.swift b/Sources/WultraPowerauthNetworking/WPNNetworkingService.swift index ea55809..46434c5 100644 --- a/Sources/WultraPowerauthNetworking/WPNNetworkingService.swift +++ b/Sources/WultraPowerauthNetworking/WPNNetworkingService.swift @@ -85,7 +85,6 @@ public class WPNNetworkingService { /// - timeoutInterval: Timeout interval of the request. /// Value from `config` will be used when nil. /// - progressCallback: Reports fraction of how much data was already transferred. - /// Note that on iOS 10 it will be called once with value -1. /// - completionQueue: Queue on wich the completion will be executed. /// Default value is .main /// - completion: Completion handler. This callback is executed on the queue defined in `completionQueue` parameter. @@ -115,7 +114,6 @@ public class WPNNetworkingService { /// - timeoutInterval: Timeout interval of the request. /// Value from `config` will be used when nil. /// - progressCallback: Reports fraction of how much data was already transferred. - /// Note that on iOS 10 it will be called once with value -1. /// - completionQueue: Queue on wich the completion will be executed. /// Default value is .main /// - completion: Completion handler. This callback is executed on the queue defined in `completionQueue` parameter. @@ -146,7 +144,6 @@ public class WPNNetworkingService { /// - timeoutInterval: Timeout interval of the request. /// Value from `config` will be used when nil. /// - progressCallback: Reports fraction of how much data was already transferred. - /// Note that on iOS 10 it will be called once with value -1. /// - completionQueue: Queue on wich the completion will be executed. /// Default value is .main /// - completion: Completion handler. This callback is executed on the queue defined in `completionQueue` parameter. diff --git a/Sources/WultraPowerauthNetworking/WPNUtils.swift b/Sources/WultraPowerauthNetworking/WPNUtils.swift index ee51706..ff59654 100644 --- a/Sources/WultraPowerauthNetworking/WPNUtils.swift +++ b/Sources/WultraPowerauthNetworking/WPNUtils.swift @@ -55,13 +55,7 @@ internal class WPNConnectionMonitor { } var status: Status { - guard #available(iOS 12.0, tvOS 12.0, *), let monitor = self.monitor as? NWPathMonitor else { - // fallback for iOS11 and older. There is no direct way how to easily get the network status without - // some utility class. As this is just a metadata info, we'll do it the best effort way. - return .unknown - } let path = monitor.currentPath - if path.usesInterfaceType(.cellular) { return .cellular } else if path.usesInterfaceType(.wifi) { @@ -75,23 +69,15 @@ internal class WPNConnectionMonitor { } } - private let monitor: Any? + private let monitor: NWPathMonitor init() { - if #available(iOS 12.0, tvOS 12.0, *) { - let m = NWPathMonitor() - m.start(queue: .global()) - monitor = m - } else { - monitor = nil - } + let m = NWPathMonitor() + m.start(queue: .global()) + monitor = m } deinit { - if #available(iOS 12.0, tvOS 12.0, *) { - if let monitor = self.monitor as? NWPathMonitor { - monitor.cancel() - } - } + monitor.cancel() } } diff --git a/WultraPowerAuthNetworking.podspec b/WultraPowerAuthNetworking.podspec index d297004..2f61c88 100644 --- a/WultraPowerAuthNetworking.podspec +++ b/WultraPowerAuthNetworking.podspec @@ -10,8 +10,8 @@ Pod::Spec.new do |s| s.source = { :git => 'https://github.com/wultra/networking-apple.git', :tag => s.version } s.source_files = 'Sources/WultraPowerauthNetworking/**/*.swift' s.platform = :ios - s.swift_version = "5.7" - s.ios.deployment_target = '11.0' + s.swift_version = "5.9" + s.ios.deployment_target = '12.0' s.dependency 'PowerAuth2', '>= 1.7' end diff --git a/WultraPowerAuthNetworking.xcodeproj/project.pbxproj b/WultraPowerAuthNetworking.xcodeproj/project.pbxproj index 914544f..6884d9a 100644 --- a/WultraPowerAuthNetworking.xcodeproj/project.pbxproj +++ b/WultraPowerAuthNetworking.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 52; + objectVersion = 54; objects = { /* Begin PBXBuildFile section */ @@ -164,8 +164,9 @@ OBJ_1 /* Project object */ = { isa = PBXProject; attributes = { + BuildIndependentTargetsInParallel = YES; LastSwiftMigration = 1300; - LastUpgradeCheck = 1340; + LastUpgradeCheck = 1500; }; buildConfigurationList = OBJ_2 /* Build configuration list for PBXProject "WultraPowerAuthNetworking" */; compatibilityVersion = "Xcode 3.2"; @@ -258,6 +259,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COMBINE_HIDPI_IMAGES = YES; COPY_PHASE_STRIP = NO; + DEAD_CODE_STRIPPING = YES; DEBUG_INFORMATION_FORMAT = dwarf; DYLIB_INSTALL_NAME_BASE = "@rpath"; ENABLE_NS_ASSERTIONS = YES; @@ -276,7 +278,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MACOSX_DEPLOYMENT_TARGET = 10.15; ONLY_ACTIVE_ARCH = YES; OTHER_SWIFT_FLAGS = "$(inherited) -DXcode"; @@ -285,7 +287,7 @@ SUPPORTS_MACCATALYST = YES; SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited) SWIFT_PACKAGE DEBUG"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - TVOS_DEPLOYMENT_TARGET = 10.0; + TVOS_DEPLOYMENT_TARGET = 12.0; USE_HEADERMAP = NO; WATCHOS_DEPLOYMENT_TARGET = 2.0; }; @@ -295,6 +297,7 @@ isa = XCBuildConfiguration; buildSettings = { CURRENT_PROJECT_VERSION = 1; + DEAD_CODE_STRIPPING = YES; ENABLE_TESTABILITY = YES; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -316,6 +319,7 @@ SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited)"; SWIFT_VERSION = 5.0; TARGET_NAME = WultraPowerAuthNetworking; + TVOS_DEPLOYMENT_TARGET = 12.0; }; name = Debug; }; @@ -323,6 +327,7 @@ isa = XCBuildConfiguration; buildSettings = { CURRENT_PROJECT_VERSION = 1; + DEAD_CODE_STRIPPING = YES; ENABLE_TESTABILITY = YES; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -344,6 +349,7 @@ SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited)"; SWIFT_VERSION = 5.0; TARGET_NAME = WultraPowerAuthNetworking; + TVOS_DEPLOYMENT_TARGET = 12.0; }; name = Release; }; @@ -372,6 +378,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COMBINE_HIDPI_IMAGES = YES; COPY_PHASE_STRIP = YES; + DEAD_CODE_STRIPPING = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DYLIB_INSTALL_NAME_BASE = "@rpath"; ENABLE_STRICT_OBJC_MSGSEND = YES; @@ -387,7 +394,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MACOSX_DEPLOYMENT_TARGET = 10.15; OTHER_SWIFT_FLAGS = "$(inherited) -DXcode"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -396,7 +403,7 @@ SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited) SWIFT_PACKAGE"; SWIFT_COMPILATION_MODE = wholemodule; SWIFT_OPTIMIZATION_LEVEL = "-O"; - TVOS_DEPLOYMENT_TARGET = 10.0; + TVOS_DEPLOYMENT_TARGET = 12.0; USE_HEADERMAP = NO; WATCHOS_DEPLOYMENT_TARGET = 2.0; }; diff --git a/WultraPowerAuthNetworking.xcodeproj/xcshareddata/xcschemes/WultraPowerAuthNetworking.xcscheme b/WultraPowerAuthNetworking.xcodeproj/xcshareddata/xcschemes/WultraPowerAuthNetworking.xcscheme index 9ce545c..c7e0d7a 100644 --- a/WultraPowerAuthNetworking.xcodeproj/xcshareddata/xcschemes/WultraPowerAuthNetworking.xcscheme +++ b/WultraPowerAuthNetworking.xcodeproj/xcshareddata/xcschemes/WultraPowerAuthNetworking.xcscheme @@ -1,6 +1,6 @@ Date: Fri, 27 Oct 2023 16:21:18 +0200 Subject: [PATCH 4/6] Fixed #45: Using specific version of swiftlint --- .github/workflows/build.yml | 8 +- .github/workflows/lint.yml | 14 +--- .gitignore | 2 + .../project.pbxproj | 3 +- scripts/swiftlint.sh | 84 +++++++++++++++++++ scripts/xcodeselect.sh | 8 ++ 6 files changed, 101 insertions(+), 18 deletions(-) create mode 100755 scripts/swiftlint.sh create mode 100755 scripts/xcodeselect.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 82530e1..f3ffaaf 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,19 +7,15 @@ on: - main - release/* pull_request: - schedule: - - cron: '25 6 * * *' jobs: build: name: Build - runs-on: macos-12 + runs-on: macos-13 steps: - name: Checkout the repo uses: actions/checkout@v2 - name: Set proper xcode version - uses: maxim-lobanov/setup-xcode@v1 - with: - xcode-version: '14.0' + run: sh ./scripts/xcodeselect.sh - name: Building run: ./scripts/build.sh \ No newline at end of file diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 7f7a7cc..6f93424 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -10,27 +10,19 @@ on: jobs: pod: name: Pod Lib Lint - runs-on: macos-12 + runs-on: macos-13 steps: - name: Checkout the repo uses: actions/checkout@v2 - name: Set proper xcode version - uses: maxim-lobanov/setup-xcode@v1 - with: - xcode-version: '14.0' - - name: Build the framework - run: ./scripts/build.sh + run: sh ./scripts/xcodeselect.sh - name: Lint run: pod lib lint --allow-warnings swift: name: Swift Lint - runs-on: macos-12 + runs-on: macos-13 steps: - name: Checkout the repo uses: actions/checkout@v2 - - name: Set proper xcode version - uses: maxim-lobanov/setup-xcode@v1 - with: - xcode-version: '14.0' - name: Lint run: swiftlint --strict \ No newline at end of file diff --git a/.gitignore b/.gitignore index f606274..7272d36 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,8 @@ Carthage/* */Pods/* +swiftlint + ## Build generated build/ DerivedData diff --git a/WultraPowerAuthNetworking.xcodeproj/project.pbxproj b/WultraPowerAuthNetworking.xcodeproj/project.pbxproj index 6884d9a..83eef7d 100644 --- a/WultraPowerAuthNetworking.xcodeproj/project.pbxproj +++ b/WultraPowerAuthNetworking.xcodeproj/project.pbxproj @@ -191,6 +191,7 @@ /* Begin PBXShellScriptBuildPhase section */ DC3EFA482774A55000C30F64 /* SwiftLint */ = { isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); @@ -205,7 +206,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "if ! [ -x \"$(command -v swiftlint)\" ]; then\n echo 'warning: swiftlint is not installed on this computer.' >&2\n exit 0\nfi\n\nswiftlint\n"; + shellScript = "\"${PROJECT_DIR}/scripts/swiftlint.sh\" \"-ne\"\n\n"; }; /* End PBXShellScriptBuildPhase section */ diff --git a/scripts/swiftlint.sh b/scripts/swiftlint.sh new file mode 100755 index 0000000..e6cfa47 --- /dev/null +++ b/scripts/swiftlint.sh @@ -0,0 +1,84 @@ +#!/bin/bash + +#set -x +set -e + +SWIFTLINT_VERSION="0.53.0" +NO_ERROR=false + +TOP=$(dirname $0) +PROJECT_HOME="${TOP}/.." +pushd "${PROJECT_HOME}" + +while [[ $# -gt 0 ]] +do + opt="$1" + case "$opt" in + -ne | --no-error) + NO_ERROR=true + ;; + esac + shift +done + +function download +{ + DOWNLOAD_FOLDER="swiftlintdownload" + pushd "${TOP}" + rm -rf "${DOWNLOAD_FOLDER}" + mkdir "${DOWNLOAD_FOLDER}" + pushd "${DOWNLOAD_FOLDER}" + curl -sSLO "https://github.com/realm/SwiftLint/releases/download/${SWIFTLINT_VERSION}/portable_swiftlint.zip" + unzip "portable_swiftlint.zip" -d . + cp "swiftlint" "./../.." + popd + rm -rf "${DOWNLOAD_FOLDER}" + popd + chmod +x swiftlint +} + +echo "" +echo "###################################################" +echo "Running swiftlint to verify code style." + +if [ ! -f "swiftlint" ]; then + echo " > downloading swiftlint ${SWIFTLINT_VERSION}..." + download +else + current=$(./swiftlint --version) + if [ "${SWIFTLINT_VERSION}" != "${current}" ]; then + + echo " > swiftlint ${current} already downloaded, but ${SWIFTLINT_VERSION} is required, removing and downloading." + rm "swiftlint" + download + + else + echo " > Using downloaded swiftlint v${SWIFTLINT_VERSION}." + fi +fi + +EXIT_CODE=0 +if [ $NO_ERROR == true ]; then + PARAM="" +else + PARAM="--strict" +fi +./swiftlint "${PARAM}" || EXIT_CODE=$? + +if [ $EXIT_CODE -eq 0 ]; then + echo " > No swiftlint errors 👍." +else + echo "" + echo " > ⚠️ There are swiftlint errors." + if [ $NO_ERROR == true ]; then + echo " > Build will continue but you need to fix swiftlint issue because otherwise build will fail on the CI." + EXIT_CODE=0 + else + echo " > Exiting with error - please fix the swiftlint issues." + EXIT_CODE=1 + fi +fi +echo "###################################################" +echo "" + +exit $EXIT_CODE \ No newline at end of file diff --git a/scripts/xcodeselect.sh b/scripts/xcodeselect.sh new file mode 100755 index 0000000..e2a8138 --- /dev/null +++ b/scripts/xcodeselect.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +set -e + +# Script used for selecting proper xcode for all builds on the CI (not appcenter). +# Available xcodes at https://github.com/actions/runner-images/blob/main/images/macos/macos-13-Readme.md#xcode + +sudo xcode-select -s "/Applications/Xcode_15.0.app" \ No newline at end of file From 4121bc543ba08c8091ba2fe594428da1e6ee2cc8 Mon Sep 17 00:00:00 2001 From: Jan Kobersky Date: Fri, 27 Oct 2023 17:02:25 +0200 Subject: [PATCH 5/6] Resolved #46: Added prepare-release script --- .limedeploy | 3 - .../WPNConstants.swift | 2 +- {Deploy => scripts/deploy}/Info.plist | 0 {Deploy => scripts/deploy}/WPNConstants.swift | 4 +- .../deploy}/WultraPowerAuthNetworking.podspec | 0 scripts/prepare-release.sh | 97 +++++++++++++++++++ 6 files changed, 100 insertions(+), 6 deletions(-) delete mode 100644 .limedeploy rename {Deploy => scripts/deploy}/Info.plist (100%) rename {Deploy => scripts/deploy}/WPNConstants.swift (86%) rename {Deploy => scripts/deploy}/WultraPowerAuthNetworking.podspec (100%) create mode 100755 scripts/prepare-release.sh diff --git a/.limedeploy b/.limedeploy deleted file mode 100644 index 45b27dd..0000000 --- a/.limedeploy +++ /dev/null @@ -1,3 +0,0 @@ -DEPLOY_POD_NAME='WultraPowerAuthNetworking' -DEPLOY_VERSIONING_FILES=( "Deploy/WultraPowerAuthNetworking.podspec,WultraPowerAuthNetworking.podspec" "Deploy/Info.plist,WultraPowerAuthNetworking.xcodeproj/WultraPowerAuthNetworking_Info.plist" "Deploy/WPNConstants.swift,Sources/WultraPowerauthNetworking/WPNConstants.swift") -DEPLOY_MODE='cocoapods' \ No newline at end of file diff --git a/Sources/WultraPowerauthNetworking/WPNConstants.swift b/Sources/WultraPowerauthNetworking/WPNConstants.swift index cfe5912..4ce9ad2 100644 --- a/Sources/WultraPowerauthNetworking/WPNConstants.swift +++ b/Sources/WultraPowerauthNetworking/WPNConstants.swift @@ -17,7 +17,7 @@ import Foundation // Note that this file is autogenerated during release process. -// If you will edit this file, you need to also edit "Deploy/Constants.swift" file +// If you will edit this file, you need to also edit "scripts/deploy/Constants.swift.tpl" file // inside the root folder. internal class WPNConstants { diff --git a/Deploy/Info.plist b/scripts/deploy/Info.plist similarity index 100% rename from Deploy/Info.plist rename to scripts/deploy/Info.plist diff --git a/Deploy/WPNConstants.swift b/scripts/deploy/WPNConstants.swift similarity index 86% rename from Deploy/WPNConstants.swift rename to scripts/deploy/WPNConstants.swift index c240962..7716ac7 100644 --- a/Deploy/WPNConstants.swift +++ b/scripts/deploy/WPNConstants.swift @@ -1,5 +1,5 @@ // -// Copyright 2022 Wultra s.r.o. +// Copyright 2023 Wultra s.r.o. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -17,7 +17,7 @@ import Foundation // Note that this file is autogenerated during release process. -// If you will edit this file, you need to also edit "Deploy/Constants.swift.tpl" file +// If you will edit this file, you need to also edit "scripts/deploy/Constants.swift.tpl" file // inside the root folder. internal class WPNConstants { diff --git a/Deploy/WultraPowerAuthNetworking.podspec b/scripts/deploy/WultraPowerAuthNetworking.podspec similarity index 100% rename from Deploy/WultraPowerAuthNetworking.podspec rename to scripts/deploy/WultraPowerAuthNetworking.podspec diff --git a/scripts/prepare-release.sh b/scripts/prepare-release.sh new file mode 100755 index 0000000..04bd421 --- /dev/null +++ b/scripts/prepare-release.sh @@ -0,0 +1,97 @@ +#!/bin/bash + +set -e # stop sript when error occures +set -u # stop when undefined variable is used + +############################################################################### +# This script prepares a release with provided version +# ---------------------------------------------------------------------------- + +TOP=$(dirname $0) +SRC_ROOT="`( cd \"$TOP/..\" && pwd )`" +DO_COMMIT=0 +DO_PUSH=0 +VERSION= +VERSIONING_FILES=( + "deploy/WultraPowerAuthNetworking.podspec,${SRC_ROOT}/WultraPowerAuthNetworking.podspec" + "deploy/Info.plist,${SRC_ROOT}/WultraPowerAuthNetworking.xcodeproj/WultraPowerAuthNetworking_Info.plist" + "deploy/WPNConstants.swift,${SRC_ROOT}/Sources/WultraPowerauthNetworking/WPNConstants.swift" +) + +function USAGE +{ + echo "" + echo "Usage: prepare-release.sh [options] version" + echo "" + echo "options are:" + echo "" + echo " -c | --commit commit changed files and create tag" + echo "" + echo " -p | --push push commits and tags" + echo "" + echo " -h | --help prints this help information" + echo "" + exit $1 +} + +while [[ $# -gt 0 ]] +do + opt="$1" + case "$opt" in + -c | --commit) + DO_COMMIT=1 + ;; + -h | --help) + USAGE 0 + ;; + -t | --tag) + DO_TAG=1 + ;; + *) + VERSION=$opt + ;; + esac + shift +done + +if [ -z "${VERSION}" ]; then + echo "You have to provide version string." + exit 1 +fi + +echo "Settings version to ${VERSION}." + +pushd $TOP + +for (( i=0; i<${#VERSIONING_FILES[@]}; i++ )); +do + patch_info="${VERSIONING_FILES[$i]}" + files=(${patch_info//,/ }) + template="${files[0]}" + target="${files[1]}" + if [ ! -f "$template" ]; then + echo "Template file not found: ${template}" + exit 1 + fi + if [ ! -f "$target" ]; then + echo "Target should exist: ${target}" + exit 1 + fi + + echo " + ${target}" + sed -e "s/%DEPLOY_VERSION%/$VERSION/g" "${template}" > "${target}" + if [ x$DO_COMMIT == x1 ]; then + git add "${target}" + fi +done + +popd + +if [ x$DO_COMMIT == x1 ]; then + git commit -m "Bumped version to ${VERSION}" + git tag "${VERSION}" +fi + +if [ x$DO_PUSH == x1 ]; then + git push --tags +fi From c88dda9def5180695a2e9bf6d81d081135713066 Mon Sep 17 00:00:00 2001 From: Jan Kobersky Date: Mon, 30 Oct 2023 11:03:59 +0100 Subject: [PATCH 6/6] Removed pods lint and upgraded xcode version --- .github/workflows/lint.yml | 10 ---------- scripts/prepare-release.sh | 15 +++++++++++++++ scripts/xcodeselect.sh | 2 +- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 6f93424..80ca374 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -8,16 +8,6 @@ on: pull_request: jobs: - pod: - name: Pod Lib Lint - runs-on: macos-13 - steps: - - name: Checkout the repo - uses: actions/checkout@v2 - - name: Set proper xcode version - run: sh ./scripts/xcodeselect.sh - - name: Lint - run: pod lib lint --allow-warnings swift: name: Swift Lint runs-on: macos-13 diff --git a/scripts/prepare-release.sh b/scripts/prepare-release.sh index 04bd421..f9c2958 100755 --- a/scripts/prepare-release.sh +++ b/scripts/prepare-release.sh @@ -11,6 +11,7 @@ TOP=$(dirname $0) SRC_ROOT="`( cd \"$TOP/..\" && pwd )`" DO_COMMIT=0 DO_PUSH=0 +DO_RELEASE=0 VERSION= VERSIONING_FILES=( "deploy/WultraPowerAuthNetworking.podspec,${SRC_ROOT}/WultraPowerAuthNetworking.podspec" @@ -29,6 +30,8 @@ function USAGE echo "" echo " -p | --push push commits and tags" echo "" + echo " -r | --release release to CocoaPods" + echo "" echo " -h | --help prints this help information" echo "" exit $1 @@ -47,6 +50,9 @@ do -t | --tag) DO_TAG=1 ;; + -r | --release) + DO_RELEASE=1 + ;; *) VERSION=$opt ;; @@ -87,6 +93,8 @@ done popd +pushd "${SRC_ROOT}" + if [ x$DO_COMMIT == x1 ]; then git commit -m "Bumped version to ${VERSION}" git tag "${VERSION}" @@ -95,3 +103,10 @@ fi if [ x$DO_PUSH == x1 ]; then git push --tags fi + +if [ x$DO_RELEASE == x1 ]; then + pod lib lint + pod trunk push +fi + +popd diff --git a/scripts/xcodeselect.sh b/scripts/xcodeselect.sh index e2a8138..09aa88e 100755 --- a/scripts/xcodeselect.sh +++ b/scripts/xcodeselect.sh @@ -5,4 +5,4 @@ set -e # Script used for selecting proper xcode for all builds on the CI (not appcenter). # Available xcodes at https://github.com/actions/runner-images/blob/main/images/macos/macos-13-Readme.md#xcode -sudo xcode-select -s "/Applications/Xcode_15.0.app" \ No newline at end of file +sudo xcode-select -s "/Applications/Xcode_15.0.1.app" \ No newline at end of file