Skip to content

Commit ba52ece

Browse files
committed
update-portable-ruby: hide and consolidate into one-shot
Rewrites `update-portable-ruby` as a single hidden command that reads the `portable-ruby` formula, writes vendor files, runs `brew vendor-install ruby`, then syncs `utils/ruby.sh`, vendored gems and RBI files via the new `Utils::PortableRuby.sync_bundler_version!` helper. Drops `--dry-run` and `--skip-vendor-install` and hides from `brew help` since this is now meant to be invoked from the homebrew-core bottle-publish workflow rather than by hand. Also scopes the `actions/create-github-app-token` permissions in `vendor-gems.yml` to `contents: write`.
1 parent 9b25148 commit ba52ece

3 files changed

Lines changed: 15 additions & 63 deletions

File tree

.github/workflows/vendor-gems.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ jobs:
128128
with:
129129
app-id: ${{ vars.BREW_COMMIT_APP_ID }}
130130
private-key: ${{ secrets.BREW_COMMIT_APP_KEY }}
131+
permission-contents: write
131132

132133
- name: Push to pull request
133134
if: github.event_name == 'workflow_dispatch'

Library/Homebrew/dev-cmd/update-portable-ruby.rb

Lines changed: 13 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -4,88 +4,48 @@
44
require "abstract_command"
55
require "formula"
66
require "utils/bottles"
7+
require "utils/portable_ruby"
78

89
module Homebrew
910
module DevCmd
1011
class UpdatePortableRuby < AbstractCommand
1112
cmd_args do
1213
description <<~EOS
13-
Update the vendored portable Ruby version files, bottle checksums,
14-
`utils/ruby.sh` and `Gemfile.lock` entries from the current
15-
`portable-ruby` formula.
14+
Update the vendored `portable-ruby` from the current `portable-ruby` formula:
15+
write the version files and bottle checksums, run `brew vendor-install ruby`,
16+
then sync `utils/ruby.sh`, vendored gems and RBI files to the bundler shipped
17+
by the new ruby.
1618
EOS
17-
switch "-n", "--dry-run",
18-
description: "Print what would be done rather than doing it."
19-
switch "--skip-vendor-install",
20-
description: "Do not run `brew vendor-install ruby`; skip the `utils/ruby.sh`, " \
21-
"`Gemfile.lock` and RBI updates."
22-
2319
named_args :none
20+
21+
hide_from_man_page!
2422
end
2523

2624
sig { override.void }
2725
def run
2826
formula = Homebrew.with_no_api_env { Formulary.factory("portable-ruby") }
29-
3027
version = formula.version.to_s
3128
pkg_version = formula.pkg_version.to_s
3229
vendor_dir = HOMEBREW_LIBRARY_PATH/"vendor"
3330

34-
write_file(vendor_dir/"portable-ruby-version", "#{pkg_version}\n")
35-
write_file(HOMEBREW_LIBRARY_PATH/".ruby-version", "#{version}\n")
31+
(vendor_dir/"portable-ruby-version").atomic_write("#{pkg_version}\n")
32+
(HOMEBREW_LIBRARY_PATH/".ruby-version").atomic_write("#{version}\n")
3633

3734
formula.bottle_specification.checksums.each do |checksum|
3835
tag_symbol = checksum.fetch("tag")
3936
tag = Utils::Bottles::Tag.from_symbol(tag_symbol)
4037
os = tag.linux? ? "linux" : "darwin"
4138
path = vendor_dir/"portable-ruby-#{tag.standardized_arch}-#{os}"
42-
write_file(path, "ruby_TAG=#{tag_symbol}\nruby_SHA=#{checksum.fetch("digest")}\n")
39+
path.atomic_write("ruby_TAG=#{tag_symbol}\nruby_SHA=#{checksum.fetch("digest")}\n")
4340
end
4441

45-
return if args.skip_vendor_install?
46-
47-
if args.dry_run?
48-
ohai "brew vendor-install ruby"
49-
ohai "Would update #{HOMEBREW_LIBRARY_PATH/"utils/ruby.sh"} and #{HOMEBREW_LIBRARY_PATH/"Gemfile.lock"} " \
50-
"with the bundler version shipped by portable-ruby #{pkg_version}."
51-
ohai "brew typecheck --update"
52-
return
53-
end
54-
55-
ohai "brew vendor-install ruby"
5642
safe_system HOMEBREW_BREW_FILE, "vendor-install", "ruby"
5743

58-
bundler_dir = Pathname.glob(vendor_dir/"portable-ruby/#{pkg_version}/lib/ruby/gems/*/gems/bundler-*").first
59-
odie "Cannot find vendored bundler for portable-ruby #{pkg_version}." if bundler_dir.nil?
60-
bundler_version = bundler_dir.basename.to_s.delete_prefix("bundler-")
61-
62-
ruby_sh = HOMEBREW_LIBRARY_PATH/"utils/ruby.sh"
63-
original = ruby_sh.read
64-
updated = original.sub(/(?<=^export HOMEBREW_BUNDLER_VERSION=")[^"]+/, bundler_version)
65-
if original != updated
66-
ohai "Writing #{ruby_sh}"
67-
ruby_sh.atomic_write(updated)
68-
end
69-
70-
ohai "brew vendor-gems --no-commit --update=--ruby,--bundler=#{bundler_version}"
71-
safe_system HOMEBREW_BREW_FILE, "vendor-gems", "--no-commit", "--update=--ruby,--bundler=#{bundler_version}"
72-
73-
ohai "brew typecheck --update"
44+
bundler_version = Utils::PortableRuby.sync_bundler_version!(pkg_version)
45+
safe_system HOMEBREW_BREW_FILE, "vendor-gems", "--no-commit",
46+
"--update=--ruby,--bundler=#{bundler_version}"
7447
safe_system HOMEBREW_BREW_FILE, "typecheck", "--update"
7548
end
76-
77-
private
78-
79-
sig { params(path: Pathname, contents: String).void }
80-
def write_file(path, contents)
81-
if args.dry_run?
82-
ohai "Write #{path}:"
83-
puts contents
84-
else
85-
ohai "Writing #{path}"
86-
path.atomic_write(contents)
87-
end
88-
end
8949
end
9050
end
9151
end

Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/update_portable_ruby.rbi

Lines changed: 1 addition & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)