-
Notifications
You must be signed in to change notification settings - Fork 9
Add android_generate_apk_from_aab
action
#467
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
Conversation
...ugin/wpmreleasetoolkit/actions/bundletool/bundletool_generate_universal_signed_apk_action.rb
Outdated
Show resolved
Hide resolved
ebbaa84
to
a3f5960
Compare
…ot a release branch'
a3f5960
to
5a54afc
Compare
...ugin/wpmreleasetoolkit/actions/bundletool/bundletool_generate_universal_signed_apk_action.rb
Outdated
Show resolved
Hide resolved
...ugin/wpmreleasetoolkit/actions/bundletool/bundletool_generate_universal_signed_apk_action.rb
Outdated
Show resolved
Hide resolved
...ugin/wpmreleasetoolkit/actions/bundletool/bundletool_generate_universal_signed_apk_action.rb
Outdated
Show resolved
Hide resolved
...ugin/wpmreleasetoolkit/actions/bundletool/bundletool_generate_universal_signed_apk_action.rb
Outdated
Show resolved
Hide resolved
...ugin/wpmreleasetoolkit/actions/bundletool/bundletool_generate_universal_signed_apk_action.rb
Outdated
Show resolved
Hide resolved
...ugin/wpmreleasetoolkit/actions/bundletool/bundletool_generate_universal_signed_apk_action.rb
Outdated
Show resolved
Hide resolved
...ugin/wpmreleasetoolkit/actions/bundletool/bundletool_generate_universal_signed_apk_action.rb
Outdated
Show resolved
Hide resolved
a57a910
to
7762101
Compare
686edc0
to
19930ed
Compare
19930ed
to
515832d
Compare
bundletool_generate_universal_signed_apk
actionandroid_generate_apk_from_aab
action
515832d
to
f99c55e
Compare
lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_generate_apk_from_aab.rb
Outdated
Show resolved
Hide resolved
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.
Your implementation is not resilient to paths with spaces and special characters, and spawns a shell interpreter for little benefit, instead of using sh('bundletool', 'arg1', 'arg2')
pre-parsed syntax.
Besides, your logic with mv
can lead to unwanted destructive action if the caller passes a path to a destination folder instead of a path to the APK.
I've suggested an alternate implementation below. If you adopt it, you'll have to adjust your unit tests accordingly too; I'd suggest you to add some more unit tests as well, to validate various combinations of parameters (like if the user is passing the keystore_path
but not the other keystore parameters, or if we provide paths with spaces or $
characters in them, test error handling, etc)
Left some other suggestions to improve the code here and there, feel free to review them.
lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_generate_apk_from_aab.rb
Outdated
Show resolved
Hide resolved
lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_generate_apk_from_aab.rb
Outdated
Show resolved
Hide resolved
lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_generate_apk_from_aab.rb
Outdated
Show resolved
Hide resolved
lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_generate_apk_from_aab.rb
Outdated
Show resolved
Hide resolved
lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_generate_apk_from_aab.rb
Outdated
Show resolved
Hide resolved
lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_generate_apk_from_aab.rb
Show resolved
Hide resolved
type: String, | ||
optional: false, | ||
default_value: 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.
Now that we decided to not create intermediate folders if they don't exist, we should add a check to ensure the parent dir exists. Otherwise we'd still have the action run bundletool
but only fail afterwards while trying to move the file to the destination, instead of failing early.
), | |
verify_block: proc { |p| UI.user_error!('The parent folder for the destination does not exist. Please create it first.') unless p.nil? || File.directory?(File.dirname(p)) } | |
), |
lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_generate_apk_from_aab.rb
Outdated
Show resolved
Hide resolved
This new implementation fixes the following issues that we had in the old implementation: - Issues and security risk with paths containing spaces or special parameters - This would not only have made the command fail - But it also created a security issue for parameter injection (e.g. `apk_output_file_path: 'foo --inject this && echo print the rest'`) - Risk of deleting any arbitrary folder on disk (due to use of unchecked `rm -rf`) - Calling the action with `apk_output_file_path: '.'` for example (or a path to any directory) would have the side effect of… deleting the whole content of the current directory before failing - This was even more problematic that this could be an easy genuine accidental error to make—especially if the caller misread the documentation and thought that the command accepted a folder for the output path instead of the path to the apk file. In addition, this commit adds the following features to the action's behavior: - The action will detect if the parent directory of the `apk_output_file_path` does not exist, and exit early with a nice error if so - We now allow `apk_output_file_path` to be a directory, and if so the output file will be put in that directory and use the same basename as the input aab_file_path (but with `.apk` extension instead of `.aab`) - The action now returns the path to the generated file (which is especially useful if you didn't provide an explicit value for `apk_output_file_path` and let the action infer it, or if you provided a directory for this output path)
Group the code related to parsing the `apk_output_file_path` parameter together
@rynaardb GitHub doesn't let me add you as reviewer for the PR (likely because you're the PR author and GitHub doesn't allow authors to review and approve their own PRs, I guess), but feel free to review my latest changes addressing what we discussed. |
As discussed in Slack, I've ended up taking over Rynaard and fixing the issues raised above myself, so the changes I requested are now all addressed (but just dismissing my review instead of approving the PR, because it doesn't seem fair to self-approve my own changes)
e177697
to
2d499f9
Compare
@AliSoftware looks good. Once you approve the PR, I'll get it merged, or feel free also to do it. |
@AliSoftware I've marked the PR as |
Good catch. Idea (not checked): could the reason for the failure be that |
So here's the thing, it does actually finds the path when you run root@buildkite-android-builder-66998c988b-4hnfl:/# command -v bundletool
/usr/local/bin/bundletool But for some reason, the check reports something else. I've already spent a good amount of time looking at the build agents to ensure we haven't misconfigured something. And so far as I can tell, everything looks fine to me. |
Mmmmh… confusing 🤔 Trying to think of something but the only think I could think of would be if the shell context could be different when running
One way of checking that this is due to different context could be to create a dummy lane that runs Note: the fact that when I used a similar logic to test the presence of |
What does it do?
Adds a new
android_generate_apk_from_aab
action to generate an APK from a given AAB.This action can be useful in cases where you already have an AAB and just need the APK from it without having to build the APK from the source.
Checklist before requesting a review
bundle exec rubocop
to test for code style violations and recommendationsspecs/*_spec.rb
) if applicablebundle exec rspec
to run the whole test suite and ensure all your tests passCHANGELOG.md
file to describe your changes under the approprioate existing###
subsection of the existing## Trunk
section.