Skip to content

Commit

Permalink
sync/shared-config: sync docs, improve dependabot.
Browse files Browse the repository at this point in the history
- the docs syncing should allow us to enforce a consistent structure
  for documentation across all our repositories.
- the dependabot syncing changes should avoid red CI and unnecessary
  dependabot checks in repositories missing the relevant files.

While we're here:
- use `yaml` consistently instead of `yml`
  • Loading branch information
MikeMcQuaid committed Jun 10, 2024
1 parent a95c7ce commit 4d06ea0
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 16 deletions.
80 changes: 65 additions & 15 deletions .github/actions/sync/shared-config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,44 @@ def git(*args)
abort "Usage: #{$PROGRAM_NAME} <target_directory_path> <homebrew_repository_path>"
end

docs = "docs"
ruby_version = ".ruby-version"
rubocop_yml = ".rubocop.yml"
dependabot_yml = ".github/dependabot.yml"
rubocop_yaml = ".rubocop.yml"
dependabot_yaml = ".github/dependabot.yml"
docs_workflow_yaml = ".github/workflows/docs.yml"

homebrew_docs = homebrew_repository_path/docs
homebrew_ruby_version =
(homebrew_repository_path/"Library/Homebrew/vendor/portable-ruby-version").read
.chomp
.sub(/_\d+$/, "")
homebrew_rubocop_config_yaml = YAML.load_file(
homebrew_repository_path/"Library/#{rubocop_yml}",
homebrew_repository_path/"Library/#{rubocop_yaml}",
permitted_classes: [Symbol, Regexp],
)
homebrew_rubocop_config = homebrew_rubocop_config_yaml.reject do |key, _|
key.match?(%r{\Arequire|inherit_from|inherit_mode|Cask/|Formula|Homebrew|Performance/|RSpec|Sorbet/})
end.to_yaml

dependabot_config_yaml = YAML.load_file(dependabot_yaml)
dependabot_config_yaml["updates"].select! do |update|
case update["package-ecosystem"]
when "bundler"
(target_directory_path/"Gemfile.lock").exist?
when "npm"
(target_directory_path/"package.json").exist?
when "docker"
(target_directory_path/"Dockerfile").exist?
when "devcontainers"
(target_directory_path/".devcontainer/devcontainer.json").exist?
when "pip"
(target_directory_path/"requirements.txt").exist?
else
true
end
end
dependabot_config = dependabot_config_yaml.to_yaml

custom_ruby_version_repos = %w[
mass-bottling-tracker-private
].freeze
Expand All @@ -51,45 +73,73 @@ def git(*args)
].freeze
custom_dependabot_repos = %w[
brew
brew-pip-audit
ci-orchestrator
].freeze

puts "Detecting changes…"
[
docs,
ruby_version,
rubocop_yml,
dependabot_yml,
rubocop_yaml,
dependabot_yaml,
docs_workflow_yaml,
".github/workflows/lock-threads.yml",
".github/workflows/stale-issues.yml",
].each do |file|
target_path = target_directory_path/file
].each do |path|
target_path = target_directory_path/path
target_path.dirname.mkpath

case file
case path
when docs
next if path == target_path.to_s
next unless target_path.exist?
next unless target_path.directory?

homebrew_docs.find do |docs_path|
next if docs_path.directory?

target_docs_path = target_path/docs_path.basename
next if docs_path.extname == ".md" && !target_docs_path.exist?

target_docs_path.dirname.mkpath
FileUtils.cp docs_path, target_docs_path
end
FileUtils.cp_r homebrew_docs, target_path.parent
when docs_workflow_yaml
next if path == target_path.to_s

docs_path = target_directory_path/docs
next unless docs_path.exist?
next unless docs_path.directory?

FileUtils.cp path, target_path
when ruby_version
next if custom_ruby_version_repos.include?(repository_name)

target_path = target_directory_path/"Library/Homebrew/#{ruby_version}" if repository_name == "brew"

target_path.write("#{homebrew_ruby_version}\n")
when rubocop_yml
when rubocop_yaml
next if custom_rubocop_repos.include?(repository_name)

FileUtils.rm_f target_path
target_path.write(
"# This file is synced from `Homebrew/brew` by the `.github` repository, do not modify it directly.\n" \
"#{homebrew_rubocop_config}\n",
)
when dependabot_yml
when dependabot_yaml
next if custom_dependabot_repos.include?(repository_name)
next if file == target_path.to_s
next if path == target_path.to_s

FileUtils.cp file, target_path
FileUtils.rm_f target_path
target_path.write(
"# This file is synced from the `.github` repository, do not modify it directly.\n" \
"#{dependabot_config}\n",
)
else
next if file == target_path.to_s
next if path == target_path.to_s

FileUtils.cp file, target_path
FileUtils.cp path, target_path
end
end

Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/sync-shared-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ concurrency:
cancel-in-progress: true

jobs:
sync-shared-config:
sync:
if: github.repository == 'Homebrew/.github'
runs-on: ubuntu-latest
strategy:
Expand Down Expand Up @@ -112,3 +112,9 @@ jobs:
This pull request was created automatically by the
[`sync-shared-config`](https://github.com/Homebrew/.github/blob/HEAD/.github/workflows/sync-shared-config.yml)
workflow.
conclusion:
needs: sync
runs-on: ubuntu-latest
steps:
- name: Conclusion
run: echo "Sync shared configurations completed"

0 comments on commit 4d06ea0

Please sign in to comment.