|
| 1 | +# Contributing |
| 2 | + |
| 3 | +Although we are always happy to make improvements, we also welcome changes and |
| 4 | +improvements from the community! |
| 5 | + |
| 6 | +Have a fix for a problem you've been running into or an idea for a new feature |
| 7 | +you think would be useful? Here's what you need to do: |
| 8 | + |
| 9 | +1. [Read and understand the Code of Conduct](#code-of-conduct). |
| 10 | +2. Fork this repo (unless you work at Ackama) and clone that repo to somewhere |
| 11 | + on your machine. |
| 12 | +3. [Ensure that you have a working environment](#setting-up-your-environment). |
| 13 | +4. Read up on the [architecture of the project](#architecture), |
| 14 | + [how to run tests](#tests), and |
| 15 | + [the code style we use in this project](#code-style). |
| 16 | +5. Cut a new branch and write a failing test for the feature or bugfix you plan |
| 17 | + on implementing. |
| 18 | +6. [Make sure your branch is well managed as you go along](#managing-your-branch). |
| 19 | +7. If this branch fixes an issue, use github's `fixes: #issue_number` when |
| 20 | + writing your commit message to link the issue to your pr. |
| 21 | +8. Push to your fork and create a pull request. |
| 22 | +9. Ensure that the test suite passes CI and make any necessary changes to your |
| 23 | + branch to bring it to green. |
| 24 | + |
| 25 | +We aim to review pull requests at our internal Ackama fortnightly ruby guild |
| 26 | +meeting. Once we look at your pull request, we may give you feedback. For |
| 27 | +instance, we may suggest some changes to make to your code to fit within the |
| 28 | +project style or discuss alternate ways of addressing the issue in question. |
| 29 | +Assuming we're happy with everything, we'll then bring your changes into main. |
| 30 | +Now you're a contributor! |
| 31 | + |
| 32 | +## Code of Conduct |
| 33 | + |
| 34 | +If this is your first time contributing, please read the [Code of Conduct]. We |
| 35 | +want to create a space in which everyone is allowed to contribute, and we |
| 36 | +enforce the policies outline in this document. |
| 37 | + |
| 38 | +[code of conduct]: |
| 39 | + https://github.com/ackama/rails-template/blob/main/CODE_OF_CONDUCT.md |
| 40 | + |
| 41 | +## Setting up your environment |
| 42 | + |
| 43 | +1. Install |
| 44 | + [the most recent ruby version](https://www.ruby-lang.org/en/downloads/) with |
| 45 | + the ruby version manager of your choice |
| 46 | +2. Run `gem install rails` to get the most recent rails release |
| 47 | +3. Install the node version defined in the `.node-version` file with the node |
| 48 | + version manager of your choice |
| 49 | +4. Install yarn v1 |
| 50 | + |
| 51 | +To run tests you'll also need to install |
| 52 | + |
| 53 | +- [PostgreSQL](https://www.postgresql.org/) |
| 54 | +- [Chromedriver](https://chromedriver.chromium.org/) |
| 55 | + |
| 56 | +## Architecture |
| 57 | + |
| 58 | +This project works by hooking into the standard Rails |
| 59 | +[application templates](https://guides.rubyonrails.org/rails_application_templates.html) |
| 60 | +system, with some caveats. The entry point is the |
| 61 | +[template.rb](https://github.com/ackama/rails-template/blob/main/template.rb) |
| 62 | +file in the root of this repository. |
| 63 | + |
| 64 | +Normally, Rails only allows a single file to be specified as an application |
| 65 | +template (i.e. using the `-m <URL>` option). To work around this limitation, the |
| 66 | +first step this template performs is a `git clone` of the |
| 67 | +`ackama/rails-template` repository to a local temporary directory. |
| 68 | + |
| 69 | +This temporary directory is then added to the `source_paths` of the Rails |
| 70 | +generator system, allowing all of its ERb templates and files to be referenced |
| 71 | +when the application template script is evaluated. |
| 72 | + |
| 73 | +Rails generators are very lightly documented; what you'll find is that most of |
| 74 | +the heavy lifting is done by [Thor](http://whatisthor.com/). Thor is a tool that |
| 75 | +allows you to easily perform command line utilities. The most common methods |
| 76 | +used by this template are Thor's `copy_file`, `template`, and `gsub_file`. You |
| 77 | +can dig into the well-organized and well-documented |
| 78 | +[Thor source code](https://github.com/erikhuda/thor) to learn more. If any file |
| 79 | +finishes with `.tt`, Thor considers it to be a template and places it in the |
| 80 | +destination without the extension `.tt`. |
| 81 | + |
| 82 | +## Tests |
| 83 | + |
| 84 | +this template is tested by building a set of apps with different configuration |
| 85 | +and checking each passes the templated linters and tests. |
| 86 | + |
| 87 | +the config is in ci/configs/\*.yml, and is run by ci/bin/build-and-test |
| 88 | + |
| 89 | +```bash |
| 90 | +# create new rails app in tmp/builds/enterprise using ci/configs/react.yml as |
| 91 | +$ CONFIG_PATH="ci/configs/react.yml" APP_NAME="enterprise" ./ci/bin/build-and-test |
| 92 | +``` |
| 93 | + |
| 94 | +To add another tested configuration |
| 95 | + |
| 96 | +1. add a file in ci/configs |
| 97 | +2. add it to the lists in .github/workflows/ci.yml |
| 98 | + |
| 99 | +## Code style |
| 100 | + |
| 101 | +Rubocop is configured for this repo and is run as part of CI. Run rubocop |
| 102 | +locally via the usual method: |
| 103 | + |
| 104 | +``` |
| 105 | +$ bundle install |
| 106 | +$ bundle exec rubocop # optionally adding -a or -A for autofixes |
| 107 | +``` |
| 108 | + |
| 109 | +Prettier is used to manage the style for json, js/jsx/ts/tsx, css/scss, and |
| 110 | +md/markdown files, and is run as part of CI. Run prettier localy via yarn |
| 111 | + |
| 112 | +``` |
| 113 | +$ yarn install |
| 114 | +$ yarn run format-check # or `yarn run format-fix` for autofixes |
| 115 | +``` |
| 116 | + |
| 117 | +## Managing your branch |
| 118 | + |
| 119 | +- Use well-crafted commit messages, providing context if possible. |
| 120 | +- Squash "WIP" commits and remove merge commits by rebasing your branch against |
| 121 | + `main`. We try to keep our commit history as clean as possible. |
| 122 | + |
| 123 | +## Documentation |
| 124 | + |
| 125 | +As you navigate the codebase, you may notice certain classes and methods that |
| 126 | +are prefaced with inline documentation. |
| 127 | + |
| 128 | +If your changes end up extending or updating the API, it helps greatly to update |
| 129 | +the docs at the same time for future developers and other readers of the source |
| 130 | +code. |
| 131 | + |
| 132 | +Ensure any changes to features documented in the README.md or this |
| 133 | +CONTRIBUTING.md have their documentation updated as necessary. |
| 134 | + |
| 135 | +If you're ackama staff, ensure any linked ackama-internal documentation is also |
| 136 | +up-to-date. |
0 commit comments