Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paywalls: SimpleApp reads API key from Xcode Cloud environment #2919

Merged
merged 3 commits into from
Jul 31, 2023
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
19 changes: 19 additions & 0 deletions Tests/TestingApps/SimpleApp/SimpleApp/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

}
2 changes: 1 addition & 1 deletion Tests/TestingApps/SimpleApp/SimpleApp/SimpleApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
}
Expand Down
14 changes: 14 additions & 0 deletions Tests/TestingApps/SimpleApp/ci_scripts/ci_pre_xcodebuild.sh
Original file line number Diff line number Diff line change
@@ -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