-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #110 from Homebrew/shared_config_improvements
Improve shared configuration syncing.
- Loading branch information
Showing
3 changed files
with
146 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,78 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
require 'fileutils' | ||
require 'open3' | ||
require 'pathname' | ||
require "English" | ||
require "fileutils" | ||
require "open3" | ||
require "pathname" | ||
|
||
# This makes sense for a standalone script. | ||
# rubocop:disable Style/TopLevelMethodDefinition | ||
def git(*args) | ||
system 'git', *args | ||
exit $?.exitstatus unless $?.success? | ||
system "git", *args | ||
exit $CHILD_STATUS.exitstatus unless $CHILD_STATUS.success? | ||
end | ||
# rubocop:enable Style/TopLevelMethodDefinition | ||
|
||
target_dir = Pathname(ARGV[0]) | ||
source_dir = ARGV[1] | ||
target_directory = ARGV[0] | ||
target_directory_path = Pathname(target_directory) | ||
homebrew_repository_path = Pathname(ARGV[1]) | ||
|
||
puts 'Detecting changes…' | ||
if !target_directory_path.directory? || !homebrew_repository_path.directory? || ARGV[2] | ||
abort "Usage: #{$PROGRAM_NAME} <target_directory_path> <homebrew_repository_path>" | ||
end | ||
|
||
ruby_version = ".ruby-version" | ||
rubocop_yml = ".rubocop.yml" | ||
|
||
homebrew_ruby_version = | ||
(homebrew_repository_path/"Library/Homebrew/vendor/portable-ruby-version").read.chomp.sub(/_\d+$/, "") | ||
homebrew_rubocop_config = homebrew_repository_path/"Library/Homebrew/#{rubocop_yml}" | ||
|
||
puts "Detecting changes…" | ||
[ | ||
'.github/workflows/lock-threads.yml', | ||
'.github/workflows/stale-issues.yml', | ||
'.ruby-version', | ||
].each do |glob| | ||
src_paths = Pathname.glob(glob) | ||
dst_paths = Pathname.glob(target_dir.join(glob)) | ||
|
||
dst_paths.each do |path| | ||
FileUtils.rm_f path | ||
end | ||
ruby_version, | ||
rubocop_yml, | ||
".github/workflows/lock-threads.yml", | ||
".github/workflows/stale-issues.yml", | ||
].each do |file| | ||
target_path = target_directory_path/file | ||
target_path.dirname.mkpath | ||
|
||
src_paths.each do |path| | ||
target_dir.join(path.dirname).mkpath | ||
FileUtils.cp path, target_dir.join(path) | ||
case file | ||
when ruby_version | ||
target_path.write("#{homebrew_ruby_version}\n") | ||
when rubocop_yml | ||
FileUtils.cp homebrew_rubocop_config, target_path | ||
else | ||
FileUtils.cp file, target_path | ||
end | ||
end | ||
|
||
out, err, status = Open3.capture3('git', '-C', target_dir.to_s, 'status', '--porcelain', '--ignore-submodules=dirty') | ||
out, err, status = Open3.capture3("git", "-C", target_directory, "status", "--porcelain", "--ignore-submodules=dirty") | ||
raise err unless status.success? | ||
|
||
target_dir_changed = !out.chomp.empty? | ||
target_directory_path_changed = !out.chomp.empty? | ||
|
||
unless target_dir_changed | ||
puts 'No changes detected.' | ||
unless target_directory_path_changed | ||
puts "No changes detected." | ||
exit | ||
end | ||
|
||
git '-C', target_dir.to_s, 'add', '--all' | ||
git "-C", target_directory, "add", "--all" | ||
|
||
out, err, status = Open3.capture3('git', '-C', target_dir.to_s, 'diff', '--name-only', '--staged') | ||
out, err, status = Open3.capture3("git", "-C", target_directory, "diff", "--name-only", "--staged") | ||
raise err unless status.success? | ||
|
||
modified_paths = out.lines.map(&:chomp) | ||
|
||
modified_paths.each do |modified_path| | ||
puts "Detected changes to #{modified_path}." | ||
git '-C', target_dir.to_s, 'commit', modified_path, '--message', "#{File.basename(modified_path)}: update to match main configuration", '--quiet' | ||
git "-C", target_directory, "commit", modified_path, "--message", | ||
"#{File.basename(modified_path)}: update to match main configuration", "--quiet" | ||
end | ||
puts | ||
|
||
File.open(ENV.fetch('GITHUB_OUTPUT'), 'a') do |f| | ||
f.puts 'pull_request=true' | ||
File.open(ENV.fetch("GITHUB_OUTPUT"), "a") do |f| | ||
f.puts "pull_request=true" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
inherit_from: | ||
- ../.rubocop.yml | ||
|
||
Bundler/GemFilename: | ||
Enabled: false | ||
|
||
Homebrew/MoveToExtendOS: | ||
Enabled: true | ||
Exclude: | ||
- "{extend,test,requirements}/**/*" | ||
- "os.rb" | ||
|
||
Naming/PredicateName: | ||
inherit_mode: | ||
merge: | ||
- AllowedMethods | ||
AllowedMethods: | ||
- is_32_bit? | ||
- is_64_bit? | ||
|
||
# Only enforce documentation for public APIs. | ||
# Checked by the tests.yml syntax job | ||
Style/Documentation: | ||
AllowedConstants: | ||
- Homebrew | ||
Include: | ||
- cask/cask.rb | ||
- cask/dsl.rb | ||
- cask/dsl/version.rb | ||
- cask/url.rb | ||
- development_tools.rb | ||
- download_strategy.rb | ||
- extend/ENV/super.rb | ||
- extend/kernel.rb | ||
- extend/pathname.rb | ||
- formula.rb | ||
- formula_assertions.rb | ||
- formula_free_port.rb | ||
- language/go.rb | ||
- language/java.rb | ||
- language/node.rb | ||
- language/perl.rb | ||
- language/python.rb | ||
- livecheck/strategy/apache.rb | ||
- livecheck/strategy/bitbucket.rb | ||
- livecheck/strategy/cpan.rb | ||
- livecheck/strategy/crate.rb | ||
- livecheck/strategy/extract_plist.rb | ||
- livecheck/strategy/git.rb | ||
- livecheck/strategy/github_latest.rb | ||
- livecheck/strategy/github_releases.rb | ||
- livecheck/strategy/gnome.rb | ||
- livecheck/strategy/gnu.rb | ||
- livecheck/strategy/hackage.rb | ||
- livecheck/strategy/json.rb | ||
- livecheck/strategy/launchpad.rb | ||
- livecheck/strategy/npm.rb | ||
- livecheck/strategy/page_match.rb | ||
- livecheck/strategy/pypi.rb | ||
- livecheck/strategy/sourceforge.rb | ||
- livecheck/strategy/sparkle.rb | ||
- livecheck/strategy/xml.rb | ||
- livecheck/strategy/xorg.rb | ||
- livecheck/strategy/yaml.rb | ||
- os.rb | ||
- resource.rb | ||
- utils/inreplace.rb | ||
- utils/shebang.rb | ||
- utils/string_inreplace_extension.rb | ||
- version.rb | ||
- tap.rb | ||
|
||
Homebrew/NegateInclude: | ||
Exclude: | ||
# YARD runs stand-alone. | ||
- yard/docstring_parser.rb | ||
|
||
Style/DocumentationMethod: | ||
Include: | ||
- "formula.rb" |