Skip to content

Remove custom check for CI in favor of using Fastlane's one #336

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

Merged

Conversation

mokagio
Copy link
Contributor

@mokagio mokagio commented Feb 7, 2022

Addresses a small TODO comment as we prepare for a new release. See also #334 (comment).

# Fastlane::is_ci doesn't work here, so reimplementing the code has been necessary.
# (This should be updated if we change CI or if fastlane is updated.)
return File.read(secrets_repository_file_path) unless self.encrypt || ENV.key?('CIRCLECI')
return File.read(secrets_repository_file_path) unless self.encrypt || FastlaneCore::Helper.is_ci?
Copy link
Contributor

Choose a reason for hiding this comment

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

Any idea why the comment initially said that "Fastlane::is_ci? doesn't work here "?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm pretty sure the reason is that is_ci is a Fastlane action and can't be called directly.

If we put it in here, we get a no method error.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, right. As opposed to calling the helper directly as you did here 👍👌

# Fastlane::is_ci doesn't work here, so reimplementing the code has been necessary.
# (This should be updated if we change CI or if fastlane is updated.)
return File.read(secrets_repository_file_path) unless self.encrypt || ENV.key?('CIRCLECI')
return File.read(secrets_repository_file_path) unless self.encrypt || FastlaneCore::Helper.is_ci?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

See is_ci? source here.

To test this change, I run the tests as usual first, the re-run them for this file with CI=1:

CI=1 bundle exec rspec spec/file_reference_spec.rb

I got the following failure:

  1) Fastlane::Configuration::FileReference without encryption #source_contents gets the contents from the secrets repo
     Failure/Error: expect(subject.source_contents).to eq('source contents')

       expected: "source contents"
            got: nil

       (compared using ==)

That's exactly the failure I would expect to get: is_ci? returned true and we didn't read from the stubbed local secrets but tried to read the encrypted source, which didn't exist.

Copy link
Contributor

Choose a reason for hiding this comment

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

That also means that the test is failing on CI though 😓😛

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤦‍♂️

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤦‍♂️ is not enough of a reaction...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

image

@wpmobilebot
Copy link

1 Warning
⚠️ Please add an entry in the CHANGELOG.md file to describe the changes made by this PR

Generated by 🚫 Danger

Comment on lines -81 to +82
set_circle_env(true) do
allow(File).to receive(:read).with(subject.secrets_repository_file_path).and_return('source contents')
expect(subject.source_contents).to eq(nil)
end
allow(FastlaneCore::Helper).to receive(:is_ci?).and_return(true)
allow(File).to receive(:read).with(subject.secrets_repository_file_path).and_return('source contents')
expect(subject.source_contents).to eq(nil)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Having to work on this made me wonder whether it is appropriate for FileReference to know whether its code runs on CI or not.

I was tempted to leave a FIXME mentioning this and suggesting to move the knowledge up the abstraction ladder, but I didn't because:

  1. FileReference is a fat model, not a mere data representation objects. For example, it knows how to diff and apply changes to the file system
  2. This objects is used for the secrets management and, in the long run, we want to use the Rust implementation so I wouldn't recommend working on stuff that is not a necessary bug fix

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I've never liked the way that this was all hosted in FileReference, this would definitively benefit some restructuration and refactoring… but that's something to keep for later™

@mokagio
Copy link
Contributor Author

mokagio commented Feb 7, 2022

@wpmobilebot

Please add an entry in the CHANGELOG.md file to describe the changes made by this PR

Ignoring because this is just a refactor of an internal method.

@mokagio mokagio requested a review from AliSoftware February 7, 2022 09:33
@AliSoftware
Copy link
Contributor

Ignoring because this is just a refactor of an internal method.

To be fair one of the goal of the CHANGELOG is also to be able to, if something stops working with secrets and configure_apply soon after the release, be aware that this might be because of that change here. So that users who notice such a change can look into the CHANGELOG and say "oh, something related to this changed in 3.0.0 so that might be it" and be able to jump in the PR which did the change… 🙃 (I know, we can also use git blame and git bisect, but CHANGELOG is faster to identify when key stuff changed).

I don't mind skipping it for this one (that's not really a big deal anyway tbh), but good to keep in mind for the future :)

@mokagio
Copy link
Contributor Author

mokagio commented Feb 7, 2022

@AliSoftware should I consider your last comment an implicit approval? If so, feel free to hit merge when you read this 😄

Otherwise, let me know what I missed. Thanks.

Copy link
Contributor

@AliSoftware AliSoftware left a comment

Choose a reason for hiding this comment

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

Oh yeah, sorry. Approved 👍

@AliSoftware AliSoftware merged commit 80f78d9 into release/3.0.0 Feb 7, 2022
@AliSoftware AliSoftware deleted the use-fastlane-helper-instead-of-reimplementing branch February 7, 2022 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants