Skip to content
This repository has been archived by the owner on Apr 29, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1124 from square/mmc-no-godep
Browse files Browse the repository at this point in the history
Update rakefile to use modules
  • Loading branch information
bwester authored Aug 8, 2019
2 parents 47c30d5 + 1062fcc commit 31f075f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 75 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ before_install:

install:
- gem install rake
- go get github.com/tools/godep
- go get github.com/kisielk/errcheck
- rake install
- wget https://releases.hashicorp.com/consul/0.7.1/consul_0.7.1_linux_amd64.zip
Expand Down
80 changes: 6 additions & 74 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,17 @@ require "json"

def e(cmd)
puts cmd
system(cmd) || raise("Error running `#{cmd}`")
system({"GO111MODULE" => "on"}, cmd) || raise("Error running `#{cmd}`")
end

def target(expand="")
root = File.dirname(__FILE__)
File.expand_path(expand, File.join(root, 'target'))
end

task :godep_check do
system("which godep") || abort("You do not have godep installed. Run `go get github.com/tools/godep` and ensure that it's on your PATH")
end

desc 'Get deps for all projects.'
task :deps => :godep_check do
e "go get -v -t ./..."
e "godep save ./..."
desc 'Vendor dependencies for all projects.'
task :deps do
e "go mod vendor"
end

desc 'Build all projects'
Expand All @@ -38,9 +33,9 @@ task :test_all => [:build] do
end

desc 'Update all dependencies'
task :update => :godep_check do
task :update do
e "go get -u -t -v ./..."
e "godep update -r .../..."
e "go mod vendor"
end

desc 'Install all built binaries'
Expand Down Expand Up @@ -85,66 +80,3 @@ end

desc 'By default, gather dependencies, build and test'
task :default => [:deps, :test, :install]

task :sync_consul_deps do
p2_repo_dir = File.join(ENV["GOPATH"], "src", "github.com", "square", "p2")

consul_vendor_contents = JSON.parse(File.read(File.join(ENV["GOPATH"], "src", "github.com", "hashicorp", "consul", "vendor", "vendor.json")))
p2_godep_contents = JSON.parse(File.read(File.join(p2_repo_dir, "Godeps", "Godeps.json")))

# build a map of package names to revisions from consul's vendor.json
consul_deps = {}
consul_vendor_contents["package"].each do |package|
consul_deps[package["path"]] = package["revision"]
end

success_count = 0
failed_count = 0
skipped_count = 0

# now iterate over our Godeps.json and find any versions that mismatch and print them
p2_godep_contents["Deps"].each do |package|
package_name = package["ImportPath"]
consul_rev = consul_deps[package_name]
next unless consul_rev

our_rev = package["Rev"]
if consul_rev != our_rev
# grab just the first three items e.g. github.com/hashicorp/consul not github.com/hashicorp/consul/api/inner/package/thing
first_three = package_name.split("/")[0..2]
first_three_joined = first_three.join("/")

# in case the consul dependency is new and not in $GOPATH, do a "go get" first
e "go get #{first_three_joined}/..."
begin
Dir.chdir(File.join(ENV["GOPATH"], "src", *first_three)) do
e "git fetch"
older_commit = `git merge-base #{our_rev} #{consul_rev}`.chomp
raise "could not determine which commit is newer for #{first_three_joined}" unless $?.exitstatus == 0
if older_commit == our_rev
e "git checkout #{consul_rev}"
else
puts "No action taken for #{package_name}: consul's version #{consul_rev} is older than P2's #{our_rev}"
skipped_count += 1
next
end
end

Dir.chdir(p2_repo_dir) do
e "godep update #{first_three.join("/")}/..."
end

puts "Successfully repaired mismatch in #{package_name}: consul has #{consul_rev} p2 had #{our_rev}"
success_count += 1
rescue => e
puts "Failed to repair mismatch in #{package_name}: consul has #{consul_rev} p2 had #{our_rev}: #{e.message}"
failed_count += 1
end

end
end

puts "Successfully updated #{success_count} packages"
puts "Failed to updated #{failed_count} packages"
puts "Skipped updating #{skipped_count} packages (because consul had an older version vendored)"
end

0 comments on commit 31f075f

Please sign in to comment.