forked from coderdojo-japan/coderdojo.jp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup
executable file
·72 lines (55 loc) · 2.12 KB
/
setup
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
#!/usr/bin/env ruby
require 'pathname'
require 'fileutils'
require 'date'
include FileUtils
# path to your application root.
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==")
end
def doorkeeper_message
<<~MESSAGE
環境変数 DOORKEEPER_API_TOKEN が設定されていないため、
Doorkeeper API を使ったイベント情報の取得をスキップします。
Doorkeeper のイベントを取得するためには、
下記ページから Doorkeeper API Token を取得し、
環境変数 DOORKEEPER_API_TOKEN に設定してください。
https://manage.doorkeeper.jp/user/oauth/applications
環境変数設定後に、bin/setup を再実行してください!
MESSAGE
end
chdir APP_ROOT do
# This script is a starting point to setup your application.
# Add necessary setup steps to this file.
puts '== Installing dependencies =='
system! 'gem install bundler --conservative'
system('bundle check') || system!('bundle install')
# Install JavaScript dependencies if using Yarn
# system('bin/yarn')
# puts "\n== Copying sample files =="
# unless File.exist?('config/database.yml')
# cp 'config/database.yml.sample', 'config/database.yml'
# end
puts "\n== Preparing database =="
system! 'bin/rails db:setup'
puts "\n== Upserting application data =="
system! 'bin/rails dojos:update_db_by_yaml'
system! 'bin/rails dojo_event_services:upsert'
today = Date.today
from = (today - 90).strftime('%Y%m')
to = today.prev_month.strftime('%Y%m')
if ENV['DOORKEEPER_API_TOKEN']
system! "bin/rails statistics:aggregation[#{from},#{to}]"
system! 'bin/rails upcoming_events:aggregation'
else
puts doorkeeper_message
system! "bin/rails statistics:aggregation[#{from},#{to},connpass]"
system! "bin/rails statistics:aggregation[#{from},#{to},facebook]"
system! 'bin/rails upcoming_events:aggregation[connpass]'
end
puts "\n== Removing old logs and tempfiles =="
system! 'bin/rails log:clear tmp:clear'
puts "\n== Restarting application server =="
system! 'bin/rails restart'
end