-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathRakefile
53 lines (49 loc) · 1.54 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
require 'html-proofer'
require 'rake'
include FileUtils
desc 'run htmlproofer, rspec if exists'
task :test do
opts = {
:check_external_hash => true,
:allow_hash_href => true,
:disable_external => true,
:empty_alt_ignore => true,
:allow_missing_href => true,
:enforce_https=> false,
:only_4xx => true,
:verbose => true
}
sh 'bundle exec jekyll b'
HTMLProofer.check_directory('./_site', opts).run
sh 'bundle exec rspec' if File.exist?('.rspec')
end
namespace :git do
namespace :push do
desc 'push built site to s3 branch'
task :static do
if ENV.fetch('CI', false)
BRANCH = ENV['TRAVIS_BRANCH']
if BRANCH == 'master'
REPO_SLUG = ENV['TRAVIS_REPO_SLUG']
USER = REPO_SLUG.split('/')[0]
TOKEN = ENV['GIT_ACCESS_TOKEN']
COMMIT_MSG = "Site updated via #{ENV['TRAVIS_COMMIT']}".freeze
ORIGIN = "https://#{USER}:#{TOKEN}@github.com/#{REPO_SLUG}.git".freeze
puts "Deploying to 'static' branch from Travis as #{USER}"
Dir.mktmpdir do |tmp|
cp_r '_site/.', tmp
Dir.chdir tmp
system 'git init'
system "git add . && git commit -m '#{COMMIT_MSG}'"
system "git remote add origin #{ORIGIN}"
system "git push origin master:refs/heads/static --force"
end
else
puts "This task only runs on the master branch. Skipping for #{BRANCH}."
end
else
puts 'Not on Travis-CI. Skipping push to static branch.'
end
end
end
end