|
1 | 1 | # frozen_string_literal: true
|
2 | 2 |
|
| 3 | +require "pathname" |
3 | 4 | require "securerandom"
|
4 | 5 | require "shellwords"
|
5 | 6 |
|
6 | 7 | require "minitest/test_task"
|
7 | 8 | require "rake/clean"
|
8 | 9 | require "rubocop/rake_task"
|
9 | 10 |
|
10 |
| -CLEAN.push(*%w[.idea/ .ruby-lsp/ .yardoc/]) |
| 11 | +tapioca = "sorbet/tapioca" |
| 12 | +ignore_file = ".ignore" |
11 | 13 |
|
12 |
| -multitask(default: [:test]) |
| 14 | +CLEAN.push(*%w[.idea/ .ruby-lsp/ .yardoc/ doc/], *FileList["*.gem"], ignore_file) |
13 | 15 |
|
| 16 | +CLOBBER.push(*%w[sorbet/rbi/annotations/ sorbet/rbi/gems/], tapioca) |
| 17 | + |
| 18 | +multitask(:default) do |
| 19 | + sh(*%w[rake --tasks]) |
| 20 | +end |
| 21 | + |
| 22 | +desc("Preview docs; use `PORT=<PORT>` to change the port") |
| 23 | +multitask(:"docs:preview") do |
| 24 | + sh(*%w[yard server --bind [::] --reload --quiet --port], ENV.fetch("PORT", "8808")) |
| 25 | +end |
| 26 | + |
| 27 | +desc("Run test suites; use `TEST=path/to/test.rb` to run a specific test file") |
14 | 28 | multitask(:test) do
|
15 | 29 | rb =
|
16 | 30 | FileList[ENV.fetch("TEST", "./test/**/*_test.rb")]
|
|
23 | 37 | rubo_find = %w[find ./lib ./test ./rbi -type f -and ( -name *.rb -or -name *.rbi ) -print0]
|
24 | 38 | xargs = %w[xargs --no-run-if-empty --null --max-procs=0 --max-args=300 --]
|
25 | 39 |
|
26 |
| -multitask(:rubocop) do |
| 40 | +desc("Lint `*.rb(i)`") |
| 41 | +multitask(:"lint:rubocop") do |
27 | 42 | lint = xargs + %w[rubocop --fail-level E] + (ENV.key?("CI") ? %w[--format github] : [])
|
28 | 43 | sh("#{rubo_find.shelljoin} | #{lint.shelljoin}")
|
29 | 44 | end
|
30 | 45 |
|
31 |
| -multitask(:ruboformat) do |
| 46 | +desc("Format `*.rb(i)`") |
| 47 | +multitask(:"format:rubocop") do |
32 | 48 | fmt = xargs + %w[rubocop --fail-level F --autocorrect --format simple --]
|
33 | 49 | sh("#{rubo_find.shelljoin} | #{fmt.shelljoin}")
|
34 | 50 | end
|
35 | 51 |
|
36 |
| -multitask(:syntax_tree) do |
| 52 | +desc("Format `*.rbs`") |
| 53 | +multitask(:"format:syntax_tree") do |
37 | 54 | find = %w[find ./sig -type f -name *.rbs -print0]
|
38 | 55 | inplace = /darwin|bsd/ =~ RUBY_PLATFORM ? %w[-i''] : %w[-i]
|
39 | 56 | uuid = SecureRandom.uuid
|
@@ -74,27 +91,49 @@ multitask(:syntax_tree) do
|
74 | 91 | fail unless success
|
75 | 92 | end
|
76 | 93 |
|
77 |
| -multitask(format: [:ruboformat, :syntax_tree]) |
| 94 | +desc("Format everything") |
| 95 | +multitask(format: [:"format:rubocop", :"format:syntax_tree"]) |
78 | 96 |
|
79 |
| -multitask(:steep) do |
| 97 | +desc("Typecheck `*.rbs`") |
| 98 | +multitask(:"typecheck:steep") do |
80 | 99 | sh(*%w[steep check])
|
81 | 100 | end
|
82 | 101 |
|
83 |
| -multitask(:sorbet) do |
| 102 | +desc("Typecheck `*.rbi`") |
| 103 | +multitask(:"typecheck:sorbet") do |
84 | 104 | sh(*%w[srb typecheck])
|
85 | 105 | end
|
86 | 106 |
|
87 |
| -file("sorbet/tapioca") do |
| 107 | +file(tapioca) do |
88 | 108 | sh(*%w[tapioca init])
|
89 | 109 | end
|
90 | 110 |
|
91 |
| -multitask(typecheck: [:steep, :sorbet]) |
92 |
| -multitask(lint: [:rubocop, :typecheck]) |
| 111 | +desc("Typecheck everything") |
| 112 | +multitask(typecheck: [:"typecheck:steep", :"typecheck:sorbet"]) |
| 113 | + |
| 114 | +desc("Lint everything") |
| 115 | +multitask(lint: [:"lint:rubocop", :typecheck]) |
| 116 | + |
| 117 | +desc("Build yard docs") |
| 118 | +multitask(:"build:docs") do |
| 119 | + sh(*%w[yard]) |
| 120 | +end |
| 121 | + |
| 122 | +desc("Build ruby gem") |
| 123 | +multitask(:"build:gem") do |
| 124 | + # optimizing for grepping through the gem bundle: many tools honour `.ignore` files, including VSCode |
| 125 | + # |
| 126 | + # both `rbi` and `sig` directories are navigable by their respective tool chains and therefore can be ignored by tools such as `rg` |
| 127 | + Pathname(ignore_file).write(<<~GLOB) |
| 128 | + rbi/* |
| 129 | + sig/* |
| 130 | + GLOB |
93 | 131 |
|
94 |
| -multitask(:build) do |
95 | 132 | sh(*%w[gem build -- openai.gemspec])
|
| 133 | + rm_rf(ignore_file) |
96 | 134 | end
|
97 | 135 |
|
98 |
| -multitask(release: [:build]) do |
| 136 | +desc("Release ruby gem") |
| 137 | +multitask(release: [:"build:gem"]) do |
99 | 138 | sh(*%w[gem push], *FileList["openai-*.gem"])
|
100 | 139 | end
|
0 commit comments