-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
76 lines (60 loc) · 1.69 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
require 'time'
AVAILABLE_REVISIONS = %w[major minor patch].freeze
task :default => [:run_server]
task :command_exists, [:command] do |_, args|
abort "#{args.command} doesn't exists" if `command -v #{args.command} > /dev/null 2>&1 && echo $?`.chomp.empty?
end
task :has_bumpversion do
Rake::Task['command_exists'].invoke('bumpversion')
end
task :bump, [:revision] => [:has_bumpversion] do |_, args|
args.with_defaults(revision: 'patch')
unless AVAILABLE_REVISIONS.include?(args.revision)
abort "Please provide valid revision: #{AVAILABLE_REVISIONS.join(',')}"
end
system "bumpversion #{args.revision}"
end
desc "run server"
task :run_server, [:port] do |_, args|
args.with_defaults(port: 9000)
begin
port = Integer(args.port)
rescue ArgumentError
abort "port value should be integer"
end
system %{
python -m http.server #{port}
}
end
desc "deploy"
task :deploy, [:revision] do |_, args|
args.with_defaults(version: 'patch')
now = Time.now
current_update_time = now.strftime("%a %b %d %H:%M:%S %z %Y")
system %{
sed -i "" 's/\\(Last update: <em>\\)[^<]*\\(<\\/em>\\)/\\1#{current_update_time}\\2/' index.html
}
unless `git status -s | wc -l`.strip.to_i.zero?
system %{
git add .
git commit -m '[UPDATE] - #{current_update_time}'
git push
}
abort "auto add and commit failed" if $?.exitstatus != 0
end
if $?.exitstatus == 0
Rake::Task[:bump].invoke(args.revision)
system %{
git push
git push --tags
git checkout gh-pages &&
git pull &&
git rebase main &&
git push origin gh-pages &&
git checkout main
}
exit $?.exitstatus
else
abort "sed fucked up"
end
end