Skip to content

Commit

Permalink
Paywalls: SimpleApp reads API key from Xcode Cloud environment (#2919)
Browse files Browse the repository at this point in the history
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).

<img width="553" alt="Screenshot 2023-07-30 at 10 55 47"
src="https://github.com/RevenueCat/purchases-ios/assets/685609/d40a00e7-6a57-4340-8160-d903d765b814">
  • Loading branch information
NachoSoto committed Sep 6, 2023
1 parent 54d9776 commit 8acda08
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
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

0 comments on commit 8acda08

Please sign in to comment.