Skip to content

Commit c3374c6

Browse files
committed
portable-ruby: replace update-portable-ruby with a workflow
Drops the `brew update-portable-ruby` dev-cmd in favour of a new `bump-portable-ruby.yml` workflow that reads the published `portable-ruby` formula's bottle spec, regenerates the vendored state, and opens a brew bump PR as `BrewTestBot`. Fires via `repository_dispatch` from a paired homebrew-core PR, with `workflow_dispatch` as a manual fallback. Also scopes the `actions/create-github-app-token` permissions in this workflow and `vendor-gems.yml` to just what they need, and updates a stale `vendor-gems.yml` error-message reference.
1 parent 2af08a7 commit c3374c6

11 files changed

Lines changed: 163 additions & 187 deletions

File tree

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
name: Bump portable-ruby
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
portable_ruby_pr:
7+
description: "homebrew-core PR number that bumped portable-ruby"
8+
type: string
9+
required: false
10+
repository_dispatch:
11+
types: [portable-ruby-published]
12+
13+
concurrency:
14+
group: ${{ github.workflow }}
15+
cancel-in-progress: false
16+
17+
permissions:
18+
contents: read
19+
pull-requests: write
20+
21+
defaults:
22+
run:
23+
shell: bash -xeuo pipefail {0}
24+
25+
jobs:
26+
open-pr:
27+
if: github.repository_owner == 'Homebrew'
28+
runs-on: macos-26
29+
steps:
30+
- name: Set up Homebrew
31+
id: set-up-homebrew
32+
uses: Homebrew/actions/setup-homebrew@main
33+
with:
34+
core: true
35+
cask: false
36+
37+
- name: Configure Git user
38+
uses: Homebrew/actions/git-user-config@main
39+
with:
40+
username: BrewTestBot
41+
42+
- name: Set up commit signing
43+
uses: Homebrew/actions/setup-commit-signing@main
44+
with:
45+
signing_key: ${{ secrets.BREWTESTBOT_SSH_SIGNING_KEY }}
46+
47+
- name: Resolve target version
48+
id: resolve
49+
working-directory: ${{ steps.set-up-homebrew.outputs.repository-path }}
50+
run: |
51+
pkg_version="$(brew ruby -- -e 'puts Homebrew.with_no_api_env { Formulary.factory("portable-ruby") }.pkg_version.to_s')"
52+
version="$(brew ruby -- -e 'puts Homebrew.with_no_api_env { Formulary.factory("portable-ruby") }.version.to_s')"
53+
{
54+
echo "pkg_version=${pkg_version}"
55+
echo "version=${version}"
56+
echo "branch=bump-portable-ruby-${pkg_version}"
57+
} >> "$GITHUB_OUTPUT"
58+
59+
- name: Create branch
60+
working-directory: ${{ steps.set-up-homebrew.outputs.repository-path }}
61+
env:
62+
BRANCH: ${{ steps.resolve.outputs.branch }}
63+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
64+
run: |
65+
if gh api "repos/${GITHUB_REPOSITORY}/branches/${BRANCH}" >/dev/null 2>&1
66+
then
67+
echo "::error::Branch ${BRANCH} already exists. Delete it or use the existing PR."
68+
exit 1
69+
fi
70+
git checkout -b "${BRANCH}"
71+
72+
- name: Write vendor files from `portable-ruby` formula
73+
working-directory: ${{ steps.set-up-homebrew.outputs.repository-path }}
74+
run: |
75+
brew ruby -- -e '
76+
formula = Homebrew.with_no_api_env { Formulary.factory("portable-ruby") }
77+
version = formula.version.to_s
78+
pkg_version = formula.pkg_version.to_s
79+
vendor_dir = HOMEBREW_LIBRARY_PATH/"vendor"
80+
81+
(vendor_dir/"portable-ruby-version").atomic_write("#{pkg_version}\n")
82+
(HOMEBREW_LIBRARY_PATH/".ruby-version").atomic_write("#{version}\n")
83+
84+
formula.bottle_specification.checksums.each do |checksum|
85+
tag_symbol = checksum.fetch("tag")
86+
tag = Utils::Bottles::Tag.from_symbol(tag_symbol)
87+
os = tag.linux? ? "linux" : "darwin"
88+
path = vendor_dir/"portable-ruby-#{tag.standardized_arch}-#{os}"
89+
path.atomic_write("ruby_TAG=#{tag_symbol}\nruby_SHA=#{checksum.fetch("digest")}\n")
90+
end
91+
'
92+
93+
- name: brew vendor-install ruby
94+
working-directory: ${{ steps.set-up-homebrew.outputs.repository-path }}
95+
run: brew vendor-install ruby
96+
97+
- name: Sync bundler version, vendored gems, and RBI files
98+
working-directory: ${{ steps.set-up-homebrew.outputs.repository-path }}
99+
env:
100+
PKG_VERSION: ${{ steps.resolve.outputs.pkg_version }}
101+
run: |
102+
bundler_version="$(brew ruby -- -e "require 'utils/portable_ruby'; puts Utils::PortableRuby.sync_bundler_version!(ENV.fetch('PKG_VERSION'))")"
103+
brew vendor-gems --no-commit --update=--ruby,--bundler="${bundler_version}"
104+
brew typecheck --update
105+
106+
- name: Commit changes
107+
id: commit
108+
working-directory: ${{ steps.set-up-homebrew.outputs.repository-path }}
109+
env:
110+
PKG_VERSION: ${{ steps.resolve.outputs.pkg_version }}
111+
run: |
112+
git add -A
113+
if git diff --cached --quiet
114+
then
115+
echo "::notice::No changes to commit; portable-ruby ${PKG_VERSION} is already vendored."
116+
echo "changes=false" >> "$GITHUB_OUTPUT"
117+
exit 0
118+
fi
119+
git commit -m "Bump portable-ruby to ${PKG_VERSION}." \
120+
-m "Autogenerated by the [bump-portable-ruby](https://github.com/Homebrew/brew/blob/HEAD/.github/workflows/bump-portable-ruby.yml) workflow."
121+
echo "changes=true" >> "$GITHUB_OUTPUT"
122+
123+
- name: Generate push token
124+
if: steps.commit.outputs.changes == 'true'
125+
id: app-token
126+
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
127+
with:
128+
app-id: ${{ vars.BREW_COMMIT_APP_ID }}
129+
private-key: ${{ secrets.BREW_COMMIT_APP_KEY }}
130+
permission-contents: write
131+
permission-pull-requests: write
132+
133+
- name: Push branch
134+
if: steps.commit.outputs.changes == 'true'
135+
uses: Homebrew/actions/git-try-push@main
136+
with:
137+
token: ${{ steps.app-token.outputs.token }}
138+
directory: ${{ steps.set-up-homebrew.outputs.repository-path }}
139+
branch: ${{ steps.resolve.outputs.branch }}
140+
141+
- name: Open pull request
142+
if: steps.commit.outputs.changes == 'true'
143+
working-directory: ${{ steps.set-up-homebrew.outputs.repository-path }}
144+
env:
145+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
146+
PKG_VERSION: ${{ steps.resolve.outputs.pkg_version }}
147+
BRANCH: ${{ steps.resolve.outputs.branch }}
148+
SOURCE_PR: ${{ inputs.portable_ruby_pr || github.event.client_payload.portable_ruby_pr }}
149+
run: |
150+
body="Bumps the vendored \`portable-ruby\` to ${PKG_VERSION}."
151+
if [[ -n "${SOURCE_PR}" ]]
152+
then
153+
body="${body}"$'\n\nSource: Homebrew/homebrew-core#'"${SOURCE_PR}"
154+
fi
155+
body="${body}"$'\n\nAutogenerated by the [bump-portable-ruby](https://github.com/Homebrew/brew/blob/HEAD/.github/workflows/bump-portable-ruby.yml) workflow.'
156+
157+
gh pr create \
158+
--base main \
159+
--head "${BRANCH}" \
160+
--title "Bump vendored portable-ruby to ${PKG_VERSION}" \
161+
--body "${body}"

.github/workflows/vendor-gems.yml

Lines changed: 2 additions & 1 deletion
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'
@@ -147,7 +148,7 @@ jobs:
147148
then
148149
{
149150
echo "::error::Vendored gems, license metadata and/or RBI files are out of date."
150-
echo "Run 'brew vendor-gems && brew typecheck --update' (or 'brew update-portable-ruby' for portable-ruby bumps) and commit the changes."
151+
echo "Run 'brew vendor-gems && brew typecheck --update' (or trigger the 'Bump portable-ruby' workflow for portable-ruby bumps) and commit the changes."
151152
echo "RubyGems licence metadata is refreshed by this workflow."
152153
echo
153154
echo "${status}"

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

Lines changed: 0 additions & 91 deletions
This file was deleted.

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

Lines changed: 0 additions & 22 deletions
This file was deleted.

Library/Homebrew/test/dev-cmd/update-portable-ruby_spec.rb

Lines changed: 0 additions & 9 deletions
This file was deleted.

completions/bash/brew

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3156,24 +3156,6 @@ _brew_update_perl_resources() {
31563156
__brew_complete_formulae
31573157
}
31583158

3159-
_brew_update_portable_ruby() {
3160-
local cur="${COMP_WORDS[COMP_CWORD]}"
3161-
case "${cur}" in
3162-
-*)
3163-
__brewcomp "
3164-
--debug
3165-
--dry-run
3166-
--help
3167-
--quiet
3168-
--skip-vendor-install
3169-
--verbose
3170-
"
3171-
return
3172-
;;
3173-
*) ;;
3174-
esac
3175-
}
3176-
31773159
_brew_update_python_resources() {
31783160
local cur="${COMP_WORDS[COMP_CWORD]}"
31793161
case "${cur}" in
@@ -3577,7 +3559,6 @@ _brew() {
35773559
update-license-data) _brew_update_license_data ;;
35783560
update-maintainers) _brew_update_maintainers ;;
35793561
update-perl-resources) _brew_update_perl_resources ;;
3580-
update-portable-ruby) _brew_update_portable_ruby ;;
35813562
update-python-resources) _brew_update_python_resources ;;
35823563
update-reset) _brew_update_reset ;;
35833564
update-sponsors) _brew_update_sponsors ;;

completions/fish/brew.fish

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,15 +1986,6 @@ __fish_brew_complete_arg 'update-perl-resources' -l verbose -d 'Make some output
19861986
__fish_brew_complete_arg 'update-perl-resources' -a '(__fish_brew_suggest_formulae_all)'
19871987

19881988

1989-
__fish_brew_complete_cmd 'update-portable-ruby' 'Update the vendored portable Ruby version files, bottle checksums, `utils/ruby.sh` and `Gemfile.lock` entries from the current `portable-ruby` formula'
1990-
__fish_brew_complete_arg 'update-portable-ruby' -l debug -d 'Display any debugging information'
1991-
__fish_brew_complete_arg 'update-portable-ruby' -l dry-run -d 'Print what would be done rather than doing it'
1992-
__fish_brew_complete_arg 'update-portable-ruby' -l help -d 'Show this message'
1993-
__fish_brew_complete_arg 'update-portable-ruby' -l quiet -d 'Make some output more quiet'
1994-
__fish_brew_complete_arg 'update-portable-ruby' -l skip-vendor-install -d 'Do not run `brew vendor-install ruby`; skip the `utils/ruby.sh`, `Gemfile.lock` and RBI updates'
1995-
__fish_brew_complete_arg 'update-portable-ruby' -l verbose -d 'Make some output more verbose'
1996-
1997-
19981989
__fish_brew_complete_cmd 'update-python-resources' 'Update versions for PyPI resource blocks in formula'
19991990
__fish_brew_complete_arg 'update-python-resources' -l debug -d 'Display any debugging information'
20001991
__fish_brew_complete_arg 'update-python-resources' -l exclude-packages -d 'Exclude these packages when finding resources'

completions/internal_commands_list.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ update-if-needed
110110
update-license-data
111111
update-maintainers
112112
update-perl-resources
113-
update-portable-ruby
114113
update-python-resources
115114
update-reset
116115
update-sponsors

completions/zsh/_brew

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,6 @@ __brew_internal_commands() {
245245
'update-license-data:Update SPDX license data in the Homebrew repository'
246246
'update-maintainers:Update the list of maintainers in the `Homebrew/brew` README'
247247
'update-perl-resources:Update versions for CPAN resource blocks in formula'
248-
'update-portable-ruby:Update the vendored portable Ruby version files, bottle checksums, `utils/ruby.sh` and `Gemfile.lock` entries from the current `portable-ruby` formula'
249248
'update-python-resources:Update versions for PyPI resource blocks in formula'
250249
'update-reset:Fetch and reset Homebrew and all tap repositories (or any specified repository) using `git`(1) to their latest `origin/HEAD`'
251250
'update-sponsors:Update the list of GitHub Sponsors in the `Homebrew/brew` README'
@@ -2534,17 +2533,6 @@ _brew_update_perl_resources() {
25342533
'*:formula:__brew_formulae'
25352534
}
25362535

2537-
# brew update-portable-ruby
2538-
_brew_update_portable_ruby() {
2539-
_arguments \
2540-
'--debug[Display any debugging information]' \
2541-
'--dry-run[Print what would be done rather than doing it]' \
2542-
'--help[Show this message]' \
2543-
'--quiet[Make some output more quiet]' \
2544-
'--skip-vendor-install[Do not run `brew vendor-install ruby`; skip the `utils/ruby.sh`, `Gemfile.lock` and RBI updates]' \
2545-
'--verbose[Make some output more verbose]'
2546-
}
2547-
25482536
# brew update-python-resources
25492537
_brew_update_python_resources() {
25502538
_arguments \

0 commit comments

Comments
 (0)