Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev-cmd/tap-new: various improvements #17110

Merged
merged 5 commits into from Apr 21, 2024
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 13 additions & 9 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,23 +94,25 @@ 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

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}')
Expand All @@ -127,10 +131,10 @@ def run
- name: Pull bottles
env:
HOMEBREW_GITHUB_API_TOKEN: ${{ github.token }}
HOMEBREW_GITHUB_PACKAGES_TOKEN: ${{ github.token }}
HOMEBREW_GITHUB_PACKAGES_USER: ${{ github.actor }}
HOMEBREW_GITHUB_PACKAGES_TOKEN: #{args.github_packages? ? "${{ github.token }}" : "null"}
HOMEBREW_GITHUB_PACKAGES_USER: #{args.github_packages? ? "${{ github.repository_owner }}" : "null"}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the advantage in using null here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sort of similar to how fine-grained tokens are configured, I think it's preferred not to set an environment variable when it's not needed. Though, technically this should already have been restricted via the permissions above with packages: none.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is skill going to set the variable but just to a null value which seems weird. Nicer to make the output of both of these a single conditional perhaps?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is skill going to set the variable but just to a null value which seems weird.

It's actually null really, because it's interpreted as a YAML null.

Nicer to make the output of both of these a single conditional perhaps?

ea37708 should hopefully make it better by not setting those variables at all.

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 +146,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