Skip to content

Commit

Permalink
Merge pull request #17110 from Homebrew/tap-new-improvements
Browse files Browse the repository at this point in the history
dev-cmd/tap-new: various improvements
  • Loading branch information
MikeMcQuaid committed Apr 21, 2024
2 parents 8810b7f + ea37708 commit 2ab0af6
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions Library/Homebrew/dev-cmd/tap-new.rb
Expand Up @@ -36,6 +36,7 @@ def run

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_repo = tap.repo.dup
Expand All @@ -62,11 +63,13 @@ def run

actions_main = <<~YAML
name: brew test-bot
on:
push:
branches:
- #{branch}
pull_request:
jobs:
test-bot:
strategy:
Expand All @@ -79,8 +82,7 @@ def run
uses: Homebrew/actions/setup-homebrew@master
- name: Cache Homebrew Bundler RubyGems
id: cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ steps.set-up-homebrew.outputs.gems-path }}
key: ${{ runner.os }}-rubygems-${{ steps.set-up-homebrew.outputs.gems-hash }}
Expand All @@ -92,31 +94,43 @@ def run
- 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'
- name: Upload bottles as artifact
if: always() && github.event_name == 'pull_request'
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: bottles
name: bottles_${{ matrix.os }}
path: '*.bottle.*'
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
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:
contents: write
packages: #{args.github_packages? ? "write" : "none"}
pull-requests: write
#{pr_pull_permissions.sort.map { |k, v| " #{k}: #{v}" }.join("\n")}
steps:
- name: Set up Homebrew
uses: Homebrew/actions/setup-homebrew@master
Expand All @@ -126,11 +140,9 @@ def run
- name: Pull bottles
env:
HOMEBREW_GITHUB_API_TOKEN: ${{ github.token }}
HOMEBREW_GITHUB_PACKAGES_TOKEN: ${{ github.token }}
HOMEBREW_GITHUB_PACKAGES_USER: ${{ github.actor }}
#{pr_pull_env.sort.map { |k, v| " #{k}: #{v}" }.join("\n")}
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
uses: Homebrew/actions/git-try-push@master
Expand All @@ -142,7 +154,7 @@ def run
if: github.event.pull_request.head.repo.fork == false
env:
BRANCH: ${{ github.event.pull_request.head.ref }}
run: git push --delete origin $BRANCH
run: git push --delete origin "$BRANCH"
YAML

(tap.path/".github/workflows").mkpath
Expand Down

0 comments on commit 2ab0af6

Please sign in to comment.