2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-04-01 16:47:30 +05:30
|
|
|
require "tap"
|
2019-04-17 18:25:08 +09:00
|
|
|
require "cli/parser"
|
2018-04-01 16:47:30 +05:30
|
|
|
|
2016-10-13 13:41:53 +01:00
|
|
|
module Homebrew
|
|
|
|
module_function
|
|
|
|
|
2018-07-30 18:25:38 +05:30
|
|
|
def tap_new_args
|
|
|
|
Homebrew::CLI::Parser.new do
|
2018-09-28 21:39:52 +05:30
|
|
|
usage_banner <<~EOS
|
2018-10-15 15:06:33 -04:00
|
|
|
`tap-new` <user>`/`<repo>
|
2018-10-02 19:54:22 +05:30
|
|
|
|
2018-09-28 21:39:52 +05:30
|
|
|
Generate the template files for a new tap.
|
|
|
|
EOS
|
2020-07-30 18:40:10 +02:00
|
|
|
|
2020-03-04 17:28:24 +00:00
|
|
|
named 1
|
2018-04-01 16:47:30 +05:30
|
|
|
end
|
2018-07-30 18:25:38 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def tap_new
|
2020-07-30 18:40:10 +02:00
|
|
|
args = tap_new_args.parse
|
2018-04-01 16:47:30 +05:30
|
|
|
|
2020-06-12 11:42:40 +01:00
|
|
|
tap_name = args.named.first
|
2020-03-04 17:28:24 +00:00
|
|
|
tap = Tap.fetch(args.named.first)
|
2020-06-12 11:42:40 +01:00
|
|
|
raise "Invalid tap name '#{tap_name}'" unless tap.path.to_s.match?(HOMEBREW_TAP_PATH_REGEX)
|
|
|
|
|
2016-10-13 13:41:53 +01:00
|
|
|
titleized_user = tap.user.dup
|
|
|
|
titleized_repo = tap.repo.dup
|
|
|
|
titleized_user[0] = titleized_user[0].upcase
|
|
|
|
titleized_repo[0] = titleized_repo[0].upcase
|
|
|
|
|
|
|
|
(tap.path/"Formula").mkpath
|
|
|
|
|
2018-07-11 15:17:40 +02:00
|
|
|
readme = <<~MARKDOWN
|
2016-10-13 13:41:53 +01:00
|
|
|
# #{titleized_user} #{titleized_repo}
|
|
|
|
|
|
|
|
## How do I install these formulae?
|
|
|
|
`brew install #{tap}/<formula>`
|
|
|
|
|
|
|
|
Or `brew tap #{tap}` and then `brew install <formula>`.
|
|
|
|
|
|
|
|
## Documentation
|
2017-07-27 15:59:37 +01:00
|
|
|
`brew help`, `man brew` or check [Homebrew's documentation](https://docs.brew.sh).
|
2018-07-11 15:17:40 +02:00
|
|
|
MARKDOWN
|
2016-10-13 13:41:53 +01:00
|
|
|
write_path(tap, "README.md", readme)
|
|
|
|
|
2020-02-15 17:27:13 +00:00
|
|
|
actions = <<~YAML
|
|
|
|
name: brew test-bot
|
|
|
|
on:
|
|
|
|
push:
|
|
|
|
branches: master
|
|
|
|
pull_request: []
|
2018-12-30 21:13:24 +00:00
|
|
|
jobs:
|
2020-02-15 17:27:13 +00:00
|
|
|
test-bot:
|
2020-08-05 20:10:09 +01:00
|
|
|
runs-on: ${{ matrix.os }}
|
|
|
|
strategy:
|
|
|
|
matrix:
|
|
|
|
os: [ubuntu-latest, macOS-latest]
|
2020-02-15 17:27:13 +00:00
|
|
|
steps:
|
2020-08-04 11:57:39 +01:00
|
|
|
- name: Set up Homebrew
|
2020-08-05 20:10:09 +01:00
|
|
|
uses: Homebrew/actions/setup-homebrew@master
|
|
|
|
|
|
|
|
- name: Cache Homebrew Bundler RubyGems
|
|
|
|
id: cache
|
2020-08-06 19:35:29 +01:00
|
|
|
uses: actions/cache@main
|
2020-08-05 20:10:09 +01:00
|
|
|
with:
|
|
|
|
path: ${{ steps.set-up-homebrew.outputs.gems-path }}
|
|
|
|
key: ${{ runner.os }}-rubygems-${{ steps.set-up-homebrew.outputs.gems-hash }}
|
|
|
|
restore-keys: ${{ runner.os }}-rubygems-
|
|
|
|
|
|
|
|
- name: Install Homebrew Bundler RubyGems
|
|
|
|
if: steps.cache.outputs.cache-hit != 'true'
|
|
|
|
run: brew install-bundler-gems
|
2020-08-04 11:57:39 +01:00
|
|
|
|
|
|
|
- name: Run brew test-bot --only-cleanup-before
|
|
|
|
run: brew test-bot --only-cleanup-before
|
|
|
|
|
|
|
|
- name: Run brew test-bot --only-setup
|
|
|
|
run: brew test-bot --only-setup
|
|
|
|
|
|
|
|
- name: Run brew test-bot --only-tap-syntax
|
|
|
|
run: brew test-bot --only-tap-syntax
|
|
|
|
|
|
|
|
- name: Run brew test-bot --only-formulae
|
|
|
|
if: github.event_name == 'pull_request'
|
|
|
|
run: brew test-bot --only-formulae
|
2018-07-11 15:17:40 +02:00
|
|
|
YAML
|
2020-02-15 17:27:13 +00:00
|
|
|
|
|
|
|
(tap.path/".github/workflows").mkpath
|
2020-08-04 11:57:39 +01:00
|
|
|
write_path(tap, ".github/workflows/tests.yml", actions)
|
2019-03-23 12:41:35 +00:00
|
|
|
ohai "Created #{tap}"
|
|
|
|
puts tap.path.to_s
|
2016-10-13 13:41:53 +01:00
|
|
|
end
|
2018-10-08 22:49:03 -04:00
|
|
|
|
|
|
|
def write_path(tap, filename, content)
|
|
|
|
path = tap.path/filename
|
|
|
|
tap.path.mkpath
|
|
|
|
raise "#{path} already exists" if path.exist?
|
|
|
|
|
|
|
|
path.write content
|
|
|
|
end
|
2016-10-13 13:41:53 +01:00
|
|
|
end
|