Merge pull request #17110 from Homebrew/tap-new-improvements

dev-cmd/tap-new: various improvements
This commit is contained in:
Mike McQuaid 2024-04-21 19:56:11 +01:00 committed by GitHub
commit 2ab0af6f59
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -36,6 +36,7 @@ module Homebrew
tap = args.named.to_taps.fetch(0) tap = args.named.to_taps.fetch(0)
odie "Invalid tap name '#{tap}'" unless tap.path.to_s.match?(HOMEBREW_TAP_PATH_REGEX) 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_user = tap.user.dup
titleized_repo = tap.repo.dup titleized_repo = tap.repo.dup
@ -62,11 +63,13 @@ module Homebrew
actions_main = <<~YAML actions_main = <<~YAML
name: brew test-bot name: brew test-bot
on: on:
push: push:
branches: branches:
- #{branch} - #{branch}
pull_request: pull_request:
jobs: jobs:
test-bot: test-bot:
strategy: strategy:
@ -79,8 +82,7 @@ module Homebrew
uses: Homebrew/actions/setup-homebrew@master uses: Homebrew/actions/setup-homebrew@master
- name: Cache Homebrew Bundler RubyGems - name: Cache Homebrew Bundler RubyGems
id: cache uses: actions/cache@v4
uses: actions/cache@v3
with: with:
path: ${{ steps.set-up-homebrew.outputs.gems-path }} path: ${{ steps.set-up-homebrew.outputs.gems-path }}
key: ${{ runner.os }}-rubygems-${{ steps.set-up-homebrew.outputs.gems-hash }} key: ${{ runner.os }}-rubygems-${{ steps.set-up-homebrew.outputs.gems-hash }}
@ -92,31 +94,43 @@ module Homebrew
- run: brew test-bot --only-tap-syntax - run: brew test-bot --only-tap-syntax
- run: brew test-bot --only-formulae#{" --root-url=#{root_url}" if root_url} - run: brew test-bot --only-formulae#{" --root-url='#{root_url}'" if root_url}
if: github.event_name == 'pull_request' if: github.event_name == 'pull_request'
- name: Upload bottles as artifact - name: Upload bottles as artifact
if: always() && github.event_name == 'pull_request' if: always() && github.event_name == 'pull_request'
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v4
with: with:
name: bottles name: bottles_${{ matrix.os }}
path: '*.bottle.*' path: '*.bottle.*'
YAML YAML
pr_pull_permissions = {
"contents" => "write",
"pull-requests" => "write",
}
pr_pull_env = {
"HOMEBREW_GITHUB_API_TOKEN" => "${{ github.token }}",
}
if args.github_packages?
pr_pull_permissions["packages"] = "write"
pr_pull_env["HOMEBREW_GITHUB_PACKAGES_TOKEN"] = "${{ github.token }}"
pr_pull_env["HOMEBREW_GITHUB_PACKAGES_USER"] = "${{ github.repository_owner }}"
end
actions_publish = <<~YAML actions_publish = <<~YAML
name: brew pr-pull name: brew pr-pull
on: on:
pull_request_target: pull_request_target:
types: types:
- labeled - labeled
jobs: jobs:
pr-pull: pr-pull:
if: contains(github.event.pull_request.labels.*.name, '#{label}') if: contains(github.event.pull_request.labels.*.name, '#{label}')
runs-on: ubuntu-22.04 runs-on: ubuntu-22.04
permissions: permissions:
contents: write #{pr_pull_permissions.sort.map { |k, v| " #{k}: #{v}" }.join("\n")}
packages: #{args.github_packages? ? "write" : "none"}
pull-requests: write
steps: steps:
- name: Set up Homebrew - name: Set up Homebrew
uses: Homebrew/actions/setup-homebrew@master uses: Homebrew/actions/setup-homebrew@master
@ -126,11 +140,9 @@ module Homebrew
- name: Pull bottles - name: Pull bottles
env: env:
HOMEBREW_GITHUB_API_TOKEN: ${{ github.token }} #{pr_pull_env.sort.map { |k, v| " #{k}: #{v}" }.join("\n")}
HOMEBREW_GITHUB_PACKAGES_TOKEN: ${{ github.token }}
HOMEBREW_GITHUB_PACKAGES_USER: ${{ github.actor }}
PULL_REQUEST: ${{ github.event.pull_request.number }} PULL_REQUEST: ${{ github.event.pull_request.number }}
run: brew pr-pull --debug --tap=$GITHUB_REPOSITORY $PULL_REQUEST run: brew pr-pull --debug --tap="$GITHUB_REPOSITORY" "$PULL_REQUEST"
- name: Push commits - name: Push commits
uses: Homebrew/actions/git-try-push@master uses: Homebrew/actions/git-try-push@master
@ -142,7 +154,7 @@ module Homebrew
if: github.event.pull_request.head.repo.fork == false if: github.event.pull_request.head.repo.fork == false
env: env:
BRANCH: ${{ github.event.pull_request.head.ref }} BRANCH: ${{ github.event.pull_request.head.ref }}
run: git push --delete origin $BRANCH run: git push --delete origin "$BRANCH"
YAML YAML
(tap.path/".github/workflows").mkpath (tap.path/".github/workflows").mkpath