Skip to content

Commit b289f6a

Browse files
authored
Merge pull request #330 from Homebrew/improve_dependabot_syncing
2 parents c0df5c4 + c2ffba2 commit b289f6a

File tree

3 files changed

+183
-144
lines changed

3 files changed

+183
-144
lines changed
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# This file is used as a base for all repositories in the Homebrew GitHub
2+
# organisation so intentionally contains a superset of all required attributes.
3+
version: 2
4+
5+
updates:
6+
- package-ecosystem: github-actions
7+
directory: /
8+
schedule:
9+
interval: weekly
10+
day: "monday"
11+
time: "08:00"
12+
timezone: "Etc/UTC"
13+
allow:
14+
- dependency-type: all
15+
groups:
16+
dependabot:
17+
patterns:
18+
- "*"
19+
cooldown:
20+
default-days: 1
21+
include:
22+
- "*"
23+
24+
- package-ecosystem: bundler
25+
directories:
26+
- /
27+
- /Library/Homebrew
28+
schedule:
29+
interval: weekly
30+
day: "monday"
31+
time: "08:00"
32+
timezone: "Etc/UTC"
33+
allow:
34+
- dependency-type: all
35+
groups:
36+
dependabot:
37+
patterns:
38+
- "*"
39+
cooldown:
40+
default-days: 1
41+
semver-major-days: 14
42+
semver-minor-days: 7
43+
semver-patch-days: 1
44+
include:
45+
- "*"
46+
47+
- package-ecosystem: npm
48+
directory: /
49+
schedule:
50+
interval: weekly
51+
day: "monday"
52+
time: "08:00"
53+
timezone: "Etc/UTC"
54+
allow:
55+
- dependency-type: all
56+
groups:
57+
dependabot:
58+
patterns:
59+
- "*"
60+
cooldown:
61+
default-days: 1
62+
semver-major-days: 14
63+
semver-minor-days: 7
64+
semver-patch-days: 1
65+
include:
66+
- "*"
67+
68+
- package-ecosystem: docker
69+
directory: /
70+
schedule:
71+
interval: weekly
72+
day: "monday"
73+
time: "08:00"
74+
timezone: "Etc/UTC"
75+
allow:
76+
- dependency-type: all
77+
groups:
78+
dependabot:
79+
patterns:
80+
- "*"
81+
82+
- package-ecosystem: devcontainers
83+
directory: /
84+
schedule:
85+
interval: weekly
86+
day: "monday"
87+
time: "08:00"
88+
timezone: "Etc/UTC"
89+
allow:
90+
- dependency-type: all
91+
groups:
92+
dependabot:
93+
patterns:
94+
- "*"
95+
cooldown:
96+
default-days: 1
97+
include:
98+
- "*"
99+
100+
- package-ecosystem: pip
101+
directories:
102+
- /
103+
- /Library/Homebrew/formula-analytics/
104+
schedule:
105+
interval: weekly
106+
day: "monday"
107+
time: "08:00"
108+
timezone: "Etc/UTC"
109+
allow:
110+
- dependency-type: all
111+
groups:
112+
dependabot:
113+
patterns:
114+
- "*"
115+
cooldown:
116+
default-days: 1
117+
semver-major-days: 14
118+
semver-minor-days: 7
119+
semver-patch-days: 1
120+
include:
121+
- "*"

.github/actions/sync/shared-config.rb

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,14 @@ def git(*args)
2828
ruby_version = ".ruby-version"
2929
rubocop_yaml = ".rubocop.yml"
3030
vale_ini = ".vale.ini"
31+
dependabot_template_yaml = ".github/actions/sync/dependabot.template.yml"
3132
dependabot_yaml = ".github/dependabot.yml"
3233
docs_workflow_yaml = ".github/workflows/docs.yml"
3334
actionlint_workflow_yaml = ".github/workflows/actionlint.yml"
3435
stale_issues_workflow_yaml = ".github/workflows/stale-issues.yml"
3536
zizmor_yml = ".github/zizmor.yml"
3637
codeql_extensions_homebrew_actions_yml = ".github/codeql/extensions/homebrew-actions.yml"
3738

38-
target_gemfile_lock = target_directory_path/"Gemfile.lock"
39-
4039
homebrew_docs = homebrew_repository_path/docs
4140
homebrew_ruby_version =
4241
(homebrew_repository_path/"Library/Homebrew/vendor/portable-ruby-version").read
@@ -63,19 +62,37 @@ def git(*args)
6362
homebrew_docs_workflow_yaml = homebrew_repository_path/docs_workflow_yaml
6463
homebrew_vale_ini = homebrew_repository_path/vale_ini
6564

66-
dependabot_config_yaml = YAML.load_file(dependabot_yaml)
65+
target_gemfile_locks = []
66+
dependabot_config_yaml = YAML.load_file(dependabot_template_yaml)
6767
dependabot_config_yaml["updates"] = dependabot_config_yaml["updates"].filter_map do |update|
68-
keep_update = case update["package-ecosystem"]
68+
bundler_ecosystem = false
69+
ecosystem_file = case update["package-ecosystem"]
6970
when "bundler"
70-
target_gemfile_lock.exist?
71+
bundler_ecosystem = true
72+
"Gemfile.lock"
7173
when "npm"
72-
(target_directory_path/"package.json").exist?
74+
"package.json"
7375
when "docker"
74-
(target_directory_path/"Dockerfile").exist?
76+
"Dockerfile"
7577
when "devcontainers"
76-
(target_directory_path/".devcontainer/devcontainer.json").exist?
78+
".devcontainer/devcontainer.json"
7779
when "pip"
78-
(target_directory_path/"requirements.txt").exist?
80+
"requirements.txt"
81+
end
82+
83+
keep_update = if ecosystem_file && (update_directories = update["directories"])
84+
update_directories.select! do |directory|
85+
ecosystem_file_path = (target_directory_path/".#{directory}/#{ecosystem_file}")
86+
next unless ecosystem_file_path.exist?
87+
88+
target_gemfile_locks << ecosystem_file_path if bundler_ecosystem
89+
90+
true
91+
end
92+
update["directories"] = update_directories
93+
update_directories.any?
94+
elsif (update_directory = update.fetch("directory"))
95+
(target_directory_path/".#{update_directory}/#{ecosystem_file}").exist?
7996
else
8097
true
8198
end
@@ -161,7 +178,7 @@ def git(*args)
161178
"# This file is synced from `Homebrew/brew` by the `.github` repository, do not modify it directly.\n" \
162179
"#{homebrew_docs_rubocop_config}\n",
163180
)
164-
else
181+
elsif docs_path != target_docs_path
165182
FileUtils.cp docs_path, target_docs_path
166183
end
167184
end
@@ -202,14 +219,14 @@ def git(*args)
202219
)
203220
when dependabot_yaml, actionlint_workflow_yaml, stale_issues_workflow_yaml,
204221
zizmor_yml, codeql_extensions_homebrew_actions_yml
205-
next if path == target_path.to_s
206-
207-
# ensure we don't replace the template files in this repository
208-
next if repository_name == ".github"
209-
210222
contents = if path == dependabot_yaml
211223
dependabot_config
212224
else
225+
next if path == target_path.to_s
226+
227+
# ensure we don't replace the non-dependabot template files in this repository
228+
next if repository_name == ".github"
229+
213230
Pathname(path).read
214231
.chomp
215232
end
@@ -233,18 +250,19 @@ def git(*args)
233250
# Update Gemfile.lock if it exists, based on the Ruby version.
234251
#
235252
# We don't have Homebrew exclude? method here.
236-
# rubocop:disable Homebrew/NegateInclude
237-
if !custom_ruby_version_repos.include?(repository_name) && target_gemfile_lock.exist?
238-
Dir.chdir target_directory_path do
239-
require "bundler"
240-
bundler_version = Bundler::Definition.build(homebrew_gemfile, homebrew_gemfile_lock, false)
241-
.locked_gems
242-
.bundler_version
243-
puts "Running bundle update (with Bundler #{bundler_version})..."
244-
system "bundle", "update", "--ruby", "--bundler=#{bundler_version}", "--quiet", out: "/dev/null"
253+
unless custom_ruby_version_repos.include?(repository_name)
254+
target_gemfile_locks.each do |target_gemfile_lock|
255+
target_directory_path = target_gemfile_lock.dirname
256+
Dir.chdir target_directory_path do
257+
require "bundler"
258+
bundler_version = Bundler::Definition.build(homebrew_gemfile, homebrew_gemfile_lock, false)
259+
.locked_gems
260+
.bundler_version
261+
puts "Running bundle update (with Bundler #{bundler_version})..."
262+
system "bundle", "update", "--ruby", "--bundler=#{bundler_version}", "--quiet", out: "/dev/null"
263+
end
245264
end
246265
end
247-
# rubocop:enable Homebrew/NegateInclude
248266

249267
out, err, status = Open3.capture3("git", "-C", target_directory, "status", "--porcelain", "--ignore-submodules=dirty")
250268
raise err unless status.success?

.github/dependabot.yml

Lines changed: 19 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -1,122 +1,22 @@
1-
# This file is used as a base for all other repositories in the Homebrew GitHub
2-
# organisation so intentionally contains package-ecosystems that do not apply to
3-
# this repository. They will be stripped out if unneeded by the sync action.
1+
# This file is synced from the `.github` repository, do not modify it directly.
2+
---
43
version: 2
5-
64
updates:
7-
- package-ecosystem: github-actions
8-
directory: /
9-
schedule:
10-
interval: weekly
11-
day: "monday"
12-
time: "08:00"
13-
timezone: "Etc/UTC"
14-
allow:
15-
- dependency-type: all
16-
groups:
17-
dependabot:
18-
patterns:
19-
- "*"
20-
cooldown:
21-
default-days: 1
22-
include:
23-
- "*"
24-
25-
- package-ecosystem: bundler
26-
directories:
27-
- /
28-
- /Library/Homebrew
29-
schedule:
30-
interval: weekly
31-
day: "monday"
32-
time: "08:00"
33-
timezone: "Etc/UTC"
34-
allow:
35-
- dependency-type: all
36-
groups:
37-
dependabot:
38-
patterns:
39-
- "*"
40-
cooldown:
41-
default-days: 1
42-
semver-major-days: 14
43-
semver-minor-days: 7
44-
semver-patch-days: 1
45-
include:
46-
- "*"
47-
48-
- package-ecosystem: npm
49-
directory: /
50-
schedule:
51-
interval: weekly
52-
day: "monday"
53-
time: "08:00"
54-
timezone: "Etc/UTC"
55-
allow:
56-
- dependency-type: all
57-
groups:
58-
dependabot:
59-
patterns:
60-
- "*"
61-
cooldown:
62-
default-days: 1
63-
semver-major-days: 14
64-
semver-minor-days: 7
65-
semver-patch-days: 1
66-
include:
67-
- "*"
68-
69-
- package-ecosystem: docker
70-
directory: /
71-
schedule:
72-
interval: weekly
73-
day: "monday"
74-
time: "08:00"
75-
timezone: "Etc/UTC"
76-
allow:
77-
- dependency-type: all
78-
groups:
79-
dependabot:
80-
patterns:
81-
- "*"
82-
83-
- package-ecosystem: devcontainers
84-
directory: /
85-
schedule:
86-
interval: weekly
87-
day: "monday"
88-
time: "08:00"
89-
timezone: "Etc/UTC"
90-
allow:
91-
- dependency-type: all
92-
groups:
93-
dependabot:
94-
patterns:
95-
- "*"
96-
cooldown:
97-
default-days: 1
98-
include:
99-
- "*"
5+
- package-ecosystem: github-actions
6+
directory: "/"
7+
schedule:
8+
interval: weekly
9+
day: friday
10+
time: '08:00'
11+
timezone: Etc/UTC
12+
allow:
13+
- dependency-type: all
14+
groups:
15+
dependabot:
16+
patterns:
17+
- "*"
18+
cooldown:
19+
default-days: 1
20+
include:
21+
- "*"
10022

101-
- package-ecosystem: pip
102-
directories:
103-
- /
104-
- /Library/Homebrew/formula-analytics/
105-
schedule:
106-
interval: weekly
107-
day: "monday"
108-
time: "08:00"
109-
timezone: "Etc/UTC"
110-
allow:
111-
- dependency-type: all
112-
groups:
113-
dependabot:
114-
patterns:
115-
- "*"
116-
cooldown:
117-
default-days: 1
118-
semver-major-days: 14
119-
semver-minor-days: 7
120-
semver-patch-days: 1
121-
include:
122-
- "*"

0 commit comments

Comments
 (0)