diff --git a/.circleci/config.yml b/.circleci/config.yml index e5e3539d40..37fd591210 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -13,6 +13,9 @@ parameters: generate_snapshots: default: false type: boolean + generate_revenuecatui_snapshots: + default: false + type: boolean aliases: base-job: &base-job @@ -23,7 +26,8 @@ aliases: xcode_version: type: string environment: - CIRCLECI_TESTS_GENERATE_SNAPSHOTS: << pipeline.parameters.generate_snapshots >> + CIRCLECI_TESTS_GENERATE_SNAPSHOTS: << pipeline.parameters.generate_snapshots >> + CIRCLECI_TESTS_GENERATE_REVENUECAT_UI_SNAPSHOTS: << pipeline.parameters.generate_revenuecatui_snapshots >> working_directory: ~/purchases-ios shell: /bin/bash --login -o pipefail release-branches: &release-branches @@ -343,6 +347,12 @@ jobs: no_output_timeout: 5m environment: SCAN_DEVICE: iPhone 13,OS=15.5 + - when: + condition: << pipeline.parameters.generate_revenuecatui_snapshots >> + steps: + - run: + name: Run create_snapshot_pr + command: bundle exec fastlane create_snapshot_pr version:"revenuecatui-15" - compress_result_bundle: directory: fastlane/test_output bundle_name: revenuecatui @@ -367,6 +377,12 @@ jobs: no_output_timeout: 5m environment: SCAN_DEVICE: iPhone 14,OS=16.4 + - when: + condition: << pipeline.parameters.generate_revenuecatui_snapshots >> + steps: + - run: + name: Run create_snapshot_pr + command: bundle exec fastlane create_snapshot_pr version:"revenuecatui-16" - compress_result_bundle: directory: fastlane/test_output bundle_name: revenuecatui @@ -390,6 +406,12 @@ jobs: no_output_timeout: 15m environment: SCAN_DEVICE: iPhone 14 Pro,OS=17.0 + - when: + condition: << pipeline.parameters.generate_revenuecatui_snapshots >> + steps: + - run: + name: Run create_snapshot_pr + command: bundle exec fastlane create_snapshot_pr version:"revenuecatui-17" - compress_result_bundle: directory: fastlane/test_output bundle_name: revenuecatui @@ -958,12 +980,24 @@ workflows: - run-test-ios-12: # Simulator fails to install on Xcode 14 xcode_version: '13.4.1' + + generate_revenuecatui_snapshots: + when: << pipeline.parameters.generate_revenuecatui_snapshots >> + jobs: + - spm-revenuecat-ui-ios-15: + xcode_version: '14.3.0' + - spm-revenuecat-ui-ios-16: + xcode_version: '14.3.0' + - spm-revenuecat-ui-ios-17: + xcode_version: '15.0.0' + build-test: when: and: - not: equal: [ scheduled_pipeline, << pipeline.trigger_source >> ] - not: << pipeline.parameters.generate_snapshots >> + - not: << pipeline.parameters.generate_revenuecatui_snapshots >> jobs: - lint: xcode_version: '14.3.0' diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/RevenueCatUI.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/RevenueCatUI.xcscheme index bd9124ed8e..df82aa47c5 100644 --- a/.swiftpm/xcode/xcshareddata/xcschemes/RevenueCatUI.xcscheme +++ b/.swiftpm/xcode/xcshareddata/xcschemes/RevenueCatUI.xcscheme @@ -26,8 +26,19 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - shouldUseLaunchSchemeArgsEnv = "YES" - shouldAutocreateTestPlan = "YES"> + shouldUseLaunchSchemeArgsEnv = "YES"> + + + + + + + + diff --git a/Tests/RevenueCatUITests/Helpers/TestCase.swift b/Tests/RevenueCatUITests/Helpers/TestCase.swift index 806c222422..4784f39491 100644 --- a/Tests/RevenueCatUITests/Helpers/TestCase.swift +++ b/Tests/RevenueCatUITests/Helpers/TestCase.swift @@ -47,7 +47,7 @@ private enum SnapshotTests { static func updateSnapshotsIfNeeded() { guard !Self.environmentVariableChecked else { return } - if ProcessInfo.processInfo.environment["CIRCLECI_TESTS_GENERATE_SNAPSHOTS"] == "1" { + if ProcessInfo.processInfo.environment["CIRCLECI_TESTS_GENERATE_REVENUECAT_UI_SNAPSHOTS"] == "1" { isRecording = true } } diff --git a/Tests/RevenueCatUITests/TestPlans/CI-RevenueCatUI.xctestplan b/Tests/RevenueCatUITests/TestPlans/CI-RevenueCatUI.xctestplan new file mode 100644 index 0000000000..5c093d4aba --- /dev/null +++ b/Tests/RevenueCatUITests/TestPlans/CI-RevenueCatUI.xctestplan @@ -0,0 +1,28 @@ +{ + "configurations" : [ + { + "id" : "9A1CEA19-F9E9-4C9C-9FC8-6F9A5B29F2AE", + "name" : "Test Scheme Action", + "options" : { + + } + } + ], + "defaultOptions" : { + "codeCoverage" : false, + "maximumTestExecutionTimeAllowance" : 180, + "maximumTestRepetitions" : 3, + "testRepetitionMode" : "retryOnFailure", + "testTimeoutsEnabled" : true + }, + "testTargets" : [ + { + "target" : { + "containerPath" : "container:", + "identifier" : "RevenueCatUITests", + "name" : "RevenueCatUITests" + } + } + ], + "version" : 1 +} diff --git a/Tests/RevenueCatUITests/TestPlans/CI-Snapshots.xctestplan b/Tests/RevenueCatUITests/TestPlans/CI-Snapshots.xctestplan new file mode 100644 index 0000000000..6aef6d5557 --- /dev/null +++ b/Tests/RevenueCatUITests/TestPlans/CI-Snapshots.xctestplan @@ -0,0 +1,33 @@ +{ + "configurations" : [ + { + "id" : "9A1CEA19-F9E9-4C9C-9FC8-6F9A5B29F2AE", + "name" : "Test Scheme Action", + "options" : { + + } + } + ], + "defaultOptions" : { + "codeCoverage" : false, + "environmentVariableEntries" : [ + { + "key" : "CIRCLECI_TESTS_GENERATE_REVENUECAT_UI_SNAPSHOTS", + "value" : "1" + } + ], + "maximumTestExecutionTimeAllowance" : 180, + "testExecutionOrdering" : "random", + "testTimeoutsEnabled" : true + }, + "testTargets" : [ + { + "target" : { + "containerPath" : "container:", + "identifier" : "RevenueCatUITests", + "name" : "RevenueCatUITests" + } + } + ], + "version" : 1 +} diff --git a/Tests/RevenueCatUITests/TestPlans/RevenueCatUI.xctestplan b/Tests/RevenueCatUITests/TestPlans/RevenueCatUI.xctestplan new file mode 100644 index 0000000000..5b748bc5a2 --- /dev/null +++ b/Tests/RevenueCatUITests/TestPlans/RevenueCatUI.xctestplan @@ -0,0 +1,26 @@ +{ + "configurations" : [ + { + "id" : "9A1CEA19-F9E9-4C9C-9FC8-6F9A5B29F2AE", + "name" : "Test Scheme Action", + "options" : { + + } + } + ], + "defaultOptions" : { + "codeCoverage" : false, + "maximumTestExecutionTimeAllowance" : 180, + "testTimeoutsEnabled" : true + }, + "testTargets" : [ + { + "target" : { + "containerPath" : "container:", + "identifier" : "RevenueCatUITests", + "name" : "RevenueCatUITests" + } + } + ], + "version" : 1 +} diff --git a/fastlane/Fastfile b/fastlane/Fastfile index 43c2b28420..188d6bb216 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -177,19 +177,26 @@ platform :ios do desc "Runs all RevenueCatUI tests" lane :test_revenuecatui do |options| - # See https://forums.swift.org/t/i-made-a-little-spm-package-that-uses-uikit-how-can-i-run-tests-from-command-line/50399/2 - xcodebuild( - workspace: '.', - scheme: 'RevenueCatUI', - destination: "platform=iOS Simulator,name=" + (ENV['SCAN_DEVICE'] || "iPhone 14,OS=16.4"), - sdk: 'iphonesimulator', - output_style: :basic, - result_bundle_path: 'fastlane/test_output/revenuecatui.xcresult', - report_formats: [:junit], - report_path: 'fastlane/test_output/revenuecatui/tests.xml', - test: true, - xcargs: "-test-iterations 3 -retry-tests-on-failure" - ) + generate_snapshots = ENV["CIRCLECI_TESTS_GENERATE_REVENUECAT_UI_SNAPSHOTS"] == "true" + + begin + # See https://forums.swift.org/t/i-made-a-little-spm-package-that-uses-uikit-how-can-i-run-tests-from-command-line/50399/2 + xcodebuild( + workspace: '.', + scheme: 'RevenueCatUI', + destination: "platform=iOS Simulator,name=" + (ENV['SCAN_DEVICE'] || "iPhone 14,OS=16.4"), + sdk: 'iphonesimulator', + output_style: :basic, + result_bundle_path: 'fastlane/test_output/revenuecatui.xcresult', + report_formats: [:junit], + report_path: 'fastlane/test_output/revenuecatui/tests.xml', + test: true, + xcargs: generate_snapshots ? "-testPlan CI-Snapshots" : "-testPlan CI-RevenueCatUI" + ) + rescue => e + # Equivalent to `fail_build: !generate_snapshots` + raise e if !generate_snapshots + end end desc "Release checks" @@ -372,8 +379,21 @@ platform :ios do end end - desc "Trigger CircleCI job to generate snapshots" - lane :generate_snapshots do + desc "Trigger CircleCI job to generate snapshots for RevenueCat" + lane :generate_snapshots_RC do + generate_snapshots( + pipeline: "generate_snapshots" + ) + end + + desc "Trigger CircleCI job to generate snapshots for RevenueCatUI" + lane :generate_snapshots_RCUI do + generate_snapshots( + pipeline: "generate_revenuecatui_snapshots" + ) + end + + private_lane :generate_snapshots do |options| require 'rest-client' # Prompt branch @@ -387,7 +407,7 @@ platform :ios do # Make request headers = {"Circle-Token": circle_token, "Content-Type": "application/json", "Accept": "application/json"} - data = {parameters: {generate_snapshots: true}, branch: branch} + data = {parameters: {options[:pipeline] => true}, branch: branch} url = "https://circleci.com/api/v2/project/github/RevenueCat/purchases-ios/pipeline" resp = RestClient.post url, data.to_json, headers @@ -409,7 +429,7 @@ platform :ios do branch_name = "generated_snapshots/#{base_branch}-#{build_number}-#{version}" sh("git", "checkout", "-b", branch_name) - sh("git", "add", "../Tests") + sh("git", "add", "../*/__Snapshots__/*") file_count = sh("git diff --cached --numstat | wc -l").strip.to_i if file_count == 0 diff --git a/fastlane/README.md b/fastlane/README.md index 73e5cf9525..8584c1d5b3 100644 --- a/fastlane/README.md +++ b/fastlane/README.md @@ -218,13 +218,21 @@ Release to CocoaPods Tag current branch with current version number -### ios generate_snapshots +### ios generate_snapshots_RC ```sh -[bundle exec] fastlane ios generate_snapshots +[bundle exec] fastlane ios generate_snapshots_RC ``` -Trigger CircleCI job to generate snapshots +Trigger CircleCI job to generate snapshots for RevenueCat + +### ios generate_snapshots_RCUI + +```sh +[bundle exec] fastlane ios generate_snapshots_RCUI +``` + +Trigger CircleCI job to generate snapshots for RevenueCatUI ### ios create_snapshot_pr