-
Notifications
You must be signed in to change notification settings - Fork 120
Add action to fetch latest version and build number #186
Conversation
…nter_build_number' plugin
jp-andre
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi! Thanks so much for contributing this PR!
It's really great to see a plugin author take interest in merging functionality directly into our plugin.
I've left a few comments in the code.
As for short_version it would be great to include it in this PR. How about returning an object that contains { version, build_number }? Note that the upload action uses version and build_number that somehow match the upload API call, but the release GET calls return version and short_version. For reference we have this conversion code in the upload action:
params[:version] = release['short_version']
params[:build_number] = release['version']
Suggestions:
- Should we also include the release ID?
- Should the upload action return the same values as this function?
Do the requested changes make sense to you?
|
|
||
| # Checks that the app name is valid | ||
| def self.check_valid_name(name) | ||
| regexp = /^[a-zA-Z0-9\-]+$/i |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this regex is not entirely correct. We can create app names with . (dot) and _ (underscore). I'm not 100% sure if any other character is possible. Also note that the trailing i (for case insensitiveness) is redundant with a-zA-Z :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the regex in the model: /^[a-zA-Z0-9-_.]+$/
|
|
||
| unless app_name.nil? | ||
| unless Helper::AppcenterHelper.check_valid_name(app_name) | ||
| UI.user_error!("The `app_name` ('#{app_name}') cannot contains spaces and must only contain alpha numeric characters and dashes") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the name is invalid, I would print a warning but not fail immediately. See my other comment about check_valid_name. In the end, if the HTTP calls pass, it means the name was valid :)
You might want to use optional_error for that (as seen in the upload action).
We probably can also mention in this warning message that the app_name is what appears in the app URL.
| return nil | ||
| end | ||
|
|
||
| host_uri = URI.parse('https://api.appcenter.ms') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These HTTP calls should be moved to the helper class, and use the same patterns, if possible.
|
|
||
| def self.get_owner_and_app_name(api_token) | ||
| apps = get_apps(api_token) | ||
| app_matches = prompt_for_apps(apps) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There can be only a single value here, right?
|
|
||
| def self.prompt_for_apps(apps) | ||
| app_names = apps.map { |app| app['name'] }.sort | ||
| selected_app_name = UI.select("Select your project: ", app_names) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the behavior in non-interactive mode? We should require both owner_name and app_name to be set in that case.
| owner_name = get_owner_name(api_token, app_name) | ||
| else | ||
| unless Helper::AppcenterHelper.check_valid_name(owner_name) | ||
| UI.user_error!("The `owner_name` ('#{owner_name}') cannot contains spaces and must only contain lowercased alpha numeric characters and dashes") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment.
| api_token = params[:api_token] | ||
| app_name = params[:app_name] | ||
| owner_name = params[:owner_name] | ||
| if app_name.nil? && owner_name.nil? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this case should not be allowed if we're running non-interactively (eg. CI build).
lib/fastlane/plugin/appcenter/actions/appcenter_fetch_version_number.rb
Outdated
Show resolved
Hide resolved
|
Thanks @jp-andre! Just taking a look through your review, but at a glance I think it all makes sense. I might remove the valid name check altogether for the time-being - it could always be re-added across all actions in this plugin if that's something that you and the team think would be useful. What do you think? I'm thinking perhaps the object returned could be are you thinking that the object would be |
Sounds good, feel free to adjust or remove as you prefer. (Note that
I believe Android's I don't know any case where we build and return a "full version" string as you mentioned. But if it's happening, I'd love to know and look into it. Apart from these comments, could you amend the README as well to add a mention to this new action? |
|
Thanks @jp-andre
I primarily work with iOS apps and have always found Personally, I’d prefer it if the API returned what you described, but I have a feeling this is a limitation based on the way Apple handles version numbers. I’d be happy to share an example via a private channel, if that helps. Edit: I suppose it doesn’t matter too much, just so long as |
This sounds about right. Each value should correspond to exactly one entry in the build configuration files. The rest is just Apple's convention. :) |
|
Hi @jp-andre - I've made the changes suggested. Changes since your last review in summary:
Looking forward to hearing back from you soon! |
jp-andre
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks really good. I'll get a second opinion from my team mates, but for me it's all good.
lib/fastlane/plugin/appcenter/actions/appcenter_fetch_version_number.rb
Outdated
Show resolved
Hide resolved
lib/fastlane/plugin/appcenter/actions/appcenter_fetch_version_number.rb
Outdated
Show resolved
Hide resolved
lib/fastlane/plugin/appcenter/actions/appcenter_fetch_version_number.rb
Outdated
Show resolved
Hide resolved
anywherepilot
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excuse the comment spam. This looks good to me!
…dating messaging in error to make this clearer
|
Thanks @jp-andre and @anywherepilot for your reviews and helpful comments! I've addressed all the remaining comments I think. |
Fixes #149
This PR adds the Fastlane actions
appcenter_fetch_version_numberto fetch the latest version number for a given app, which is returned as a string in the formatmajor.minor.patch.build.The action uses the App Center API to list releases, which is one of the 'distribute' endpoints. It uses the value received from the
'version'key, though I'd be interested to see if there's an appetite to provide an action/parameter to provide the value for'short_version'.Usage
This action can be used simply by calling
appcenter_fetch_version_number, which returns the version number as a string. For example, if your Fastfile looked like thisthen provided the environment variable
APPCENTER_API_TOKENis set, the user will be prompted to choose their app from a list (if there is more than 1) when running this lane. If it's not set, thenapi_tokenshould be passed as a parameter.For CI and other non-interactive use cases, the app name should be specified as a minimum, however specifying the owner name too saves on an API call:
What about
latest_appcenter_build_number?To be clear, the functionality contained in this PR is identical to what currently exists in the
fastlane-plugin-latest_appcenter_build_numberplugin. If this PR is acceptable and the action within it are merged into this repository, I will put a notice in the README and a command-line-warning asking users to adopt this as the official App Center plugin and make it clear that additional features and bug fixes will only be addressed in releases from this repository.