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

Use RC API key for local development from local.xcconfig #4795

Merged
merged 6 commits into from
Feb 19, 2025

Conversation

ajpallares
Copy link
Member

Motivation

When using the testing apps for developing the SDK, we usually need to add our own RevenueCat API key and/or Proxy URL. However, before this PR:

  • Each testing app had a different place where the API key and Proxy URL needed to be added
  • We often committed, by mistake, the changes that contained the API keys, which was not critical, but still undesired

Description

This PR addresses the two pain points mentioned above when setting an API key for local development (or Proxy URL):

  • Centralizes the place where the RevenueCat API key and Proxy URL are set for local development in the local.xcconfig file
  • Because the local.xcconfig file is ignored by git in this repo, we can finally stop worrying about committing the API key by mistake

Notes

  • The implementation for this relies on adding the local API key and Proxy URL to the info.plist of the projects, to make them available for the code to access.
  • The CI for PaywallsTester app still relies on the existing implementation of replacing the value of the apiKey String in ConfigItem.swift

@ajpallares ajpallares requested review from a team and aboedo February 18, 2025 12:16
Copy link
Member

@JayShortway JayShortway left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yessss omg thank you! This was one of my main motivations for adding the Local.xcconfig file, but I hadn't gotten around to it yet. ❤️

I have some suggestions to take it even further haha.

@@ -38,7 +38,6 @@ verify_no_included_apikeys() {
"${SCRIPT_DIR}/../Examples/MagicWeather/MagicWeather/Constants.swift"
"${SCRIPT_DIR}/../Examples/MagicWeatherSwiftUI/Shared/Constants.swift"
"${SCRIPT_DIR}/../Tests/TestingApps/PurchaseTesterSwiftUI/Core/Constants.swift"
"${SCRIPT_DIR}/../Tests/TestingApps/PaywallsTester/PaywallsTester/Config/LocalConfigItems.swift"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not get rid of all of these files, so we can get rid of the entire verify_no_included_apikeys() check?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well I see the utility of having then in the sense that someone might forget about the local.xcconfig file thing and perhaps wants to do a quick change of the API key and they do it in the code directly. So it does not harm. That said, by that argument, I'd need to add the ConfigItem.swift file to it 😄

Comment on lines +10 to +11
// DO NOT MODIFY THIS FILE.
// CI system adds the API key here.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about removing this file and making the CI script create a Local.xcconfig file instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, this file is still needed for the PaywallsTester app. I mean, not needed per se, but it's good to have a centralized place where we get the necessary variables from the info.plist.

Regarding having the CI script create a Local.xcconfig, I think that could totally work, yes. I'll open a separate PR for the CI changes related to this one 👍

@@ -1,31 +0,0 @@
//
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This comment has nothing to do with the line it's attached to 😅)

We also have a :replace_api_key_integration_tests Fastlane lane. We could refactor that to write values to Local.xcconfig as well, instead of to the various files listed in that lane. Just a suggestion and definitely not a blocker for this PR, as that is not really a pain point for local development.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. But it would definitely be much cleaner. I'll do this in a separate PR for CI-related stuff. Thank you for the suggestions!!!

@aboedo
Copy link
Member

aboedo commented Feb 18, 2025

YESSS

@ajpallares
Copy link
Member Author

Related PR, but for Examples apps --> #4796

@ajpallares ajpallares requested a review from a team February 18, 2025 17:26
Copy link
Contributor

@tonidero tonidero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! 🫶

@ajpallares ajpallares merged commit af30b55 into main Feb 19, 2025
10 checks passed
@ajpallares ajpallares deleted the api-key-in-local-config branch February 19, 2025 08:48
struct ConfigItem: AvailableConfigItems {
// DO NOT MODIFY THIS FILE.
// CI system adds the API key here.
struct ConfigItem {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Suggested change
struct ConfigItem {
enum ConfigItem {

Copy link
Contributor

@facumenzella facumenzella left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lovely

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants