This repository was archived by the owner on Jul 3, 2025. It is now read-only.
forked from skyglobal/web-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrakefile
More file actions
155 lines (128 loc) · 3.89 KB
/
rakefile
File metadata and controls
155 lines (128 loc) · 3.89 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
require 'aws-sdk'
require 'cgi'
def s3
$s3 ||= AWS::S3.new(access_key_id: ENV["S3_ACCESS_KEY_ID"] , secret_access_key: ENV["S3_ACCESS_KEY"], region: 'eu-west-1')
end
def bucket
$bucket ||= s3.buckets['prod-sky-web-toolkit']
end
def latest_version_number
$latest_version_number ||= File.open('_config.yml').read.match(/version:(.+)/)[1].strip
end
def version_already_exists?
bucket.objects.any?{|obj|obj.key.include? latest_version_number}
end
def version_is_release_candidate?
latest_version_number.include? 'rc'
end
def static_to_upload
Dir.glob("static/**/*.*")
end
def assets_to_upload
["stylesheets/toolkit.css",
"fonts/skycons.css", "fonts/skycons.eot", "fonts/skycons.svg", "fonts/skycons.ttf",
"scripts/toolkit.js",
"images/icon.png"]
end
def templates_to_upload
Dir.glob("_site/**/*.*")
end
def content_type(file)
case File.extname(file)
when '.svg'
content_type = 'image/svg+xml'
when '.eot'
content_type = 'application/vnd.ms-fontobject'
when '.ttf'
content_type = 'font/ttf'
when '.woff'
content_type = 'application/x-font-woff'
when '.map'
content_type = 'text/javascript'
when '.js'
content_type = 'text/javascript'
when '.css'
content_type = 'text/css'
when '.png'
content_type = 'image/png'
when '.html'
content_type = 'text/html'
else
content_type = 'image/jpeg'
end
content_type
end
def emptyGitCache
system "git rm --cached grunt/fonts/min -r"
system "git rm --cached _site -r"
system "git rm --cached dist/images -r"
system "git rm --cached dist/scripts -r"
system "git rm --cached dist/stylesheets -r"
end
def tagBuild
puts "*** Tagging Version #{latest_version_number} ***"
system "git config user.email 'circleci@bskyb.com'"
system "git config user.name 'CircleCI'"
system "git tag -a v#{latest_version_number} -m \"Rake deploy: auto tag on #{getDate}\""
system "git push origin master v#{latest_version_number}"
end
def pushToAmazonS3
puts "*** Pushing to the AmazonS3 ***"
doc_resources = []
puts 'Uploading assets'
cd "dist"
assets_to_upload.each do |file|
doc_resources << bucket.objects["#{latest_version_number}/#{file}"].write(File.open(file).read, cache_control: 'public, max-age=2592000', content_type: content_type(file), acl: :public_read )
end
cd ".."
puts 'Uploading template files'
templates_to_upload.each do |file|
doc_resources << bucket.objects["#{latest_version_number}/#{file}"].write(File.open(file).read, cache_control: 'public, max-age=2592000', content_type: content_type(file), acl: :public_read )
end
puts 'Uploading static files'
static_to_upload.each do |file|
doc_resources << bucket.objects["#{file}"].write(File.open(file).read, cache_control: 'public, max-age=2592000', content_type: content_type(file), acl: :public_read )
end
end
def fetchGHPages
puts "*** Fecthing GH Pages ***"
`git fetch origin gh-pages`
`git checkout gh-pages`
`git rebase master`
`git pull origin gh-pages`
end
def updateGHPages
puts "*** Updating GH Pages ***"
`git add -A ./dist/`
`git add -A ./_site/`
`git commit -m "Rake deploy: auto push to gh-pages"`
`git push origin gh-pages`
end
def buildDistributionFiles
puts "*** Grunting Distribution files ***"
system "grunt"
system "jekyll build"
end
def getDate
`date +'%d-%m-%Y'`
end
desc 'Removes previously cached directories that were in git but are now in .gitIgnore'
task :emptyGitCache do
emptyGitCache
end
desc 'Deploys a new version to the CDN'
task :deploy do
`git config --global user.email "circle@circle.com"`
`git config --global user.name "rake file"`
if version_already_exists?
puts "Version #{latest_version_number} exists so exiting."
next
end
fetchGHPages
buildDistributionFiles
pushToAmazonS3
if !version_is_release_candidate?
tagBuild
updateGHPages
end
end