-
Notifications
You must be signed in to change notification settings - Fork 47
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
Improve shared configuration syncing. #110
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A lot of this is intentionally Homebrew/brew specific like this cop (we don't want to block
if OS.mac?
in formulae etc). Is this the correct file?The
../rubocop.yml
isn't correct for any repository AFAIK, since if we're targetingLibrary/.rubocop.yml
it should be../../..
for taps (and nothing for non-taps).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, not correct, see #111 to fix.