portable-ruby: replace update-portable-ruby with a workflow
#19731
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Vendor Gems | |
| on: | |
| pull_request: | |
| paths: | |
| - .github/licensed.yml | |
| - .github/workflows/vendor-gems.yml | |
| - .licenses/** | |
| - Library/Homebrew/dev-cmd/vendor-gems.rb | |
| - Library/Homebrew/Gemfile* | |
| push: | |
| paths: | |
| - .github/workflows/vendor-gems.yml | |
| branches-ignore: | |
| - main | |
| - master | |
| workflow_dispatch: | |
| inputs: | |
| pull_request: | |
| description: Pull request number | |
| required: true | |
| permissions: | |
| contents: read | |
| pull-requests: read | |
| defaults: | |
| run: | |
| shell: bash -xeuo pipefail {0} | |
| jobs: | |
| vendor-gems: | |
| if: github.repository_owner == 'Homebrew' | |
| runs-on: macos-26 | |
| steps: | |
| - name: Set up Homebrew | |
| id: set-up-homebrew | |
| uses: Homebrew/actions/setup-homebrew@main | |
| with: | |
| core: false | |
| cask: false | |
| - name: Configure Git user | |
| if: github.event_name == 'workflow_dispatch' | |
| uses: Homebrew/actions/git-user-config@main | |
| with: | |
| username: BrewTestBot | |
| - name: Set up commit signing | |
| if: github.event_name == 'workflow_dispatch' | |
| uses: Homebrew/actions/setup-commit-signing@main | |
| with: | |
| signing_key: ${{ secrets.BREWTESTBOT_SSH_SIGNING_KEY }} | |
| - name: Check out pull request | |
| id: checkout | |
| if: github.event_name == 'workflow_dispatch' | |
| run: | | |
| gh pr checkout "${PR}" | |
| branch="$(git branch --show-current)" | |
| echo "branch=${branch}" >> "$GITHUB_OUTPUT" | |
| gem_name="$(echo "${branch}" | sed -E 's|.*/||;s|(.*)-.*$|\1|')" | |
| echo "gem_name=${gem_name}" >> "$GITHUB_OUTPUT" | |
| env: | |
| PR: ${{ github.event.pull_request.number || github.event.inputs.pull_request }} | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| working-directory: ${{ steps.set-up-homebrew.outputs.repository-path }} | |
| - name: Vendor Gems | |
| run: | | |
| if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]] | |
| then | |
| brew vendor-gems --non-bundler-gems | |
| else | |
| brew vendor-gems --non-bundler-gems --no-commit | |
| fi | |
| - name: Install CMake and Licensed | |
| uses: Homebrew/actions/cache-homebrew-prefix@main | |
| with: | |
| install: cmake licensed | |
| workflow-key: vendor-gems-licensed | |
| uninstall: true | |
| - name: Update RubyGems licence metadata | |
| working-directory: ${{ steps.set-up-homebrew.outputs.repository-path }} | |
| run: | | |
| BUNDLE_WITH="$(brew ruby -- -e 'require "utils/gem_setup"; puts Homebrew.valid_gem_groups.join(":")')" | |
| export BUNDLE_WITH | |
| licensed cache --config .github/licensed.yml | |
| licensed status --config .github/licensed.yml | |
| - name: Commit licence metadata changes | |
| if: github.event_name == 'workflow_dispatch' | |
| env: | |
| GEM_NAME: ${{ steps.checkout.outputs.gem_name }} | |
| working-directory: ${{ steps.set-up-homebrew.outputs.repository-path }} | |
| run: | | |
| if [[ -n "$(git status --porcelain -- ".licenses")" ]] | |
| then | |
| git add ".licenses" | |
| git commit -m "Update RubyGems licence metadata for ${GEM_NAME}." \ | |
| -m "Autogenerated by the [vendor-gems](https://github.com/Homebrew/brew/blob/HEAD/.github/workflows/vendor-gems.yml) workflow." | |
| fi | |
| - name: Update RBI files | |
| run: brew typecheck --update | |
| - name: Commit RBI changes | |
| if: github.event_name == 'workflow_dispatch' | |
| env: | |
| GEM_NAME: ${{ steps.checkout.outputs.gem_name }} | |
| working-directory: ${{ steps.set-up-homebrew.outputs.repository-path }} | |
| run: | | |
| if [[ -n "$(git status --porcelain -- "Library/Homebrew/sorbet")" ]] | |
| then | |
| git add "Library/Homebrew/sorbet" | |
| git commit -m "Update RBI files for ${GEM_NAME}." \ | |
| -m "Autogenerated by the [vendor-gems](https://github.com/Homebrew/brew/blob/HEAD/.github/workflows/vendor-gems.yml) workflow." | |
| fi | |
| - name: Generate push token | |
| uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0 | |
| id: app-token | |
| if: github.event_name == 'workflow_dispatch' | |
| with: | |
| app-id: ${{ vars.BREW_COMMIT_APP_ID }} | |
| private-key: ${{ secrets.BREW_COMMIT_APP_KEY }} | |
| permission-contents: write | |
| - name: Push to pull request | |
| if: github.event_name == 'workflow_dispatch' | |
| uses: Homebrew/actions/git-try-push@main | |
| with: | |
| token: ${{ steps.app-token.outputs.token }} | |
| directory: ${{ steps.set-up-homebrew.outputs.repository-path }} | |
| branch: ${{ steps.checkout.outputs.branch }} | |
| force: true | |
| - name: Check vendor and RBI files are in sync | |
| if: github.event_name == 'pull_request' | |
| working-directory: ${{ steps.set-up-homebrew.outputs.repository-path }} | |
| run: | | |
| status="$(git status --porcelain -- .licenses Library/Homebrew/vendor/bundle Library/Homebrew/sorbet)" | |
| if [ -n "${status}" ] | |
| then | |
| { | |
| echo "::error::Vendored gems, license metadata and/or RBI files are out of date." | |
| echo "Run 'brew vendor-gems && brew typecheck --update' (or trigger the 'Bump portable-ruby' workflow for portable-ruby bumps) and commit the changes." | |
| echo "RubyGems licence metadata is refreshed by this workflow." | |
| echo | |
| echo "${status}" | |
| } >&2 | |
| exit 1 | |
| fi |