diff --git a/.github/workflows/tapioca.yml b/.github/workflows/tapioca.yml index a2561d18d7..98761c3240 100644 --- a/.github/workflows/tapioca.yml +++ b/.github/workflows/tapioca.yml @@ -21,17 +21,6 @@ jobs: with: username: BrewTestBot - # TODO: remove with `brew typecheck` - - name: Set up Ruby - uses: actions/setup-ruby@main - with: - ruby-version: '2.6' - - name: Install RubyGems - run: | - cd "$GITHUB_WORKSPACE/Library/Homebrew" - gem install bundler -v "~>1" - bundle install --jobs 4 --retry 3 - - name: Update Tapioca definitions id: update run: | @@ -48,13 +37,7 @@ jobs: BRANCH_EXISTS="1" fi - # TODO: replace with `brew typecheck` - cd "$GITHUB_WORKSPACE/Library/Homebrew" - bundle exec tapioca sync --exclude json - bundle exec srb rbi hidden-definitions - if ! git diff --no-patch --exit-code -- sorbet; then - - # if brew typecheck --update --fail-if-not-changed; then + if brew typecheck --update-definitions --fail-if-not-changed; then git add "$GITHUB_WORKSPACE/Library/Homebrew/sorbet" git commit -m "sorbet: update RBI files using Tapioca." -m "Autogenerated by [a scheduled GitHub Action](https://github.com/Homebrew/brew/blob/master/.github/workflows/tapioca.yml)." echo "::set-output name=committed::true" diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index dffdbb2675..2821cf0271 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -120,6 +120,9 @@ jobs: - name: Run brew audit --skip-style on all taps run: brew audit --skip-style + # TODO: remove --quiet when possible. + - run: brew typecheck --quiet + - name: Run vale for docs linting run: | brew install vale diff --git a/Library/Homebrew/dev-cmd/typecheck.rb b/Library/Homebrew/dev-cmd/typecheck.rb new file mode 100644 index 0000000000..012e2397d3 --- /dev/null +++ b/Library/Homebrew/dev-cmd/typecheck.rb @@ -0,0 +1,62 @@ +# frozen_string_literal: true + +require "cli/parser" + +module Homebrew + module_function + + def typecheck_args + Homebrew::CLI::Parser.new do + usage_banner <<~EOS + `typecheck` + + Check for typechecking errors using Sorbet. + EOS + switch "-q", "--quiet", + description: "Silence all non-critical errors." + switch "--update-definitions", + description: "Update Tapioca gem definitions of recently bumped gems" + switch "--fail-if-not-changed", + description: "Return a failing status code if all gems are up to date " \ + "and gem definitions do not need a tapioca update" + flag "--dir=", + description: "Typecheck all files in a specific directory." + flag "--file=", + description: "Typecheck a single file." + flag "--ignore=", + description: "Ignores input files that contain the given string " \ + "in their paths (relative to the input path passed to Sorbet)." + conflicts "--dir", "--file" + max_named 0 + end + end + + def typecheck + args = typecheck_args.parse + + Homebrew.install_bundler_gems! + + HOMEBREW_LIBRARY_PATH.cd do + if args.update_definitions? + system "bundle", "exec", "tapioca", "sync" + system "bundle", "exec", "srb", "rbi", "hidden-definitions" + + Homebrew.failed = system("git", "diff", "--stat", "--exit-code") if args.fail_if_not_changed? + + return + end + + srb_exec = %w[bundle exec srb tc] + srb_exec << "--quiet" if args.quiet? + srb_exec += ["--ignore", args.ignore] if args.ignore.present? + if args.file.present? || args.dir.present? + cd("sorbet") + srb_exec += ["--file", "../#{args.file}"] if args.file + srb_exec += ["--dir", "../#{args.dir}"] if args.dir + else + srb_exec += ["--typed-override", "sorbet/files.yaml"] + end + Homebrew.failed = !system(*srb_exec) + end + end +end diff --git a/Library/Homebrew/test/dev-cmd/typecheck_spec.rb b/Library/Homebrew/test/dev-cmd/typecheck_spec.rb new file mode 100644 index 0000000000..8fef2f67f1 --- /dev/null +++ b/Library/Homebrew/test/dev-cmd/typecheck_spec.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +require "cmd/shared_examples/args_parse" + +describe "Homebrew.typecheck_args" do + it_behaves_like "parseable arguments" +end diff --git a/completions/internal_commands_list.txt b/completions/internal_commands_list.txt index 474f832272..027f057351 100644 --- a/completions/internal_commands_list.txt +++ b/completions/internal_commands_list.txt @@ -81,6 +81,7 @@ tap-info tap-new test tests +typecheck uninstal uninstall unlink diff --git a/docs/Manpage.md b/docs/Manpage.md index 80584238a1..2124276e6c 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -1178,6 +1178,23 @@ Run Homebrew's unit and integration tests. * `--seed`: Randomise tests with the specified *`value`* instead of a random seed. +### `typecheck` + +Check for typechecking errors using Sorbet. + +* `-q`, `--quiet`: + Silence all non-critical errors. +* `--update-definitions`: + Update Tapioca gem definitions of recently bumped gems +* `--fail-if-not-changed`: + Return a failing status code if all gems are up to date and gem definitions do not need a tapioca update +* `--dir`: + Typecheck all files in a specific directory. +* `--file`: + Typecheck a single file. +* `--ignore`: + Ignores input files that contain the given string in their paths (relative to the input path passed to Sorbet). + ### `unpack` [*`options`*] *`formula`* Unpack the source files for *`formula`* into subdirectories of the current diff --git a/manpages/brew.1 b/manpages/brew.1 index dbfa71b5a5..9826247171 100644 --- a/manpages/brew.1 +++ b/manpages/brew.1 @@ -1610,6 +1610,33 @@ Run only \fItest_script\fR\fB_spec\.rb\fR\. Appending \fB:\fR\fIline_number\fR w \fB\-\-seed\fR Randomise tests with the specified \fIvalue\fR instead of a random seed\. . +.SS "\fBtypecheck\fR" +Check for typechecking errors using Sorbet\. +. +.TP +\fB\-q\fR, \fB\-\-quiet\fR +Silence all non\-critical errors\. +. +.TP +\fB\-\-update\-definitions\fR +Update Tapioca gem definitions of recently bumped gems +. +.TP +\fB\-\-fail\-if\-not\-changed\fR +Return a failing status code if all gems are up to date and gem definitions do not need a tapioca update +. +.TP +\fB\-\-dir\fR +Typecheck all files in a specific directory\. +. +.TP +\fB\-\-file\fR +Typecheck a single file\. +. +.TP +\fB\-\-ignore\fR +Ignores input files that contain the given string in their paths (relative to the input path passed to Sorbet)\. +. .SS "\fBunpack\fR [\fIoptions\fR] \fIformula\fR" Unpack the source files for \fIformula\fR into subdirectories of the current working directory\. .