You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -33,7 +39,9 @@ Ruby rules for [Bazel](https://bazel.build).
33
39
34
40
**Work in progress.**
35
41
36
-
## USAGE
42
+
We have a guide on [Building your first Ruby Project](https://github.com/bazelruby/rules_ruby/wiki/Build-your-ruby-project) on the Wiki. We encourage you to check it out.
43
+
44
+
## Usage
37
45
38
46
Add `ruby_rules_dependencies` and `ruby_register_toolchains` into your `WORKSPACE` file.
1. Setup dev tools as described in the [setup](#setup) section.
425
-
2. hack, hack, hack...
426
-
3. Make sure all tests pass
427
-
*`bazel test //...`
428
-
*`cd examples/simple_script && bazel test //...`
429
-
4. Open a pull request in Github
432
+
We welcome contributions to RulesRuby. Please make yourself familiar with the [CODE_OF_CONDUCT](CODE_OF_CONDUCT.md) document.
433
+
434
+
You may notice that there is more than one Bazel WORKSPACE inside this repo. There is one in `examples/simple_script` for instance, because
435
+
we use this example to validate and test the rules. So be mindful whether your current directory contains `WORKSPACE` file or not.
430
436
431
437
### Setup
432
438
433
-
To get the initial stuff setup required by this repo, please run the script:
439
+
#### Using the Script
440
+
441
+
You will need Homebrew installed prior to running the script.
442
+
443
+
After that, cd into the top level folder and run the setup script in your Terminal:
434
444
435
445
```bash
436
-
bin/setup
446
+
❯ bin/setup
437
447
```
438
448
439
-
This script does a couple of very useful things, including setting up a git commit
440
-
hook that performs rubocop fixes and buildifier fixes of the Bazel build files.
441
-
442
-
You can run partial setup comamnds like so:
449
+
This runs a complete setup, shouldn't take too long. You can explore various script options with the `help` command:
443
450
444
451
```bash
445
-
❯ bin/setup -h
452
+
❯ bin/setup help
453
+
USAGE
454
+
# without any arguments runs a complete setup.
455
+
bin/setup
446
456
447
-
USAGE:
448
-
bin/setup [ gems | git-hook |help|install| main |no-git-hook ]
457
+
# alternatively, a sub-setup function name can be passed:
458
+
bin/setup [ gems | git-hook |help|os-specific| main |remove-git-hook ]
449
459
450
460
DESCRIPTION:
451
461
Runs full setup without any arguments.
452
462
453
-
Accepts one argument — one of the actions that typically run
454
-
as part of setup.
463
+
Accepts one optional argument — one of the actions that typically run
464
+
as part of setup, with one exception — remove-git-hook.
465
+
This action removes the git commit hook installed by the setup.
455
466
456
-
For instance, to perform full setup:
467
+
EXAMPLES:
468
+
bin/setup — runs the entire setup.
469
+
```
457
470
458
-
bin/setup
471
+
#### OS-Specific Setup
459
472
460
-
Or, to run only one of the sub-functions (actions), pass
461
-
it as an argument:
473
+
Note that the setup contains `os-specific` section. This is because there are two extension scripts:
462
474
463
-
bin/setuphelp
464
-
bin/setup no-git-hook
475
+
*`bin/setup-linux`
476
+
*`bin/setup-darwin`
465
477
466
-
etc.
467
-
```
478
+
Those will install Bazel and everything else you need on either platform. In fact, we use the linux version on CI.
479
+
480
+
##### Issues During Setup
481
+
482
+
**Please report any errors to `bin/setup` as Issues on Github. You can assign them to @kigster.**
483
+
484
+
### Developing Rules
485
+
486
+
Besides making yourself familiar with the existing code, and [Bazel documentation on writing rules](https://docs.bazel.build/versions/master/skylark/concepts.html), you might want to follow this order:
487
+
488
+
1. Setup dev tools as described in the [setup](#Setup) section.
489
+
3. hack, hack, hack...
490
+
4. Make sure all tests pass — you can run a single command for that (but see more on it [below](#test-script).
491
+
492
+
```bash
493
+
bin/test-suite
494
+
```
495
+
496
+
OR you can run individual Bazel test commands from the inside.
497
+
498
+
*`bazel test //...`
499
+
*`cd examples/simple_script && bazel test //...`
468
500
469
-
Whenever you'll commit something, a pre-commit hook will run as well. If it
470
-
finds anything that needs fixing, it will attempt to fix it. If the resulting
471
-
git state is different than before the commit, the commit is aborted and the user
472
-
should add any auto-fixed modifications to the list of staged files for commit.
501
+
4. Open a pull request in Github, and please be as verbose as possible in your description.
502
+
503
+
In general, it's always a good idea to ask questions first — you can do so by creating an issue.
473
504
474
505
### Running Tests
475
506
476
-
We have a pretty useful script you can use to run all tests in the repo that run on CI:
507
+
After running setup, and since this is a bazel repo you can use Bazel commands:
508
+
509
+
```bazel
510
+
bazel build //...:all
511
+
bazel query //...:all
512
+
bazel test //...:all
513
+
```
514
+
515
+
But to run tests inside each sub-WORKSPACE, you will need to repeat that in each sub-folder. Luckily, there is a better way.
516
+
517
+
#### Test Script
518
+
519
+
This script runs all tests (including sub-workspaces) when ran without arguments:
520
+
521
+
```bash
522
+
bin/test-suite
523
+
```
524
+
525
+
Run it with `help` command to see other options, and to see what parts you can run individually. At the moment they are:
477
526
478
527
```bash
479
-
bin/ci
528
+
# alternatively, a partial test name can be passed:
529
+
bin/test-suite [ all | bazel-info | buildifier | help | rspec | rubocop | simple-script | workspace ]
480
530
```
481
531
482
532
On a MacBook Pro it takes about 3 minutes to run.
483
533
534
+
### Linter
535
+
536
+
We are using RuboCop for ruby and Buildifier for Bazel. Both are represented by a single script `bin/linter`, which just like the scripts above runs ALL linters when ran without arguments, accepts `help` commnd, and can be run on a subset of linting strategies:
537
+
538
+
```bash
539
+
bin/linter
540
+
```
541
+
542
+
The following are the partial linting functions you can run:
543
+
544
+
```bash
545
+
# alternatively, a partial linter name can be passed:
0 commit comments