forked from FarmBot/Farmbot-Web-App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auto_upgrade.rb
81 lines (67 loc) · 1.69 KB
/
auto_upgrade.rb
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
require "pry"
class UpgradeFailure < Exception; end
def type_check
system 'npm run typecheck'
end
def run_tests
system 'jest --bail'
end
def run_build
system 'npm run build'
end
def commit_upgrade(dep)
system('git add -A')
system("git commit -am 'Upgrade #{dep}' --allow-empty")
end
def upgrade(dep)
system("yarn add #{dep} --save")
end
def stash(dep)
puts "stashing failed upgrade for #{dep}"
system("git stash") && system("yarn install")
end
def attempt(dep, operation, args)
result = send(operation, *args)
unless result
raise UpgradeFailure, "operation failed for #{dep}: #{operation} failed"
else
puts "#{operation} for #{dep} OK"
end
end
# Parse `yarn outdated` list into String[] with format `name@version`
DEPS = `yarn outdated`
.split("\n")[6..-1]
.map{|y| y.split }
.map{|y| "#{y[0]}@#{y[3]}"}
.sort
.reject { |x| x.include?("router") }
# puts "Making sure that type checks pass WITHOUT any upgrades"
tc_ok = type_check
# puts "Making sure tests pass WITHOUT any upgrades"
test_ok = run_tests
# puts "Making sure build works WITHOUT any upgrades"
build_ok = run_build
proceed = tc_ok && test_ok && build_ok
if (proceed)
puts "LOOKS GOOD!"
commit_upgrade("START")
else
puts "Make sure types and tests pass before upgrading"
exit
end
FAILED = []
puts "Start upgrade..."
DEPS.each do |dep|
begin
attempt(dep, :upgrade, [dep])
attempt(dep, :type_check, [])
attempt(dep, :run_tests, [])
attempt(dep, :run_build, [])
attempt(dep, :commit_upgrade, [dep])
rescue UpgradeFailure => e
FAILED.push(dep)
attempt(dep, :stash, [dep])
end
end
puts "FAILED UPGRADES:\n"
puts FAILED.join("\n") + "\n"