Class: Homebrew::DevCmd::TapNew Private
- Inherits:
-
AbstractCommand
- Object
- AbstractCommand
- Homebrew::DevCmd::TapNew
- Includes:
- FileUtils
- Defined in:
- dev-cmd/tap-new.rb,
sorbet/rbi/dsl/homebrew/dev_cmd/tap_new.rbi
This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.
Defined Under Namespace
Classes: Args
Instance Method Summary collapse
- #args ⇒ Homebrew::DevCmd::TapNew::Args private
- #run ⇒ void private
Methods inherited from AbstractCommand
command, command_name, dev_cmd?, #initialize, parser, ruby_cmd?
Constructor Details
This class inherits a constructor from Homebrew::AbstractCommand
Instance Method Details
#args ⇒ Homebrew::DevCmd::TapNew::Args
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
10 |
# File 'sorbet/rbi/dsl/homebrew/dev_cmd/tap_new.rbi', line 10 def args; end |
#run ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'dev-cmd/tap-new.rb', line 35 def run label = args.pull_label || "pr-pull" branch = args.branch || "main" tap = args.named.to_taps.fetch(0) odie "Invalid tap name '#{tap}'" unless tap.path.to_s.match?(HOMEBREW_TAP_PATH_REGEX) odie "Tap is already installed!" if tap.installed? titleized_user = tap.user.dup titleized_repository = tap.repository.dup titleized_user[0] = titleized_user[0].upcase titleized_repository[0] = titleized_repository[0].upcase root_url = GitHubPackages.root_url(tap.user, "homebrew-#{tap.repository}") if args.github_packages? (tap.path/"Formula").mkpath # FIXME: https://github.com/errata-ai/vale/issues/818 # <!-- vale off --> readme = <<~MARKDOWN # #{titleized_user} #{titleized_repository} ## How do I install these formulae? `brew install #{tap}/<formula>` Or `brew tap #{tap}` and then `brew install <formula>`. Or, in a `brew bundle` `Brewfile`: ```ruby tap "#{tap}" brew "<formula>" ``` ## Documentation `brew help`, `man brew` or check [Homebrew's documentation](https://docs.brew.sh). MARKDOWN # <!-- vale on --> write_path(tap, "README.md", readme) tests_yml = <<~ERB name: brew test-bot on: push: branches: - <%= branch %> pull_request: jobs: test-bot: strategy: matrix: os: [ ubuntu-22.04, macos-13, macos-15 ] runs-on: ${{ matrix.os }} permissions: actions: read checks: read contents: read <% if args.github_packages? -%> packages: read <% end -%> pull-requests: read steps: - name: Set up Homebrew id: set-up-homebrew uses: Homebrew/actions/setup-homebrew@master with: token: ${{ github.token }} - name: Cache Homebrew Bundler RubyGems uses: actions/cache@v4 with: path: ${{ steps.set-up-homebrew.outputs.gems-path }} key: ${{ matrix.os }}-rubygems-${{ steps.set-up-homebrew.outputs.gems-hash }} restore-keys: ${{ matrix.os }}-rubygems- - run: brew test-bot --only-cleanup-before - run: brew test-bot --only-setup - run: brew test-bot --only-tap-syntax <% if args.github_packages? -%> - name: Base64-encode GITHUB_TOKEN for HOMEBREW_DOCKER_REGISTRY_TOKEN id: base64-encode if: github.event_name == 'pull_request' env: TOKEN: ${{ github.token }} run: | base64_token=$(echo -n "${TOKEN}" | base64 | tr -d "\\n") echo "::add-mask::${base64_token}" echo "token=${base64_token}" >> "${GITHUB_OUTPUT}" <% end -%> - run: brew test-bot --only-formulae<% if root_url %> --root-url='<%= root_url %>'<% end %> if: github.event_name == 'pull_request' <% if args.github_packages? -%> env: HOMEBREW_DOCKER_REGISTRY_TOKEN: ${{ steps.base64-encode.outputs.token }} <% end -%> - name: Upload bottles as artifact if: always() && github.event_name == 'pull_request' uses: actions/upload-artifact@v4 with: name: bottles_${{ matrix.os }} path: '*.bottle.*' ERB publish_yml = <<~ERB name: brew pr-pull on: pull_request_target: types: - labeled jobs: pr-pull: if: contains(github.event.pull_request.labels.*.name, '<%= label %>') runs-on: ubuntu-22.04 permissions: actions: read checks: read contents: write issues: read <% if args.github_packages? -%> packages: write <% end -%> pull-requests: write steps: - name: Set up Homebrew uses: Homebrew/actions/setup-homebrew@master with: token: ${{ github.token }} - name: Set up git uses: Homebrew/actions/git-user-config@master - name: Pull bottles env: HOMEBREW_GITHUB_API_TOKEN: ${{ github.token }} <% if args.github_packages? -%> HOMEBREW_GITHUB_PACKAGES_TOKEN: ${{ github.token }} HOMEBREW_GITHUB_PACKAGES_USER: ${{ github.repository_owner }} <% end -%> PULL_REQUEST: ${{ github.event.pull_request.number }} run: brew pr-pull --debug --tap="$GITHUB_REPOSITORY" "$PULL_REQUEST" - name: Push commits uses: Homebrew/actions/git-try-push@master with: branch: <%= branch %> - name: Delete branch if: github.event.pull_request.head.repo.fork == false env: BRANCH: ${{ github.event.pull_request.head.ref }} run: git push --delete origin "$BRANCH" ERB (tap.path/".github/workflows").mkpath write_path(tap, ".github/workflows/tests.yml", ERB.new(tests_yml, trim_mode: "-").result(binding)) write_path(tap, ".github/workflows/publish.yml", ERB.new(publish_yml, trim_mode: "-").result(binding)) unless args.no_git? cd tap.path do |path| Utils::Git.set_name_email! Utils::Git.setup_gpg! # Would be nice to use --initial-branch here but it's not available in # older versions of Git that we support. safe_system "git", "-c", "init.defaultBranch=#{branch}", "init" args = [] git_owner = File.stat(File.join(path, ".git")).uid if git_owner != Process.uid && git_owner == Process.euid # Under Homebrew user model, EUID is permitted to execute commands under the UID. # Root users are never allowed (see brew.sh). args << "-c" << "safe.directory=#{path}" end # Use the configuration of the original user, which will have author information and signing keys. Utils::UID.drop_euid do env = { HOME: Utils::UID.uid_home }.compact env[:TMPDIR] = nil if (tmpdir = ENV.fetch("TMPDIR", nil)) && !File.writable?(tmpdir) with_env(env) do safe_system "git", *args, "add", "--all" safe_system "git", *args, "commit", "-m", "Create #{tap} tap" safe_system "git", *args, "branch", "-m", branch end end end end ohai "Created #{tap}" puts <<~EOS #{tap.path} When a pull request making changes to a formula (or formulae) becomes green (all checks passed), then you can publish the built bottles. To do so, label your PR as `#{label}` and the workflow will be triggered. EOS end |