-
Notifications
You must be signed in to change notification settings - Fork 9
Promo screenshots action refinements #685
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
Promo screenshots action refinements #685
Conversation
Otherwise, every hit (and there are many) of the method would print the path in the logs. Example: ``` [20:09:25]: ------------------------------- [20:09:25]: --- Step: promo_screenshots --- [20:09:25]: ------------------------------- [20:09:25]: Creating Promo Screenshots /opt/homebrew/bin/drawText [20:09:25]: ✅ Original Screenshot Source: /Users/gio/Developer/a8c/wcios/fastlane/screenshots /opt/homebrew/bin/drawText [20:09:25]: ✅ Translation source: /Users/gio/Developer/a8c/wcios/fastlane/metadata /opt/homebrew/bin/drawText /opt/homebrew/bin/drawText [20:09:26]: ▸ ✅ Font "Helvetica Neue" found and active /opt/homebrew/bin/drawText /opt/homebrew/bin/drawText /opt/homebrew/bin/drawText /opt/homebrew/bin/drawText /opt/homebrew/bin/drawText /opt/homebrew/bin/drawText [20:09:26]: ✅ Output Folder: /Users/gio/Developer/a8c/wcios/fastlane/promo_screenshots /opt/homebrew/bin/drawText [20:09:26]: 💙 Creating Promo Screenshots for: ar-SA, de-DE, en-US [20:09:26]: Do you want to overwrite the existing promo screenshots? (y/n) y /opt/homebrew/bin/drawText /opt/homebrew/bin/drawText /opt/homebrew/bin/drawText /opt/homebrew/bin/drawText /opt/homebrew/bin/drawText /opt/homebrew/bin/drawText /opt/homebrew/bin/drawText /opt/homebrew/bin/drawText /opt/homebrew/bin/drawText /opt/homebrew/bin/drawText /opt/homebrew/bin/drawText /opt/homebrew/bin/drawText /opt/homebrew/bin/drawText /opt/homebrew/bin/drawText /opt/homebrew/bin/drawText /opt/homebrew/bin/drawText /opt/homebrew/bin/drawText /opt/homebrew/bin/drawText /opt/homebrew/bin/drawText /opt/homebrew/bin/drawText /opt/homebrew/bin/drawText /opt/homebrew/bin/drawText /opt/homebrew/bin/drawText /opt/homebrew/bin/drawText /opt/homebrew/bin/drawText /opt/homebrew/bin/drawText /opt/homebrew/bin/drawText /opt/homebrew/bin/drawText /opt/homebrew/bin/drawText /opt/homebrew/bin/drawText /opt/homebrew/bin/drawText /opt/homebrew/bin/drawText /opt/homebrew/bin/drawText /opt/homebrew/bin/drawText /opt/homebrew/bin/drawText /opt/homebrew/bin/drawText /opt/homebrew/bin/drawText /opt/homebrew/bin/drawText /opt/homebrew/bin/drawText /opt/homebrew/bin/drawText /Users/gio/Developer/a8c/wcios/vendor/bundle/ruby/3.2.0/gems/fastlane-plugin-wpmreleasetoolkit-13.8.1/lib/fastlane/plugin/wpmreleasetoolkit/helper/promo_screenshots_helper.rb:410: warning: passing a block without an image argument is deprecated ... ```
Felt pretty dumb when I looked in the screenshots folder and realized that it was empty because, duh, I didn't run the automation.
See how rmagick/rmagick#1279 addressed the same issue.
Doing so prevents printing the long `drawText` message and making the logs noisy. I tried using `command:` and `log: false` to silence that (as per fastlane/fastlane#14945) but it didn't work.
| end | ||
|
|
||
| UI.user_error!('`drawText` not found – install it using `brew install automattic/build-tools/drawText`.') unless system('command -v drawText') | ||
| UI.user_error!('`drawText` not found – install it using `brew install automattic/build-tools/drawText`.') unless system('command -v drawText > /dev/null') |
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.
Otherwise, we'd get a long list of command -v drawText output.
As a side note, this line seems to be called many times. We should cache, memoize, or otherwise implement a way to run this check only once.
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.
So I guess we should consider something like:
UI.user_error!('`drawText` not found – install it using `brew install automattic/build-tools/drawText`.') unless self.drawText_available?And then:
def self.drawText_available?
@drawText_available ||= system('command -v drawText')
end
lib/fastlane/plugin/wpmreleasetoolkit/helper/promo_screenshots_helper.rb
Show resolved
Hide resolved
| Image.new(width, height) do | ||
| self.background_color = working_background | ||
| Image.new(width, height) do |info| | ||
| info.background_color = working_background | ||
| end | ||
| end |
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 addresses a deprecation warning. See commit message for more details.
| message = <<~MESSAGE | ||
| Unable to locate #{path}. | ||
| Did you run the automation to generate the screenshots? |
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.
Just in case I go through the same process of pondering why annotating non existing screenshots fails again.
| Did you run the automation to generate the screenshots? | ||
| MESSAGE | ||
| UI.user_error!(message) |
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.
Used user_error! instead of crash! because it makes less noise in the logs as it doesn't give a stacktrace.
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.
Good one 👍
This is just in case the `sh` error I'm experiencing has been fixed recently. I haven't actually checked the release notes, but an update like this is beneficial anyway.
`Action.sh` delegates directly to `Actions.sh_control_output,` which accepts `print_command:` and `print_command_output:`, not `log:`. The delegation occurs in `fastlane/lib/fastlane/action.rb` using Ruby's Forwardable module: ``` def_delegator(Actions, :sh_control_output, :sh) ``` `Actions.sh` is a wrapper that accepts `log:` and translates it to `print_command:` and `print_command_output:` when calling `sh_control_output`. See: - https://github.com/fastlane/fastlane/blob/2.231.0/fastlane/lib/fastlane/action.rb#L32-L39 - https://github.com/fastlane/fastlane/blob/2.231.0/fastlane/lib/fastlane/helper/sh_helper.rb#L4-L28
| elsif can_resolve_path(localized_file) | ||
| resolve_path(localized_file).realpath.to_s | ||
| else | ||
| UI.important("Could not identify '#{localized_file}' as a file path or the file was not found. Will use its value as a raw string. This may result in undesired annotations.") |
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.
In testing, I was surprised to find annotated screenshots with a path instead of of text as the title.
The reason was misconfiguration of the path on my end, but the fact remains that the tool, in being flexible, might hide missing files. This can be dangerous if automation runs unsupervised.
We might want to rethink the tool's behavior. But in the meantime, here's a warning in the logs.
(Not sure yet why it's printed twice)
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.
The reason was misconfiguration of the path on my end, but the fact remains that the tool, in being flexible, might hide missing files. This can be dangerous if automation runs unsupervised.
👍 I agree.
Not sure yet why it's printed twice
I see that if both paths are misconfigured and can't be resolved, we'll then have two warnings as resolve_text_into_path is called twice (draw_caption_to_canvas and draw_text_attachment_to_canvas).
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 see that if both paths are misconfigured
Oh, of course! Thanks @iangmaia !
In my tests, I had hardcoded only one language, but forgot Woo is configured to create promo screenshots for iPhone and iPad. Given the copy is the same, we'll obviously attempt two reads of that localization file. All clear now.
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.
Left a non blocking comment about avoiding command -v being called multiple times and there's also the CHANGELOG.md update.
Approving to unblock (I've disabled auto-merge in case you want to address anything before merging).
--- Generate with the help of Claude Code, https://code.claude.com Co-Authored-By: Ian Maia <ian.maia@automattic.com> Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
From the docs: Use this method to exit the program because of terminal state that is neither the fault of fastlane, nor a problem with the user's input. Using this method instead of user_error! will avoid tracking this outcome as a fastlane failure.
| Dir.mkdir(path) | ||
| else | ||
| UI.user_error!("Exiting to avoid overwriting #{description}.") | ||
| UI.abort_with_message!("Exiting to avoid overwriting #{description}.") |
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.
Seems more appropriate as an exit call resulting from a confirm user input than user_error!.
I'd actually argue we should not crash and simply terminate the execution (return, next). But that's out of scope at the moment because it would require restructuring the entire method to bubble up the intention of terminating. Simply calling return here would only result in the code continuing, which is not what we desire.
|
@iangmaia thanks again for the review. I implemented your suggestions and tested the code locally via the integration PR on WooCommerce iOS, woocommerce/woocommerce-ios#16517 I'm going to merge to keep the ball rolling. Then, I'll merge |
What does it do?
I tried running the screenshot annotation on my end and it failed. Internal ref p1768453313053599/1768288277.528279-slack-CC7L49W13.
The reason it failed is that I didn't have screenshots images to annotate. That's obvious in hindsight, but it took me a bit to understand in between the dense logs.
This PR tracks the changes I made to cleanup the logs.
Note
As discussed in the thread, I haven't been able to test the changes yet in terms of actually calling down to ImageMagick. Still, I'd appreciate your feedback.Update: This has now been tested locally, but I closed the session with the successful outcome so I don't have a screenshot (pun not intended) to share.
I sampled the generated annotated screenshots and they LGTM.
Checklist before requesting a review
bundle exec rubocopto test for code style violations and recommendations.specs/*_spec.rb) if applicable. — N.A.bundle exec rspecto run the whole test suite and ensure all your tests pass.CHANGELOG.mdfile to describe your changes under the appropriate existing###subsection of the existing## Trunksection.MIGRATION.mdfile to describe how the changes will affect the migration from the previous major version and what the clients will need to change and consider. — N.A.