From d17b2f4000d594d4ba2eea49fff332bec880c8de Mon Sep 17 00:00:00 2001 From: NachoSoto Date: Mon, 31 Jul 2023 11:31:44 +0200 Subject: [PATCH] `Paywalls`: SimpleApp reads API key from Xcode Cloud environment (#2919) This will allow us to automatically make new releases from the `paywalls` branch. See [docs](https://developer.apple.com/documentation/xcode/writing-custom-build-scripts). Screenshot 2023-07-30 at 10 55 47 --- .../SimpleApp/SimpleApp/Configuration.swift | 19 +++++++++++++++++++ .../SimpleApp/SimpleApp/SimpleApp.swift | 2 +- .../SimpleApp/ci_scripts/ci_pre_xcodebuild.sh | 14 ++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100755 Tests/TestingApps/SimpleApp/ci_scripts/ci_pre_xcodebuild.sh diff --git a/Tests/TestingApps/SimpleApp/SimpleApp/Configuration.swift b/Tests/TestingApps/SimpleApp/SimpleApp/Configuration.swift index 8381a6074e..fa85a2e067 100644 --- a/Tests/TestingApps/SimpleApp/SimpleApp/Configuration.swift +++ b/Tests/TestingApps/SimpleApp/SimpleApp/Configuration.swift @@ -18,3 +18,22 @@ enum Configuration { static let entitlement = "pro" } + +extension Configuration { + + static var effectiveApiKey: String = { + return Self.apiKey.nonEmpty ?? Self.apiKeyFromCI + }() + + // This is modified by CI: + private static let apiKeyFromCI = "" + +} + +// MARK: - Extensions + +private extension String { + + var nonEmpty: String? { return self.isEmpty ? nil : self } + +} diff --git a/Tests/TestingApps/SimpleApp/SimpleApp/SimpleApp.swift b/Tests/TestingApps/SimpleApp/SimpleApp/SimpleApp.swift index 306341f881..3f9dc0e12e 100644 --- a/Tests/TestingApps/SimpleApp/SimpleApp/SimpleApp.swift +++ b/Tests/TestingApps/SimpleApp/SimpleApp/SimpleApp.swift @@ -19,7 +19,7 @@ struct SimpleApp: App { : URL(string: Configuration.proxyURL)! Purchases.configure( - with: .init(withAPIKey: Configuration.apiKey) + with: .init(withAPIKey: Configuration.effectiveApiKey) .with(usesStoreKit2IfAvailable: true) ) } diff --git a/Tests/TestingApps/SimpleApp/ci_scripts/ci_pre_xcodebuild.sh b/Tests/TestingApps/SimpleApp/ci_scripts/ci_pre_xcodebuild.sh new file mode 100755 index 0000000000..f6ed7568fb --- /dev/null +++ b/Tests/TestingApps/SimpleApp/ci_scripts/ci_pre_xcodebuild.sh @@ -0,0 +1,14 @@ +#!/bin/bash -e + +SIMPLE_APP_API_KEY=$REVENUECAT_XCODE_CLOUD_SIMPLE_APP_API_KEY +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +if [ -z "$SIMPLE_APP_API_KEY" ]; then + echo "SimpleApp API key environment variable is not set." +else + echo "Replacing API key on SimpleApp" + + file="$SCRIPT_DIR/../SimpleApp/Configuration.swift" + sed -i.bak 's/private static let apiKeyFromCI = ""/private static let apiKeyFromCI = "'$SIMPLE_APP_API_KEY'"/g' $file + rm $file.bak +fi