-
Notifications
You must be signed in to change notification settings - Fork 6
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
Generate models automatically to keep them up-to-date #4
base: master
Are you sure you want to change the base?
Conversation
I realised that |
I switched the input format to JSON so that parsing is easy now. However, I decided not to go with keeping markdown comments (original definition) as it's just duplicated and now a bit difficult to replicate😅 Updated the models with stable Xcode 13.1's xcresulttool accordingly. |
Nothing blocks at all. It's just a matter of who to review and merge, I guess? @lechuckcaptain if you could test #5's branch with your project and report feedback, that would be amazing, too! |
Prior to this PR,
xcresult
gem has been using (semi?) handcrafted models to parse.xcresult
data, I assume. So that it's not up-to-date to the latest version nor implementing all of the properties on each type.This PR aims to switch the strategy to maintain
xcresult
to using a script to generate models based on whatxcrun xcresulttool formatDescription get --format json
outputs.As a result, we've got new models related to
ActivityLog
(honestly I don't know what it is though😅) and most importantly it's got "version" info and the timestamp of the last update in its code.With this PR, the file structure related to models will be like below. (Naming suggestions are very welcome🙏)
lib/xcresult/models.gen.rb
- automatically generated file that defines models and is supposed to be updated bybin/generate_models
scriptlib/xcresult/models.rb
- entrypoint to dorequire
models.gen
and add convenient methods to defined modelsbin/generate_models
script is the one we can use to updatelib/xcresult/models.gen.rb
. We might be able to automate to create PRs to keep models up-to-date in future but for now, we need to run it manually.One thing I need to mention is that this time I wrapped all models into another nested namespace
XCResult::Models
to make it easy to differentiate other classes that exist other than representing models. And you won't need to worry about the conflict of naming with what Apple gives us in the future. I started using dynamic class loading likeKernel.const_get("XCResult::Models::#{type_name}")
, which makes implementing polymorphic objects easier a lot. If we don't use a dedicated namespace, it's less likely but may happen to load the wrong classes. It's safer to assume classes underXCResult::Models
namespace are for models parsing the JSON.This is a breaking change but I would justify it for the following reasons, in my opinion.
parser.export_xccovreports(destination: './outputs')
https://github.com/fastlane-community/xcov/blob/f8904c7f000b415c7800b1c68c50e8de9dab76da/lib/xcov/manager.rb#L217-L221::Models
) and only once but the benefit will be foreverI can easily remove the additional nest of the namespace (
::Models
) if you are concerned about compatibility. Please let me know🙂JFYI: After merging this PR, I'd like to add screenshot extraction functionality to this gem 🏃