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

Set up Rubocop for the template #320

Merged
merged 10 commits into from
Mar 21, 2022
Merged

Set up Rubocop for the template #320

merged 10 commits into from
Mar 21, 2022

Conversation

rosle
Copy link
Contributor

@rosle rosle commented Feb 3, 2022

#168

What happened

  • Set up Rubocop for template
  • Set up the workflow to run Rubocop - Test Template

Insight

Due to our current template structure, there are some customization on Bundle and Rubocop.

Current structure:

.
├── .template
│   ├── .rspec
│   ├── .rubocop.yml   <--- Rubocop config for template here
│   ├── .ruby-gemset
│   ├── Gemfile.       <--- Gemfile for the template here
│   ├── Gemfile.lock
│   ├── ...
│   ├── addons
│   └── variants
├── bin
│   ├── ...
│   └── template.rb
├── config
│   ├── ...
│   └── template.rb
├── spec
│   ├── ...
│   └── template.rb
└── template.rb.       <--- There are also project template outside (Base template)

The problem is we would need to run rubocop on the root of the project. So it runs tests for all the base template in the root and addon/varient in .template. Hence, we need to:

  1. Bundle - Config the Gemfile path in .bundle/config to point to .template/Gemfile. With this we will able to run bundle install and bundle exec rubocop from the root of the project
  2. Rubocop - Point the config when running rubocop command rubocop --config .template/.rubocop.yml. I've added the script in .template/bin/rubocop.

Due to the current file structure limitation, we need to have these configs in order to run rubocop. Later we can revisit the template structure e.g. consider moving base into .template 🤔

Proof Of Work

  • Able to run rubocop through .template/bin/rubocop at the root of the project.
    Screen Shot 2565-03-17 at 14 25 05

  • The Test Template workflow is run.
    Screen Shot 2565-03-17 at 14 22 25

@rosle rosle added this to the 5.0.0 milestone Feb 3, 2022
@rosle rosle self-assigned this Feb 3, 2022
@rosle rosle force-pushed the chore/refactor-heredoc branch 3 times, most recently from a43227d to 086e8ad Compare March 16, 2022 03:29
@rosle rosle changed the base branch from chore/refactor-heredoc to develop March 16, 2022 03:41
@rosle rosle force-pushed the chore/setup-rubocop branch 7 times, most recently from b510ba8 to 07f798f Compare March 16, 2022 05:04
Style/GlobalVars:
Enabled: false

# TODO: Enable this rule later
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'll enable these rules later in another PR, so this PR is not too big. 🙏

Copy link
Contributor

Choose a reason for hiding this comment

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

@rosle , here are two of my favorites cops:

Is this something we could incorporate, what do you think? Thank you!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noted. I'll open more PRs to fix these cops and I'll revisit those rules 👍 ✨

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tyrro I revisited these 2 cops, seems we already have it enabled 👍 🚀

@@ -1 +1,3 @@
# rubocop:todo Style/ClassAndModuleChildren
Copy link
Contributor Author

@rosle rosle Mar 17, 2022

Choose a reason for hiding this comment

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

I'll fix this when working on refactoring the template - #321. Because it needs to load the template module in prior. 🙏

@rosle rosle requested a review from a team March 17, 2022 08:09
@rosle rosle marked this pull request as ready for review March 17, 2022 08:10
Copy link
Contributor

@olivierobert olivierobert left a comment

Choose a reason for hiding this comment

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

Looks good to me. I just have one question.

README.md Outdated
If running on Apple M1:

- Set bundle platform to ruby `bundle config set --global force_ruby_platform true`
- To build docker image, please make sure to set platform to AMD64 `export DOCKER_DEFAULT_PLATFORM=linux/amd64`
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you have a reference/source for this workaround? We might need to have it on other templates too.

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 have issue when building the image, Chrome is failed to installed

#9 7.669 E: Unable to locate package google-chrome-stable
Screen Shot 2565-03-17 at 16 05 22

and seems it is because we need to supply --platform when doing docker build

https://medium.com/no-sliver-bullet/apple-m1-%E8%AE%93%E4%BD%A0%E7%9A%84-docker-build-%E4%B8%8D%E8%B5%B7%E4%BE%86%E4%BA%86%E5%97%8E-bbe133d6d1bb

From docker documentation:

We can supply that option in many places, --platform when build through cli, platform in docker compose file or through ENV export DOCKER_DEFAULT_PLATFORM=linux/amd64

Now I just set that ENV in my zshrc 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For bundle config set --global force_ruby_platform true, without it, the Gemfile.lock will generate

PLATFORMS
 arm64-darwin-21

(While usually we have platform ruby)

The project is created successfully but when running docker container, it fails (I think maybe because platform is different?). The error is from Nogokiri

https://nokogiri.org/tutorials/installing_nokogiri.html#how-can-i-avoid-using-a-precompiled-native-gem

🛠️ To fix: we can just add ruby to platforms

PLATFORMS
  arm64-darwin-21
  ruby

I found bundle config set --global force_ruby_platform true is easier, so we do not have to keep editing the lock file. 👀

But after I tried to reproduce, it does not happen anymore (maybe because we set platform 💭 ). Now Gemfile.lock in the container is automatically modified to

PLATFORMS
  arm64-darwin-21
  x86_64-linux

I'll revisit this config again tomorrow 🤔

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 can confirm bundle config set --global force_ruby_platform true is not required anymore. Maybe it's from platform setting:

On local machine:
Screen Shot 2565-03-18 at 10 41 55

Inside container, The additional platform is added:
Screen Shot 2565-03-18 at 10 55 46

I've updated the readme on f502949 👍

Copy link
Contributor

@tyrro tyrro left a comment

Choose a reason for hiding this comment

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

LGTM!

Style/GlobalVars:
Enabled: false

# TODO: Enable this rule later
Copy link
Contributor

Choose a reason for hiding this comment

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

@rosle , here are two of my favorites cops:

Is this something we could incorporate, what do you think? Thank you!

Copy link
Contributor

@longnd longnd left a comment

Choose a reason for hiding this comment

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

Screen Shot 2022-03-18 at 10 26 29
small tip, maybe you already know:

When linking a PR to an issue, we can use special keywords to close the issue automatically when the PR is merged, e.g.

close #168

@@ -0,0 +1,53 @@
AllCops:
NewCops: enable
TargetRubyVersion: 2.7
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't we target ruby 3?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in 25f0dc4

@rosle
Copy link
Contributor Author

rosle commented Mar 18, 2022

When linking a PR to an issue, we can use special keywords to close the issue automatically when the PR is merged, e.g.

close #168

Thank Long 👍 There will be a couple more PRs to fix the disabled Rubocop. I disabled those rules now to prevent the PR from getting too big. I'll do it in the last PR~ ✨

@rosle rosle requested a review from longnd March 18, 2022 04:07
@rosle rosle merged commit 43311cb into develop Mar 21, 2022
@rosle rosle mentioned this pull request Mar 21, 2022
@rosle rosle deleted the chore/setup-rubocop branch March 21, 2022 07:59
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.

5 participants