forked from dependabot/dependabot-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
129 lines (109 loc) · 3.65 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# frozen_string_literal: true
require "fileutils"
require "English"
require "net/http"
require "uri"
require "json"
require "shellwords"
require "rubygems/package"
require "./lib/dependabot/version"
GEMSPECS = %w(
dependabot-core.gemspec
terraform/dependabot-terraform.gemspec
elm/dependabot-elm.gemspec
docker/dependabot-docker.gemspec
git_submodules/dependabot-git_submodules.gemspec
python/dependabot-python.gemspec
nuget/dependabot-nuget.gemspec
gradle/dependabot-gradle.gemspec
maven/dependabot-maven.gemspec
cargo/dependabot-cargo.gemspec
go_modules/dependabot-go_modules.gemspec
omnibus/dependabot-omnibus.gemspec
).freeze
namespace :ci do
task :rubocop do
packages = changed_packages
puts "Running rubocop on: #{packages.join(', ')}"
packages.each do |package|
puts "> cd #{package} && bundle exec rubocop"
system("cd #{package} && bundle exec rubocop")
end
end
task :rspec do
packages = changed_packages
puts "Running rspec on: #{packages.join(', ')}"
packages.each do |package|
puts "> cd #{package} && bundle exec rspec spec"
system("cd #{package} && bundle exec rspec spec")
end
end
end
namespace :gems do
task build: :clean do
root_path = Dir.getwd
pkg_path = File.join(root_path, "pkg")
Dir.mkdir(pkg_path) unless File.directory?(pkg_path)
GEMSPECS.each do |gemspec_path|
puts "> Building #{gemspec_path}"
Dir.chdir(File.dirname(gemspec_path)) do
gemspec = Bundler.load_gemspec_uncached(File.basename(gemspec_path))
pkg = ::Gem::Package.build(gemspec)
FileUtils.mv(pkg, File.join(pkg_path, pkg))
end
end
end
task release: [:build] do
guard_tag_match
GEMSPECS.each do |gemspec_path|
gem_name = File.basename(gemspec_path).sub(/\.gemspec$/, "")
gem_path = "pkg/#{gem_name}-#{Dependabot::VERSION}.gem"
if rubygems_release_exists?(gem_name, Dependabot::VERSION)
puts "- Skipping #{gem_path} as it already exists on rubygems"
else
puts "> Releasing #{gem_path}"
sh "gem push #{gem_path}"
end
end
end
task :clean do
FileUtils.rm(Dir["pkg/*.gem"])
end
end
def guard_tag_match
tag = "v#{Dependabot::VERSION}"
tag_commit = `git rev-list -n 1 #{tag} 2> /dev/null`.strip
abort "Can't release - tag #{tag} does not exist" unless $CHILD_STATUS == 0
head_commit = `git rev-parse HEAD`.strip
return if tag_commit == head_commit
abort "Can't release - HEAD (#{head_commit[0..9]}) does not match " \
"tag #{tag} (#{tag_commit[0..9]})"
end
def rubygems_release_exists?(name, version)
uri = URI.parse("https://rubygems.org/api/v1/versions/#{name}.json")
response = Net::HTTP.get_response(uri)
abort "Gem #{name} doesn't exist on rubygems" if response.code != "200"
body = JSON.parse(response.body)
existing_versions = body.map { |b| b["number"] }
existing_versions.include?(version)
end
def changed_packages
all_packages = GEMSPECS.
select { |gs| gs.include?("/") }.
map { |gs| "./" + gs.split("/").first }
return all_packages if ENV["CIRCLE_COMPARE_URL"].nil?
range = ENV["CIRCLE_COMPARE_URL"].split("/").last
core_paths = %w(Dockerfile Dockerfile.ci Gemfile dependabot-core.gemspec
config helpers lib spec)
core_changed = commit_range_changes_paths?(range, core_paths)
packages = all_packages.select do |package|
next true if core_changed
commit_range_changes_paths?(range, [package])
end
packages.insert(0, "./") if core_changed
packages
end
def commit_range_changes_paths?(range, paths)
cmd = %w(git diff --quiet) + [range, "--"] + paths
!system(Shellwords.join(cmd))
end