vendor-gems.yml 2.6 KB
Newer Older
Markus Reiter's avatar
Markus Reiter 已提交
1
2
3
name: Vendor Gems

on:
4
  pull_request_target:
Markus Reiter's avatar
Markus Reiter 已提交
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
  workflow_dispatch:
    inputs:
      pull_request:
        description: Pull request number
        required: true

jobs:
  vendor-gems:
    if: >
      startsWith(github.repository, 'Homebrew/') && (
        github.event_name == 'workflow_dispatch' || (
          github.event.pull_request.user.login == 'dependabot[bot]' &&
          contains(github.event.pull_request.title, '/Library/Homebrew')
        )
      )
20
    runs-on: macos-latest
Markus Reiter's avatar
Markus Reiter 已提交
21
22
23
24
    steps:
      - name: Set up Homebrew
        id: set-up-homebrew
        uses: Homebrew/actions/setup-homebrew@master
Markus Reiter's avatar
Markus Reiter 已提交
25
26
      - name: Set up Xcode
        run: sudo xcode-select --switch /Applications/Xcode_12.2.app/Contents/Developer
Markus Reiter's avatar
Markus Reiter 已提交
27
28
29
30
      - name: Configure Git user
        uses: Homebrew/actions/git-user-config@master
        with:
          username: BrewTestBot
31
32
33
34
      - name: Set up commit signing
        uses: Homebrew/actions/setup-commit-signing@master
        with:
          signing_key: ${{ secrets.BREWTESTBOT_GPG_SIGNING_SUBKEY }}
Markus Reiter's avatar
Markus Reiter 已提交
35
      - name: Check out pull request
36
        id: checkout
Markus Reiter's avatar
Markus Reiter 已提交
37
38
        run: |
          gh pr checkout '${{ github.event.pull_request.number || github.event.inputs.pull_request }}'
39
40
41
42
43
44

          branch="$(git branch --show-current)"
          echo "::set-output name=branch::${branch}"

          gem_name="$(echo "${branch}" | sed -E 's|.*/||;s|(.*)-.*$|\1|')"
          echo "::set-output name=gem_name::${gem_name}"
Markus Reiter's avatar
Markus Reiter 已提交
45
46
47
        env:
          GITHUB_TOKEN: ${{ secrets.HOMEBREW_GITHUB_API_TOKEN }}
      - name: Vendor Gems
48
49
        env:
          GEM_NAME: ${{ steps.checkout.outputs.gem_name }}
nandahkrishna's avatar
nandahkrishna 已提交
50
          HOMEBREW_GPG_PASSPHRASE: ${{ secrets.BREWTESTBOT_GPG_SIGNING_SUBKEY_PASSPHRASE }}
Markus Reiter's avatar
Markus Reiter 已提交
51
        run: |
52
53
54
          set -u

          if [[ "${GEM_NAME}" == 'sorbet' ]]; then
55
56
57
58
            brew vendor-gems --update sorbet,sorbet-runtime
          else
            brew vendor-gems
          fi
Markus Reiter's avatar
Markus Reiter 已提交
59
      - name: Update RBI files
60
61
        env:
          GEM_NAME: ${{ steps.checkout.outputs.gem_name }}
nandahkrishna's avatar
nandahkrishna 已提交
62
          HOMEBREW_GPG_PASSPHRASE: ${{ secrets.BREWTESTBOT_GPG_SIGNING_SUBKEY_PASSPHRASE }}
Markus Reiter's avatar
Markus Reiter 已提交
63
        run: |
64
65
          set -u

Markus Reiter's avatar
Markus Reiter 已提交
66
67
          if brew typecheck --update --fail-if-not-changed; then
            if git add Library/Homebrew/sorbet; then
68
              git commit -m "Update RBI files for ${GEM_NAME}."
Markus Reiter's avatar
Markus Reiter 已提交
69
70
71
72
73
74
75
76
            fi

            git reset --hard
          fi
      - name: Push to pull request
        uses: Homebrew/actions/git-try-push@master
        with:
          token: ${{ secrets.HOMEBREW_GITHUB_API_TOKEN }}
77
          branch: ${{ steps.checkout.outputs.branch }}
Markus Reiter's avatar
Markus Reiter 已提交
78
          force: true