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

[action] add xcodes action, deprecating xcversion and xcode-install #20672

Merged
merged 29 commits into from Nov 12, 2022

Conversation

rogerluan
Copy link
Member

@rogerluan rogerluan commented Sep 18, 2022

Checklist

  • I've run bundle exec rspec from the root directory to see all new and existing tests pass
  • I've followed the fastlane code style and run bundle exec rubocop -a to ensure the code style is valid
  • I see several green ci/circleci builds in the "All checks have passed" section of my PR (connect CircleCI to GitHub if not)
  • I've read the Contribution Guidelines
  • I've updated the documentation if necessary.

Motivation and Context

With the planned sunset of xcode-install (aka xcversion) gem (xcpretty/xcode-install#467), a new action was needed to support xcodes.

Description

This PR depends on XcodesOrg/xcodes#220 and XcodesOrg/xcodes#182 merge & release so the installed option with specified version is available, as well as --install and --select arguments for the install option.

These PRs were later merged & released under v1.1.0 https://github.com/RobotsAndPencils/xcodes/releases/tag/1.1.0, so v1.1.0 of xcodes is required to use and test this feature.

Testing Steps

To test this branch, modify your Gemfile as:

gem 'fastlane', git: 'https://github.com/fastlane/fastlane.git', branch: 'rogerluan-xcodes'

And run bundle install to apply the changes.

Then switch your implementation of xcversion and xcode_install according to the migration guide which can be found here: https://github.com/xcpretty/xcode-install/blob/master/MIGRATION.md

Any and every testing is highly appreciated! I did very limited testing only 🙇

image

image

@rogerluan
Copy link
Member Author

The spec failure that is happening in this PR also happens in master, and it may be something related to recent changes on Apple's end 😬

@rogerluan rogerluan changed the title [action] add 'xcodes' action, deprecating 'xcversion' and 'xcode-install' [action] add xcodes action, deprecating xcversion and xcode-install Sep 19, 2022
@rogerluan
Copy link
Member Author

It's weird:

  • Locally, on my machine, a lot of specs fail both in this PR as well as in master, same for rubocop violations
  • In CI, master seems to not be failing
  • In CI, in another PR of mine, all specs passed
  • In CI, this PR keeps failing in non-related changes 🤔

@rogerluan
Copy link
Member Author

Ugh, so, locally, here's the breakdown:

  • Ruby 3.1.x: a bunch of linter and specs issues
  • Ruby 3.x.x: linter and specs are all passing
  • Ruby 2.7.x: linter and specs are all passing
  • Ruby 2.6.x: I'm having trouble installing this version using rbenv (M2 machine) 😥 so I couldn't test..

CI is failing specs and it is running Ruby 2.6.0 apparently... but not sure why this is happening in my PR only, and on presumably unrelated files (fastlane_core/spec/cert_checker_spec.rb) something related to:

#installed_wwdr_certificates
      should return installed certificate's alias (FAILED - 4)
      should return an empty array if unknown WWDR certificates are found (FAILED - 5)

😬 Any help would be appreciated

Copy link
Collaborator

@revolter revolter left a comment

Choose a reason for hiding this comment

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

Hi @rogerluan 👋🏻

Nice to "see" you again after a long time 😃 And sorry for the late reply.


😬 Any help would be appreciated

I can't promise anything, but I hope I'll take a look some time after reviewing this.


I read the migration guide and this PR's description, I started testing it, but it failed with:

[21:00:46]: Couldn't find xcodes binary at path ''
[21:00:46]: You passed invalid parameters to 'xcodes'.
[21:00:46]: Check out the error below and available options by running `fastlane action xcodes`
+------------------+------------------+
|            Lane Context             |
+------------------+------------------+
| DEFAULT_PLATFORM | ios              |
| PLATFORM_NAME    | ios              |
| LANE_NAME        | ios ensure_xcode |
+------------------+------------------+
[21:00:46]: Invalid default value for binary_path, doesn't match verify_block

Although it is fairly obvious that the issue is that it can't find xcodes, and you have to (most probably) run brew install robotsandpencils/made/xcodes, I think that this should be mentioned in the migration guide and/or the new action's description, since it's a required dependency that's not automatically managed by fastlane. What do you think?

fastlane/lib/fastlane/actions/xcodes.rb Outdated Show resolved Hide resolved
fastlane/lib/fastlane/actions/xcodes.rb Outdated Show resolved Hide resolved
fastlane/lib/fastlane/actions/xcodes.rb Show resolved Hide resolved
fastlane/spec/helper/xcodes_helper_spec.rb Outdated Show resolved Hide resolved
fastlane/spec/helper/xcodes_helper_spec.rb Outdated Show resolved Hide resolved
fastlane/spec/helper/xcodes_helper_spec.rb Outdated Show resolved Hide resolved
fastlane/spec/helper/xcodes_helper_spec.rb Outdated Show resolved Hide resolved
fastlane/spec/helper/xcodes_helper_spec.rb Outdated Show resolved Hide resolved
fastlane/spec/helper/xcodes_helper_spec.rb Outdated Show resolved Hide resolved
fastlane/spec/helper/xcodes_helper_spec.rb Outdated Show resolved Hide resolved
@rogerluan
Copy link
Member Author

Oops, forgot to address the "no binary" issue. Gimme a few mins

@rogerluan
Copy link
Member Author

rogerluan commented Oct 14, 2022

Done @revolter 😊 Nice catch!

image


Also: xcpretty/xcode-install@43328e9

@rogerluan
Copy link
Member Author

@revolter would you mind helping me understand what's failing in the CI specs? I added comments about it here and I'm still clueless on how to solve this 😿

Copy link
Collaborator

@revolter revolter left a comment

Choose a reason for hiding this comment

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

Just some small changes, to be less confusing for future contributors 🤔

fastlane/lib/fastlane/actions/xcodes.rb Outdated Show resolved Hide resolved
fastlane/spec/actions_specs/xcodes_spec.rb Show resolved Hide resolved
fastlane/spec/actions_specs/xcodes_spec.rb Outdated Show resolved Hide resolved
fastlane/spec/actions_specs/xcodes_spec.rb Show resolved Hide resolved
@revolter
Copy link
Collaborator

revolter commented Nov 1, 2022

@rogerluan, would you mind if I'd remove the merge commit, and rebase the branch instead?

@rogerluan
Copy link
Member Author

@rogerluan, would you mind if I'd remove the merge commit, and rebase the branch instead?

By all means @revolter 🙇
Would that help debug the CI problem?

@revolter
Copy link
Collaborator

revolter commented Nov 2, 2022

Would that help debug the CI problem?

I hope it fixes it 😂 Because it doesn't make sense

@revolter revolter force-pushed the rogerluan-xcodes branch 7 times, most recently from 2b04c63 to fad9d58 Compare November 2, 2022 21:58
This makes it consistent with the rest of the codebase.
This was caused by the fact that that test calls a method that uses `$?`
(https://stackoverflow.com/a/6834572/865175), which, somehow, (I think)
was executed right after a call to XcodesHelper's
`find_xcodes_binary_path` method. This latter one returned a non-zero
code, because `xcodes` can't be installed on Ubuntu, which got picked up
by the certificates return code check, so it treated its actual command
as failed.
@revolter
Copy link
Collaborator

revolter commented Nov 2, 2022

Ok, this took me a lot longer than I thought it would 😐 Very very weird issue, but great debugging session nonetheless ❤️

I also noticed that some paths were being concatenated using +, so I used the same method as in xcode_select.rb (note: it works with an already present slash because that method makes sure not to duplicate the separator: https://stackoverflow.com/a/4114966/865175).

There are still some failures, but these ones might not be that hard to fix 🤔

(Also, because I rebased and force-pushed to the branch, guessing that you didn't commit anything after 136b664, please delete the local branch, fetch the new changes, and check it out again, to avoid other superfluous merges.)

I really need to go to sleep now, as it's already tomorrow 😫

@revolter
Copy link
Collaborator

revolter commented Nov 3, 2022

Please let me work on this more? 😂 I have an idea that I want to test this evening.

@revolter
Copy link
Collaborator

revolter commented Nov 3, 2022

Ok, I was not happy with the fix, because I didn't understand it fully (still don't), and felt more like a hack. From what I (extensively) read, even through the source code, and by also testing it locally by replacing the curl command with ls, it looks like this (the last commit) is the safe and correct way to fix this issue for good.

@revolter
Copy link
Collaborator

revolter commented Nov 3, 2022

Somehow, the 2 failures (Validate Documentation and Validate Fastlane.swift generation) got fixed too 😮

Copy link
Member Author

@rogerluan rogerluan left a comment

Choose a reason for hiding this comment

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

@revolter dude, this was just amazing!! Thank you thank you thank you ❤️ Great context that you provided in the commit messages also! I'd never have guessed something like this, I can't even imagine how was your train of thought and how you got to the root cause 🤯

Separately, do you think we should at least create an Issue for future improvement of getting rid of all the $? in other specs (and maybe in the source code too)?

Again, thank you so much 🙇 I'm so glad we'll be able to deliver this PR to xcode-install users 💪

if FastlaneCore::Globals.verbose?
UI.command_output(stdout)
UI.command_output(stderr)
end

unless $?.success?
unless status.success?
Copy link
Member Author

Choose a reason for hiding this comment

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

👏👏👏

@@ -12,7 +12,7 @@ def self.read_xcode_version_file
end

def self.find_xcodes_binary_path
`which xcodes`.strip
Actions.sh("which xcodes", log: false).strip
Copy link
Member Author

Choose a reason for hiding this comment

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

What the... 🤯

In the case of the tests, `$?` was not mocked, so it looks like it was
indeed just a coincidence that it worked. Meaning, some other shell
command that somehow was actually executed (so it wasn't stubbed)
succeeded, which caused the `$?.success?` to succeed too.
@revolter
Copy link
Collaborator

revolter commented Nov 4, 2022

I can't even imagine how was your train of thought and how you got to the root cause 🤯

Brute-force trial and error, using divide et impera, by reverting half of the changes, then half of the half, etc., until I pinpointed the responsible line of code, and then a lightbulb went off in my head about the $? usage from cert_checker.rb.

image

Separately, do you think we should at least create an Issue for future improvement of getting rid of all the $? in other specs (and maybe in the source code too)?

Hmm, maybe that would be the way to go, but it's also a case of "if it ain't broken, don't fix it" 🤔 Maybe the best thing is that at least the 2 of us know of this, and hopefully remember it when (if) it happens in the future.

Again, thank you so much 🙇 I'm so glad we'll be able to deliver this PR to xcode-install users 💪

Really happy that I could (finally) help you with this one. Thank you too for the kind words, I'm really flattered ☺️ I'm happy that you took the time to do the other 99% of work for this migration ❤️

Copy link
Member

@joshdholtz joshdholtz 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 soooo amazing!! ❤️ Sorry it took so long but I'm back from family leave and thank for doing this 😊

@fastlane-bot
Copy link

Congratulations! 🎉 This was released as part of fastlane 2.211.0 🚀

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

Successfully merging this pull request may close these issues.

None yet

5 participants